You are on page 1of 4

RPGPGM.

COM - From AS400 to IBM i


Advice about programming, operations, communications, and anything else I can think of

This blog is about IBM i for PowerSystems

Home About this blog List of all posts IBM i user groups Legal notices Privacy policy Search this site

We d n e s d a y, A p r i l 2 1 , 2 0 2 1

Display values of SQL variables in ACS Run SQL


Scripts
Db2 for i comes with a host of built-in global variables and
special registers that provide us with some of the basic
information about the environment of the IBM i we are using.

When I am using ACS's Run SQL Scripts it is useful to be able


to quickly check these values. Or if I am doing a presentation I
need to be able to show which IBM i partition I am using to
help people to understand what I am doing.
Contact Form
If I wanted to see which partition I am using I could use the following SQL statement:
Name

Email
*

Message
*

I am sure more of you are familiar using the SYSDUMMY1 table in the library SYSIBM to do this
kind of thing.
Send
I am all for shortcuts and making things easier for myself. I need to give credit to Paul Tuohy
for showing this particular shortcut.

Rather than using the Select statement I can use the VALUES statement in its place. By using
the VALUES I do not have to define a file. If I want to display which database server my Run
SQL Scripts session is attached to I could just use the following:

Having had a chance to play with this I have some interesting things you need to be aware of.

You can list more than one built-in function and special register:

Follow This Blog by


Email

Unavailable

Links to useful sites


The returned values are shown in one column.

Notice how I had to use the CHAR function with the date, time, and timestamp. I have found
Getting started with IBM i
that: 1

IBM Documentation for 7.4


If the only special registers chosen are for dates, times, and timestamps the data's 2
type does not need to be changed 3 IBM Documentation for 7.3
If the results contain a mixture of data types, such as character, dates, times, and
timestamps, not all of the results will be displayed. Some will return null 4 IBM Documentation for 7.2

By converting those results to character prevents this issues.


5 IBM Documentation for 7.1
A few more examples:
6 PowerSystems Redbooks (inc.
IBM i)

Popular Posts: Last


30 days

1 Defining variables in RPG all


free

2 New RPG built in function to


split apart a string

3 Creating PDF using SQL

Seeing which index or logical


4 file is being used by a SQL
statement

5 Upper and Lower built in


functions come to RPG

These show how I can get day and month name from the date, and some other information
from the date too. Again I had to convert the numeric results to character for all of the results
to be shown.
Popular Posts: All
Time
 

This article was written for IBM i 7.4, and should work for some earlier releases too. 1 Defining variables in RPG all
free

Written by
Simon Hutchinson
at
5:00 AM
2 Example subfile program
using modern RPG
Labels:
programming,
sql
3 Run SQL statements in your
CL

Email IFS files


4
5 comments:
5 Defining Procedures in RPG all
free
Jax April 21, 2021 at 10:12 AM
Creating PDF files from spool
6
In addition, if one wants the results in different columns instead, include the values in ().
files
Ex: values (current_server, current_time);
7 File definition in RPG all free
Reply

8 Externally described Data


Structures
Ken H April 22, 2021 at 2:31 AM
9 Creating a SQL table "on the
This stuff works fine in green on black interactive SQL. On V7R1M0 :) fly"
Reply
10 Happy 28th birthday!

cei_blog April 22, 2021 at 6:48 AM

Good morning Simon, I can't see the code. I am using Chrome. Thanks. Regards. Carlos Labels
Reply

CL
Replies 1

Simon Hutchinson April 22, 2021 at 9:44 AM DSPF


2
Most of the code is in image files inserted in the post.

Are those what you cannot see.


HISTORY
3
(I use Chrome too, IMHO it is the best brwoser)

IFS
4
Reply

5 LF

Anonymous April 22, 2021 at 10:44 AM NEW RELEASE


6
Most of these special registers can be viewed in the Environment tab which is next to the
Messages tab and if not visible can be seen by checking it from the View menu.
NODE.JS
7

-Matt
8 OPERATIONS
Reply

PF
9

PROGRAMMING
10
11 QUERY
Enter your comment...

RPG
12

13 SHARED
Comment as:
Ino Gomez (Go Sign out

SQL
14

Publish Preview
Notify me
15 USER GROUP

To prevent "comment spam" all comments are moderated.

16 VIRTUAL USER GROUP


Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If
this is you feel free to use the Contact Form to send me the comment and I will post it for you, please
include the title of the post so I know which one to post the comment to. Blog Archive
Newer Post Home Older Post
▼ 
2021
(40)
▼ 

► 
June
(1)
► 

► 
May
(8)
► 

▼ 
April
(11)
▼ 

Support for IBM i 7.2


comes to an end
Handling variable length
variables in CL
Display values of SQL
variables in ACS Run SQL
Scr...
Unlocking objects locked by
ACS Run SQL Scripts
New ACS 1.1.8.7
RPG PTFs for 7.4 TR4 and
7.3 TR10
Blogger's Follow by Email
ending
7.4 TR 4 and 7.3 TR10
announced
Displaying foreign key
constraints using SQL
Special religious day for IT
IBM KnowledgeCenter
replaced

► 
March
(5)
► 

► 
February
(8)
► 

► 
January
(7)
► 

► 
2020
(92)
► 

► 
2019
(89)
► 

► 
2018
(70)
► 

► 
2017
(92)
► 

► 
2016
(85)
► 

► 
2015
(86)
► 

► 
2014
(94)
► 

► 
2013
(59)
► 

3-Month Immersive
Learn to Code
Master your coding skills and

boost your career. Join the

leading bootcamp in Europe.


codeworks.me

OPEN

Copyright © 2013-2021 Simon Hutchinson.  All rights reserved.

View mobile site


Volvo XC60
El VOLVO XC60 es fuerza, aventura y deportividad. Consulta planes de
Abrir
financiación.
Rieder & Cia.

Powered by Blogger.

You might also like