Vous êtes sur la page 1sur 39

Tips n Facts

(Version 1)

An e-book on AS/400 programming


(OS/400 & CL/400)

-1-

Tips n Facts

Preface
In the initial stages of my career as an AS/400 application programmer,
I had many questions in my mind, which needed clarifications. Though
I could not get everything clarified I had to get on with my
programming as per my project requirements. I had to code in a
particular way without knowing why it has to be coded that way. Now,
all those questions in my mind got clarified but at the cost of time.
Of late, I realized that had I got clarified those questions in my mind I
could have done much better job as a programmer in the initial stages
itself. This prompted me to sum up my experiences as a programmer
for the benefit of the novice programmers. At the same time this book
can also serve as a quick reference for senior programmers.
Before using this book, you should be familiar with general
programming concepts and terminology, and have a general
understanding of Operating System/400 (OS/400) and the AS/400
system.
You may need to refer to IBM manuals for more specific information
about a particular topic.

Author:
Naveen Dronavalli

-2-

Tips n Facts
CONTENTS
THE FREQUENTLY ASKED QUESTIONS..............................................7
MESSAGES................................................................................7
COPYING MESSAGES FROM ONE MESSAGE FILE TO ANOTHER......................7
COMMANDS THAT CAN BE SPECIFIED IN THE EXEC PARAMETER OF MONMSG
...................................................................................................................... 7
MESSAGE TYPES MONITORED BY MONMSG COMMAND.................................7
LIBRARIES................................................................................7
PRODUCT LIBRARIES..................................................................................... 7
SIGNIFICANCE OF QTEMP LIBRARY................................................................7
QGPL LIBRARY............................................................................................... 7
LIBRARY LIST................................................................................................. 7
NUMBER OF LIBRARIES ALLOWED IN THE USER PART OF THE LIBRARY LIST..7
PRODUCTION VS TEST LIBRARIES..................................................................8
SIGNIFICANCE OF *LIBL, *ALLUSR, *USRLIBL FOR THE LIBRARY PARAMETER.8
DATABASE FILES.......................................................................8
FLAT FILE....................................................................................................... 8
RETRIEVING DATA FROM A FLAT FILE IN THE CL PROGRAM...........................8
NUMBER OF RECORD-FORMATS OF A DATABASE FILE DECLARED IN CL........8
COMMANDS ALLOWED ON A DATABASE FILE DECLARED IN CL.....................8
IMPLICIT FIELD DECLARATION FOR A FILE DECLARED IN CL..........................8
FILE MEMBER................................................................................................. 8
FILE CREATION WITH EXPIRY DATE LESS THAN CURRENT DATE....................9
DYNSLT KEYWORD IN A LOGICAL FILE............................................................9
KEY FIELDS FOR LOGICAL FILES AND JOURNALLING......................................9
COLUMN HEADINGS FOR A FIELD IN A PHYSICAL FILE...................................9
TYPES OF ACCESS PATH MAINTENANCE.........................................................9
OPNQRYF VS LOGICAL FILE............................................................................9
FIELD REFERENCE FILE..................................................................................9
RGZPFM (REORGANIZE PHYSICAL FILE MEMBER)..........................................9
DELETION OF A PHYSICAL FILE......................................................................9
CLOF COMMAND.......................................................................................... 10
DISPLAY FILES.........................................................................10
SNDRCVF (SEND RECEIVE FILE)...................................................................10
COMMAND ATTENTION (CA**) AND COMMAND FUNCTION (CF**) KEYS......10
FIELD WITH DISPLAY ATTRIBUTES: RI, UL, AND HI ......................................10
NON-DISPLAY VS HIDDEN FIELDS................................................................10
OVRDBF & OPNQRYF...............................................................10
NECESSARY COMMAND BEFORE OPNQRYF..................................................10
SECURE PARAMETER ON OVRDBF COMMAND.............................................10
SEQONLY PARAMETER ON OPNQRYF COMMAND..........................................10
PDM.......................................................................................11
SEQUENCE IN WHICH PDM OPTIONS ARE PROCESSED................................11
GROUPINGS OPTIONS ON PDM....................................................................11
COMMANDS............................................................................11
SIMILARITY BETWEEN THE COMMANDS ALCOBJ AND CHKOBJ.....................11
DSPPGMREF (DISPLAY PROGRAM REFERENCE)............................................11
RCLRSC (RECLAIM RESOURCE)....................................................................11
-3-

Tips n Facts
CALL VS RETURN VS TFRCTL.......................................................................11
RETRIEVE COMMANDS ON THE COMMAND LINE.........................................12
OPERATORS............................................................................12
CONCATENATION OPERATORS IN A CL PROGRAM........................................12
VARIOUS TYPES OF OPERATORS THAT CAN BE USED IN CL.........................13
GENERAL................................................................................13
ASSIGNING VALUE TO A CHARACTER VARIABLE WITH/WITHOUT
APOSTROPHES............................................................................................. 13
RECURSION IN CL PROGRAMS.....................................................................13
OBJECTS EXISTENCE AT THE TIME OF THE CL PROGRAM COMPILATION......13
CONTINUING A SOURCE STATEMENT WITH (+) AND A (-)?..........................14
ASYNCHRONOUS COMMUNICATION.............................................................14
DIFFERENT WAYS TO PASS DATA BETWEEN PROGRAMS..............................14
CUA AND SAA.............................................................................................. 14
JOB DESCRIPTION........................................................................................ 14
AUTHORIZATION LIST.................................................................................. 14
VALID DATA TYPES ON AS/400.....................................................................14
INTERACTIVE JOB VS BATCH JOB..................................................................15
THE TIPS...................................................................................16
VIEWING THE PROGRAM SOURCE WITH OPTIONS OTHER THAN 2 & 5........16
FIND A PARTICULAR STRING IN THE FILE RECORDS.....................................16
THE SYSTEM DATE, ITS FORMAT ETC...........................................................16
RETRIEVING A CL SOURCE...........................................................................16
AVOIDING SOURCE LISTING WHILE COMPILING A CL PROGRAM..................16
CHANGE IN THE TEXT OF THE OBJECT WITH OUT COMPILATION.................16
METHODS OF MINIMIZING THE PROGRAM OBJECT SIZE..............................16
OBSERVABILITY............................................................................................ 16
OPTIMIZATION............................................................................................. 17
CPROBJ (COMPRESS OBJECT) COMMAND.....................................................17
KNOWING WHETHER AN OBJECT IS COMPRESSED OR NOT.........................17
RETRIEVING THE PROGRAM NAME IN A CL PROGRAM.................................17
PASSING A NUMERIC VARIABLE FROM COMMAND LINE...............................18
READING A PARTICULAR MEMBER OF A PHYSICAL FILE IN THE PROGRAM...18
DEBUGGING CL PROGRAM USING STRDBG COMMAND................................18
DSPSPLF (DISPLAY SPOOL FILE COMMAND).................................................18
PRTCMDUSG (PRINT COMMAND USAGE)......................................................18
DIFFERENT DESCRIPTIONS FOR A SOURCE AND ITS OBJECT.......................18
BACK UP OF THE SPOOL FILE.......................................................................18
KNOWING ALL THE COMMANDS STARTING WITH A PARTICULAR STRING....19
SIGNIFICANCE OF MRGSRC (MERGE SOURCE) COMMAND...........................19
SEARCHING FOR A STRING IN ALL THE MEMBERS OF A SOURCE PHYSICAL
FILE............................................................................................................. 19
USER-DEFINED OPTIONS.............................................................................. 19
COPYING A LOGICAL FILE............................................................................. 19
DEPENDANT LOGICAL FILES ON A PHYSICAL FILE........................................19
FILES USING THE FORMAT OF A PHYSICAL FILE...........................................19
INFORMATION PROVIDED BY DSPFD COMMAND..........................................19
RECORD COUNT IN A FILE USING RUNQRY COMMAND................................20
RECORD SELECTION USING RUNQRY COMMAND.........................................20

-4-

Tips n Facts
THE OR AND AND SELECT/OMIT CONDITIONS IN THE DDS OF A LOGICAL
FILE............................................................................................................. 20
AVOIDING UNDERLINING OF INPUT FIELDS ON DISPLAY FILE SCREEN.........20
RETAINING THE SCREEN AFTER CLOSING THE DISPLAY FILE.......................20
COPYING THE RECORDS SELECTED BY THE OPNQRYF.................................20
PRINTING THE HELP FOR ONE CL COMMAND KEYWORD PARAMETER.........20
RESTORING THE SOURCE FOR A PARTICULAR LINE OF CODE......................20
CREATING JOBLOG WHENEVER A USER SIGNS OUT.....................................21
USING SQL IN CL PROGRAMS.......................................................................21
AVOIDING STATUS MESSAGE WHILE RUNNING COMMANDS LIKE CPYF ETC. 21
USING QCMDEXC......................................................................................... 21
THE FACTS................................................................................22
APPENDIX A - USING COMMAND PROMPTS....................................23
APPENDIX B - SELECTIVE PROMPTING CHARACTER.........................23
APPENDIX C - OBJECT AUTHORITIES AND LOCK STATES...................24
OBJECT AUTHORITIES.................................................................................. 24
OBJECT LOCK STATES..................................................................................25
APPENDIX D - MESSAGE QUEUES AND MESSAGES...........................26
TYPES OF MESSAGE QUEUES.......................................................................26
TYPES OF MESSAGES................................................................................... 26
SNDMSG (SEND MESSAGE)..........................................................................27
SNDPGMMSG (SEND PROGRAM MESSAGE)..................................................27
SNDUSRMSG (SEND USER MESSAGE)..........................................................28
SNDBRKMSG (SEND BREAK MESSAGE)........................................................28
DEFINING SUBSTITUTION VARIABLES..........................................................28
APPENDIX E - %BINARY AND %SWITCH BUILT-IN FUNCTIONS...........29
USING THE %BINARY BUILT-IN FUNCTION....................................................29
USING THE %SWITCH BUILT-IN FUNCTION...................................................30
APPENDIX F - DATA QUEUES..........................................................31
TO CLEAR A DATA QUEUE:...........................................................................31
TO SEND DATA TO A DATA QUEUE:..............................................................31
TO RECEIVE DATA FROM DATA QUEUE:........................................................31
APPENDIX G - DATA AREA.............................................................32
APPENDIX H - SEU COLORS AND ATTRIBUTES.................................33
APPENDIX I - SELECTING RECORDS USING THE OPNQRYF COMMAND
...................................................................................................34
TO REQUEST A SELECTION AGAINST A CHARACTER CONSTANT..................34
TO REQUEST A SELECTION AGAINST A NUMERIC CONSTANT:.....................34
WHEN COMPARING A CHARCTER FIELD VALUE TO A CL VARIABLE..............34
WHEN COMPARING A NUMERIC FIELD VALUE TO A CL VARIABLE.................34
SELECTING RECORDS USING THE CONTAINS FUNCTION.............................34
MAPPING FIELDS FOR PACKED NUMERIC DATA FIELDS................................34
USING THE "WILDCARD" FUNCTION............................................................34

-5-

Tips n Facts
APPENDIX J - USER DEFINED COMMANDS.......................................35
COMMAND STATEMENTS............................................................................. 35
COMMAND PROCESSING PROGRAM.............................................................35
VALIDITY CHECKING PROGRAM....................................................................35
PROMPT OVERRIDE PROGRAM.....................................................................35
COMMAND CREATION..................................................................................35
THE CODE FOR THE COMMAND PROGRAM.................................36
THE CODE FOR COMMAND PROCESSING PROGRAM....................36
THE CODE FOR COMMAND VALIDITY CHECKING PROGRAM.........36

-6-

Tips n Facts
The Frequently Asked Questions

Messages
How can we copy messages from one message file to another?
- Use the command MRGMSGF. For example:
MRGMSGF FROMMSGF (MYLIB1/MSGF1) TOMSGF (MYLIB1/MSGF2)
What commands can be specified in the EXEC parameter of program level
MONMSG and command level MONMSG?
- GOTO is the only valid value for the EXEC parameter on the program level MONMSG.
- Any CL command can be coded in the EXEC parameter of the command level MONMSG.
- The action specified on the command level MONMSG overrides the action specified on
the program level MONMSG.
What message types are monitored by MONMSG command?
- The MONMSG command monitors only *STATUS, *NOTIFY AND *ESCAPE messages It does
not monitor *INFO and *INQ messages.

Libraries
What are Product libraries?
- The product libraries are used to support languages and utilities that are
dependent on libraries other than the system library, QSYS, to process their
commands.
What is the significance of QTEMP library?
- The QTEMP library is cleared when a job ends.
- As SBMJOB command initiates a new routing step, QTEMP library is not passed on to the
submitted job but this submitted job will have its own QTEMP library, which is not visible
to other jobs.
- You can move object out of QTEMP but not in to QTEMP.
If no current library exists in which library does a Create command create
the object?
- The object gets created in QGPL with Create command.
Is Library list an object? In which order it is searched?
- Library list is not an object.
- The order in which the parts of the library list are searched is System, Product, Current
and User.
- There is no OS/400 command that saves the user library list. It has to be taken care of in
the job description.

-7-

Tips n Facts
What is the maximum number of libraries allowed in the user part of the
library list?
- A maximum of 25 libraries can be present in the user part of the library list.
- Please note that libraries can never be created within libraries.
What is the difference between Production and Test libraries?
- Database files in Production library cannot be opened for update by a program running in
debug mode if UPDPROD (*NO) was specified on the STRDBG command.
- This restriction does not apply to database files in Test library.
What is the significance of the values *LIBL, *ALLUSR and *USRLIBL for the
library parameter on any command?
- *LIBL is used to search for an object in the library list.
- *ALLUSR is used to search for an object in all the user-defined libraries existing on
the system.
- *USRLIBL is used to search for an object only in the user part of the library list.

Database Files
What is a flat file?
- It is a file created with out any DDS. Record length has to be given. For example:
CRTPF FILE (MYLIB1/PF1) RCDLEN (132)
- The fields for this file can be described with in the program in which it is being used.
Hence it is also called program-described file.
If a CL program contains the reference to a flat file, how can the data be
retrieved in the program?
- The data can be retrieved from the variable &FILENAME.
How many record-formats can a database file have, which is declared in CL?
- Only database files with single record format can be used in a CL program.
- Please note that the database file need not have member when it is referred to
create a program.
What commands are allowed on a database file declared in CL?
- Only RCVF command is allowed for database file as it can be opened for input
only.
Do I need to declare the fields of a file, which is declared in a CL?
- If a database file is declared in CL, the fields in the file are automatically declared in the
CL program with & prefixed to it.
- Please note that the variable name in CL must begin with & followed by not more than
10 characters.
How can I define a file member?
- A member is a subset of records in a physical file (PF-SRC or PF-DTA). Each
member conforms to the characteristics of the file.

-8-

Tips n Facts
-

For PF-SRC members, you can define the type of a member as well. For example
CLP, RPGLE, PF, LF etc.

What happens if a file is created with expiry date less than current date?
- If a file is created with EXPDATE less than current date the file gets created but member
is not added on creation. An error message is sent at the time of creation saying that the
EXPDATE is invalid.
What is the significance of DYNSLT keyword in a logical file?
- DYNSLT keyword does the SELECT/OMIT processing when a program reads records, rather
than when records are added or changed.
Are key fields mandatory for logical files? Can logical files be journaled?
- Key fields are not mandatory for logical files. Logical files cannot be journaled.
How many column headings can be specified for a field in a physical file?
- For a field in a physical file, 3 column headings of not more than 20 bytes each can be
specified.
What are various types of access path maintenance?
- With MAINT (*IMMED), the access path is updated each time a record is changed, added,
or deleted from a member. *IMMED must be specified for files that require unique keys.
- With MAINT (*REBLD), the entire access path is rebuilt when the file is opened.
- With MAINT (*DLY), the access path is changed only for records added, changed, or
deleted since the last open.
Why would you prefer OPNQRYF to LF? When would you prefer an LF?
OPNQRYF
We prefer OPNQRYF when selection
criterion gets changed frequently.
OPNQRY is a temporary file, it does not
take any space on the disk.
As it has to process the query every time,
the run time for a particular program will
be more.

LF
We go for logical file, when selection
criterion is permanent.
LF is a permanent file and it takes space
on the disk.
Run time for a particular program will be
relatively less.

What is Field Reference File?


- A Field Reference File contains just the field descriptions. It does not contain any data. It
is used as reference for the field description for other files. This is used to simplify record
format descriptions and to ensure field descriptions are used consistently.
What is the use of RGZPF?
- The Reorganize Physical File Member (RGZPFM) command is used to compress (remove
deleted records from) the member of a physical file in the database.

-9-

Tips n Facts
Under what circumstances we will not be able to delete a PF?
- When there are dependent Logical Files
- When there is no authority
- When the PF is locked or in use
When do we use CLOF command?
- When a file is opened using either OPNQRYF or OPNDBF command, CLOF command
should be used to close the opened file.

Display files
How actually SNDRCVF works?
- The command SNDRCVF is the combination of write and read in that order. It writes the
record and waits for the user input. After pressing any key it reads the data.
What is difference between Command Attention (CA**) and Command
Function (CF**) keys?
- A key defined with CF** causes data to be returned to the program. A key defined with
CA** does not.
What would be the effect on a field with the following display attributes:
reverse image, underline, and high intensity when used together?
- The field will not be displayed i.e. becomes non-display.
What is the difference between Non-display and Hidden fields?
- Non-display - Causes the data in the field to be invisible to the operator. The display
positions for the fields appear to be blank. Use this attribute for passwords or other
security-sensitive data. Non-display fields do not print.
- Hidden - Type H to indicate a hidden field (one that is used for both input and output but
not displayed).

OVRDBF & OPNQRYF


What is the necessary command needed before OPNQRYF and why?
- OVRDBF. We use this to make sure that the ODP (open data path) created by the
OPNQRYF is shared by program.
What is the significance of SECURE parameter on OVRDBF command?
- Consider the following example:
OVRDBF
FILE(ACCTMAST) SHARE(*YES) SECURE(*YES)
It will prevent ACCTMAST file from being overridden to SHARE (*NO) by any program that is
called from the program in which the above command exists.

- 10 -

Tips n Facts
What is the significance of SEQONLY parameter on OPNQRYF command?
- The SEQONLY (Sequential Only) parameter indicates that the file will be processed
sequentially (Arrival Sequence) and that one record at a time will be transferred from the
database to the programs internal buffer.

PDM
What is the sequence in which PDM options are processed?
- If you select more than one PDM option on a list display, the options are
processed sequentially, starting with the first option selected.
What are the groupings options on PDM?
- When you select an option and press Enter, PDM first determines whether it is a
grouping option.
- The Copy option, the Rename option, the Delete option, and the Move option are
grouping options. If it is a grouping option, a grouping display is shown, listing all
the items for which a particular option was chosen and requesting confirmation
(and, possibly, additional input).

Commands
Is there any similarity between the commands ALCOBJ and CHKOBJ?
- Both the commands do checking for the existence of an object. ALCOBJ command
allocates the object in addition to performing the existence check.
What does DSPPGMREF do?
- Displays the list of all objects used in the program.
What actually RCLRSC command does?
- The resources that are reclaimed by this command are

Static storage
Open files of object type *FILE
User interface manager (UIM) application resources
Common Programming Interface (CPI) Communications conversations
Hierarchical file systems (HFS) resources
User-defined communications sessions.

For an original program model (OPM) program, its static storage will be reclaimed.
For an Integrated Language Environment (ILE) program, its static storage will be
marked so that it will be re-initialized on the next call.
Static storage is not affected for a service program, or any ILE program running in
an activation group other than the default activation group.
The RCLRSC command is not needed to reclaim the files and static storage of
most programs, such as CL programs that end (return) normally, RPG programs
that have the last record (LR) indicator set on, and COBOL programs.

- 11 -

Tips n Facts
What is the difference between the commands CALL, RETURN, TFRCTL?
- In a CALL, the calling program receives the control after the called program
finishes the processing at the command after the call to called program. Control is
thus returned up the program stack.
- The RETURN command has no parameters and removes the program from the
program stack. If no RETURN statement is coded in a CL program, a return is
performed after the last executable statement is performed.
- The TRFCTL command transfers the control to the program and removes the
transferring program from the program stack. It returns the control to the
statement after the most recently run CALL command in the program that called
the transferring program. No statements after the TFRCTL in a CL program will be
executed.
Why cant retrieve commands be used on the command line?
- Retrieve commands can not be used on command line, as those commands need a
variable to store the retrieved value.
- Please note that retrieve commands can not be used even in a call to QCMDEXC.

Operators
What are the various concatenation operators in a CL program?
- The *CAT operator concatenates two character strings. Blanks are included in the
concatenation. For example:
ABC *CAT DEF becomes ABCDEF
'ABC ' *CAT 'DEF ' becomes 'ABC DEF '
-

The *BCAT operator truncates all trailing blanks in the first character string; one blank is
inserted, then the two character strings are concatenated. Leading blanks on the second
operand are not truncated. For example:
ABC *BCAT DEF becomes ABC DEF
'ABC ' *BCAT DEF becomes 'ABC DEF'

The *TCAT operator truncates all trailing blanks in the first character string, then the two
character strings are concatenated. All leading blanks on the second operand are not
truncated. For example:
ABC *TCAT DEF becomes ABCDEF
'ABC ' *TCAT DEF becomes 'ABCDEF'
ABC *TCAT ' DEF' becomes 'ABC DEF'
'ABC '*TCAT ' DEF' becomes 'ABC DEF'

All blanks that surround the concatenation operator are ignored, but at least one blank
must be on each side of the reserved value operator (*CAT, *BCAT, or *TCAT). If multiple
blanks are wanted in the expression, a quoted character string (a character string
enclosed within apostrophes) must be used.

- 12 -

Tips n Facts
What are the various types of operators that can be used in CL?
- There are four broad categories of operators. Each operator can be replaced by a
special character as shown below:
Logical
operator
Special
character
Character
operator
Special
character
Arithmetic
operator
Special
character
Relational
operator
Special
character

*AND

*OR

&

*CAT

*BCAT

*TCAT

||

|>

|<

ADD

SUB

MULT

DIV

*EQ

*GT

*LT

*GE

*LE

*NE

*NG

*NL

>

<

>=

<=

>

<

General
What is the difference in assigning value to a character variable with
apostrophes and with out apostrophes in a CL program?
- When you assign value to a character variable without apostrophes the value would be
translated to uppercase.
- The value is assigned as it is in case of assigning with apostrophes.
- Also observe the assignment for the variables in the following example:
DCL
DCL
CHGVAR
CHGVAR
CHGVAR
CHGVAR
CHGVAR

VAR(&RES1) TYPE(*CHAR) LEN(10)


VAR(&RES2) TYPE(*DEC) LEN(10)
VAR(&RES1)
VAR(&RES1)
VAR(&RES1)
VAR(&RES1)
VAR(&RES2)

VALUE(1) results in
VALUE(A) results in
VALUE(1) results in
VALUE(a) results in
VALUE(1) results in

0000000001
A

Is recursion allowed on CL programs?


- Under any circumstances a CL program may call itself in the same manner that it calls
any other program i.e. recursion is allowed.
Do all the objects referred to in a CL program, need to exist at the time of
the CL program compilation?
- For most of the objects referred to in a CL program, the object dos not have to
exist when the program is compiled.
- However, Files and command definitions are exceptions to this rule.

- 13 -

Tips n Facts
What is the difference between continuing a source statement with a plus
sign (+) and a minus sign (-)?
- The difference is that all the blanks in the next record that precede the first non-blank
character are ignored when a plus sign is coded and included when a minus sign is
coded.
What is asynchronous communication?
- It is the communication in which one of the commands waits for the output from
another command to get executed. This involves WAIT parameter.
- In the below example the RCVMSG waits for 10 seconds to receive the message
from the command SNDPGMMSG.
SNDPGMMSG MSGID(A000004) MSGF(MYLIB1/MSGF1)
RCVMSG
PGMQ(*PRV) WAIT(10) SENDER(&SENDER)
What are the different ways to pass data between programs? Which one is
the most efficient way?
- Parameters, Data area, Data queue, Message queues, Files
- Data queues are the most efficient way of data transfer.
Explain about CUA and SAA?
- Common User Access standards (CUA) are the standards for designing user interface of
an application.
- System Application Architecture standards (SAA) are the standards for coding.
What is Job Description?
- The job description may contain request data that causes a program or a command to
run.
- Job descriptions can also specify what user profile the job should run under.
- The workstation entry tells what job description will be used when a job starts at that
workstation.
What is an authorization list?
- An Authorization list contains the access rights for individual users and groups of users
for the functions such as tasks, menus, batch environments, data sets and so on. For
each authorization list, 10 levels of authorization rights can be defined (0 to 9). Level 0
means no authorization and a level greater than 0 means authorization. You can secure
an object by the authorization list.
What are the valid data types on AS/400?
- The valid data types are
Entry
Meaning
A
Character
P
Packed decimal
S
Zoned decimal
B
Binary
F
Floating point
H
Hexadecimal
L
Date

- 14 -

Tips n Facts
T
Time
Z
Timestamp
What is the difference between Interactive and Batch jobs?
-

CL commands are used in either batch or interactive jobs.


The AS/400 system provides many menus and displays to assist the programmer,
including the Programmer Menu, the Command Entry display, command prompt displays,
and the Programming Development Manager (PDM) Menu to make interactive entries.
Interactive job has to wait for the issued command to complete to continue with another
command.
SBMJOB command causes the command to run in batch.
SBMJOB command causes the program that issues it to continue without waiting for the
issued command to complete.
In case of an exception, if the program is running in an interactive job, the system sends
the message to the job's external message queue. If the program is running as a batch
job, the system sends the message to the system operator message queue, QSYSOPR.

- 15 -

Tips n Facts
The Tips
To view the program source we generally use 2 or 5 option on PDM. Is there
any other way to it?
- Try using the following commands to view the code:
DSPPFM FILE (SRCPF) MBR (PROGRAM NAME)
DSPF
FILE (SRCPF) MBR (PROGRAM NAME)
The RUNQRY command displays the records but it is not possible to find a
particular string in the file records, as the find option is not provided.
Is there any way out?
- Try using the following commands to find a particular string:
DSPPFM FILE (FILE NAME)
DSPF
FILE (FILE NAME)
How can I know the system date, its format etc.?
- Use DSPSYSVAL command on the command line with the system values like QDATE,
QDATFMT, QDATSEP, QDAY, QDAYOFWEEK etc.
- Please note that the system date does not have any fixed format. It is always displayed
in the format specified in the QDATFMT system value.
Can I retrieve a CL source, which I have deleted by mistake?
- A CL program can be reconstructed from the object program by using the command
RTVCLSRC.
Can I avoid source listing while compiling a CL program?
- Yes. By specifying OPTION (*NOSOURCE) for source listing options on a CRTCLPGM
command only error messages are listed. A complete source listing is not printed.
If I change the text for a source, is there any other way to reflect that
change in the text of the object other than compilation?
- Yes. Use CHGPGM command to change the object text of a CL program without
recompiling the program. The CHGPGM command automatically recompiles the program
with the changed text. However, the attribute FRCCRT should be (*YES) on CHGPGM
command for automatic compilation.
What are the various methods of minimizing the program object size?
- Removal of observability
- Optimization
- Compression
What is observability?

- 16 -

Tips n Facts
-

Program observability consists of two types of data, namely Debug Data and Creation
Data:
Debug Data represented by the *DBGDTA value. This data is necessary to allow a
program to be debugged.
Creation Data represented by the *CRTDTA value. This data is necessary to translate the
code to machine instructions. The program must have this data for you to change the
program optimization level.
Using the Change Program (CHGPGM) command, you can remove either type of data
from the module, or remove both types. Removing all observability reduces the program
to its minimum size (with compression). Once this data is removed, you cannot change
the program in any way unless you compile the program again and replace the data. To
compile it again, you must have authority to the source code.

What is optimization?
- Optimization is a process where the system looks for processing shortcuts that reduce
the amount of system resources necessary to produce the same output.
- Optimization removes redundant instructions.
- To optimize, set the OPTIMIZE attribute on a CHGPGM command to *YES.
What is the significance of CPROBJ command?
- Use Compress Object (CPROBJ) command to compress selected objects in order to
save disk space.
- You can use the Decompress object (DCPOBJ) command to decompress objects
that have been compressed.
- Please note that the database files can not be compressed.
How do I know whether an object is compressed or not?
- Use DSPOBJD OBJ (TEST1) OBJTYPE (*PGM) DETAIL (*FULL) to know the
compression status.
- Compressed objects are temporarily or permanently decompressed when used,
depending on the object type and usage.
- For example *PGM is automatically permanently decompressed when used. *FILE
is automatically decompressed when opened. If only description is retrieved,
*FILE is temporarily decompressed.
How can you retrieve the program name in a CL program?
- Send a program message (SNDPGMMSG) to this job and receive (RCVMSG) the message.
The call stack entry will be the name of this program. In the following example, the
variable &PGMNM will have the program name:
PGM
DCL
VAR(&PGMNM) TYPE(*CHAR) LEN(10)
DCL
VAR(&CALLING) TYPE(*CHAR) LEN(10)
DCL
VAR(&SENDER) TYPE(*CHAR) LEN(80)
SNDPGMMSG MSGID(A000004) MSGF(MYLIB1/MSGF1)
RCVMSG
PGMQ(*PRV) SENDER(&SENDER)
CHGVAR
VAR(&PGMNM) VALUE(%SST(&SENDER 27 10))
ENDPGM
-

Please note that the below statement will retrieve the calling program name:
CHGVAR
VAR(&CALLING) VALUE(%SST(&SENDER 56 10))

- 17 -

Tips n Facts
Can I pass a numeric variable for the call to a program from command line?
- Yes, the hexadecimal value of the numeric variable has to be passed. The
following call command shows how to pass the value 25.5 to a program variable
that is declared as LEN(15 5) in hexadecimal value
CALL PGMA PARM (X02550F)
How can you read a particular member of a physical file in your program?
- Mention the physical file member name you want to read on data member (DTAMBR)
parameter of CRTLF command and use that logical file to read.
Generally STRISDB is used for debugging CLP. Can I debug a CLP using
STRDBG command?
- Yes. The steps involved are as follows:
Compile CLP using with Source listing options *SRCDBG.
Then issue command STRDBG PGM (PGM1) OPMSRC (*YES)
- Follow the same process for debugging RPG also.
It is very time consuming to go to spool and search for the spool file for the
latest compilation made. Is there any way out?
- Try this. If you are compiling a source by name PGM1, use the following command
to see its spool:
DSPSPLF FILE (PGM1) SPLNBR (*LAST)
Can I know in what all CL program objects a particular command is being
used?
- Use PRTCMDUSG (Print Command Usage) command.
Is it possible to have different descriptions for a source and its object?
- Yes, it is possible. When you try to compile a source the default for object text is
*SRCMBRTXT. Instead of *SRCMBRTXT you can type your own text.
- Please note that this is valid only for objects created from sources.
How can we take a back up of the spool file?
- Create a physical file with record length = Length of the record in spool + 12.
CRTPF FILE (MYLIB1/SPOOL) RCDLEN (144)
- Open the spool file with option 2 (CHGSPLFA) and make note of Spooled file, Job
name, User, Number, Spooled file number.
- Use CPYSPLF command as follows to copy the spool file to physical file SPOOL:
CPYSPLF FILE (PGM1) TOFILE (MYLIB1/SPOOL) JOB
(599815/#VYERRAP/QPADEV004C) SPLNBR (12)
- Now use CPYF command as follows:
CPYF FROMFILE (MYLIB1/SPOOL) TOFILE (MYLIB1/QCLSRC) TOMBR
(PGM1BKUP) MBROPT (*REPLACE) FMTOPT (*CVTSRC)
- The above process creates a member by name PGM1BKUP in source physical file
QCLSRC.

- 18 -

Tips n Facts
How can I know all the commands starting with a particular string?
- For example if you want to know all the commands starting with string CHG type
CHG* on command line and press enter.
What is the significance of MRGSRC (Merge source) command?
- If you are maintaining two copies of the same source and if one of the copies is
updated, you can reflect those updates in other copy by using MRGSRC command
(option 55 on PDM).
How can I search for a string in all the members of a source physical file?
- Type option 25 on first member in the source physical file.
- Press F13. Option 25 is repeated for all the members. Press Enter.
- Find String display is shown. Enter the string you want to search for and press
Enter.
- The members having the string in them are displayed one after another by
pressing Enter.
- The other way is to use FNDSTRPDM command as follows:
FNDSTRPDM STRING ('CHG') FILE (MYLIB1/QCLSRC) MBR (*ALL) OPTION
(*DSP)
What are User-defined options?
- With user-defined options, you can call your own commands from any PDM list
display. These options make it easier for you to do frequent operations, because
you can type an option on a list display instead of retyping an entire command.
- The process to create an user-defined option is as follows:
- Press F16 on PDM. Work with User-Defined Options display is shown.
- Press F6. Create User-Defined Option display is shown. Type the option and
command. For example: CC CHGCURLIB CURLIB (&L)
- Now you can use CC instead of CHGCURLIB as an option on PDM.
Can I use CPYF command for copying a logical file?
- If you try to copy a logical file using CPYF command a physical file with the same name is
created. Therefore CRTDUPOBJ command should be used.
How can I know the dependant logical files on a physical file?
- The DSPDBR command on a physical file can be used to display a list of dependent
logical files by default.
How can I know all the files using the format of a physical file?
- Use DSPDBR command with RCDFMT parameter on a physical file.
For what all information I can use DSPFD command?
- Use DSPFD command to know the number of records in a database file.
- Use TYPE (*MBRLIST) parameter on DSPFD command to know the members in a file.
- Use TYPE (*SELECT) parameter on DSPFD command to know the select/omit rules in a
logical file.
- Use TYPE (*JOIN) parameter on DSPFD command to know the join description in a join
logical file.

- 19 -

Tips n Facts

Can I know the record count in a file using RUNQRY command?


- Use OUTFORM (*SUMMARY) parameter on RUNQRY command to know the number of
records in a file.
Can I select records from a file based on certain criteria using RUNQRY
command?
- Use RUNQRY QRYFILE ((FILENAME)) RCDSLT (*YES).
How do I specify the OR and AND select/omit conditions in the DDS of a
logical file?
- The OR condition for select rule in LF:
A
A
A
A

S DEPART
S DEPART

COMP(EQ 117)
COMP(EQ 131)

The AND condition for select rule in LF:


S DEPART
DEPART

COMP(EQ 117)
COMP(EQ 131)

Can I avoid underlining of input fields on display file screen?


- By specifying CHGINPDFT at the file level or record level or field level the underlining of
input fields on the screen be prevented.
Can I retain the screen after closing the display file?
- Using the KEEP keyword at the record level will prevent the screen from being erased
when the display file is closed.
Can you copy the records created by the OPNQRYF to other files?
- Yes, by using CPYFRMQRYF.
How to print the help for one CL command keyword parameter?
- From a command line, type the CL command name and press F4 to display the command
prompt display. Position the cursor anywhere on the line of the keyword parameter for
which you want help. Press F1 to display the help for the keyword parameter. Press F14
to print the help.
We can restore the source changes but not the source date for a particular
line of code. Is there any way out?
- For example if you want to change the source date for a particular line of code in
member PGM1 in MYLIB1/QCLSRC, the steps involved would be:
- OVRDBF FILE (PGM1) TOFILE (MYLIB1/QCLSRC) MBR (PGM1)
- Start SQL session and enter the following command: UPDATE PGM1 SET SRCDAT =
111213 WHERE SRCDAT = 111215

- 20 -

Tips n Facts

The system creates a job log when it is idle long enough and the system
logs the user out but how can I have this created all the time i.e.
whenever a user signs out?
- Take prompt for SIGNOFF command and change the job log parameter to *LIST.
Is it possible to use SQL in CL programs?
- SQL in CL is no problem. Add this line to your CL program (MYCLPGM1):
RUNSQLSTM SRCFILE(MYLIB1/QCLSRC) SRCMBR(MYSQL1) COMMIT(*NONE)
-

Create MYSQL1 member with the required SQL statements: (the member type in PDM is
'SQL' instead of 'CLP')
DELETE FROM MYLIB1/TCAFILE;

Note: RUNSQLSTM runs the whole SQL member, no way to select only one statement of
it. So you must create more SQL members for a CLP, if you need to run the statements
from several places of your CLP. Perhaps like this: CLP = MYCLPGM, SQL members:
MYCLPGM1, MYCLPGM2, ... then you have them right below the CL in PDM. See the ';' at
the end of each line. It's important.

How can I avoid status message while running commands like CPYF,
OPNQRY etc. in a CL program?
- The following code will avoid status message:
DCL
VAR (&STSMSG)
TYPE (*CHAR) LEN (7)
RTVJOBA
STSMSG (&STSMSG)
CHGJOB
STSMSG (*NONE)
CPYF
CHGJOB

STSMSG (&STSMSG)

How to use QCMDEXC?


Execute Command (QCMDEXC) is an IBM-supplied program that runs a single
command. This command is used to activate another command. After the command
gets executed the control returns to your CL program.
The command runs as if it was not in a program. Therefore, variables cannot be used
on the command because values cannot be returned by the command to CL
variables. Additionally, the QCMDEXC program cannot run commands that can only
be used in CL procedures or programs. The format of the call to the QCMDEXC
program is the following:
CALL PGM (QCMDEXC) PARM (command command-length)
Enter the command you wish to run as a character string on the first parameter. You
must enclose the command in apostrophes if it contains blanks. The maximum
length of the character string is 6000 characters. Never count the delimiters (the
apostrophes) as part of the string. The length that is specified as the second value on
the PARM parameter is the length of the character string that is passed as the
command. Length must be a packed decimal value of length 15 with 5 decimal

- 21 -

Tips n Facts
positions. Thus, to replace a library list, the call to the QCMDEXC program would look
like this:
CALL PGM (QCMDEXC) PARM ('CHGLIBL LIBL (QGPL NEWLIB QTEMP)' 31)

- 22 -

Tips n Facts
The Facts
1. A CL program can handle up to 1000 MONMSG commands. Up to 50 message identifiers
can be entered on a MSGID parameter for a MONMSG command.
2. Up to 10 programs can be debugged simultaneously in a job.
3. CLP does not support zoned and binary variables. It supports only packed variables.
4. The maximum number of parameters that can be passed to another program is 40.
5. There is no limit on command label length as long as the label fits on one line in the
source record.
6. Up to 10 levels of embedding are permitted in CL. Let us see the IF condition embedding.
E.g. IF (A=1) THEN (IF (B=2) THEN (IF C=3) THEN (DO)))
7. When a call command is run in batch mode, variables passed as arguments are
treated as constants.
8. CL does not support arrays. CL does not support CASE statement.
9. A null value can not be passed to another program.
10. CL cannot be used for processing printer or ICF files.
11. All keywords in a CL command can be coded positional.
12. The command QCMD is used to display command entry screen.
13. The command MOVOBJ is used to move the object from one library to another.
14. DCL, DCLF commands must precede all other commands except the PGM command.
15. The system message file is QCPFMSG. You can view all the exception messages in this
message file.
16. CL cannot be used for processing sub files within display files. However message sub
files can be processed.
17. CL cannot be used to update or add records in database files. However, it can read
records from the database files.
18. The only way, a program can determines that no messages were received by a RCVMSG
command if the message text is blank.
19. If an override command through a call to QCMDEXEC is executed, the override will be in
effect at the same invocation level as the program that issued the call to QCMDEXEC.
20. Only one file can be declared in a CL.

- 23 -

Tips n Facts
Appendix A - Using Command prompts
-

On a prompt display of a command, enter ? on a field to know the permissible values


for that field. This character can be used in all entry fields. It performs the same function
as the F4 (Prompt) key.

On a prompt display of a command, enter & to increase the length of the entry field. If a
particular input field is not large enough for the parameter value or values you want to
type, you can expand the field by using the ampersand (&). The field will expand to the
next larger length of 25, 80, 132, 256, or 512 characters.

If you type a less than sign (<) followed by at least one blank in place of the first
character of a value, that value is deleted. This character can be used only in fields that
allow a list of values.

By typing a greater than sign (>) in the input field, you tell the system you want to type
additional values ahead of that value. On an input field that already contains a value,
type the > over the first character of the value and press the spacebar or press the Field
Exit key to remove the remaining characters. Then press the Enter key. The value in the
input field where you typed the > is not lost. When you enter the additional values and
press the Enter key, the replaced value reappears following the inserted value. This
character can be used only in fields that allow a list of values.

Appendix B - Selective prompting character.


The special prompt characters help us in displaying command prompts both on
command line and while running the programs. For example the command
? WRKMBRPDM will display the prompt as if F4 is pressed. Let us see how others
work
- WRKMBRPDM ??FILE (*N)
The parameter is displayed and input-capable.
- WRKMBRPDM ?*FILE(*N)
The parameter is displayed but not input-capable.
- WRKMBRPDM ?<FILE(*N)
The parameter is displayed and input-capable, but the command default is sent to
the CPP unless the value displayed on the parameter is changed.
- ?
WRKMBRPDM ?-FILE(*N)
The parameter is not displayed. The specified value is passed to the CPP. Not allowed
prompt override programs.
- WRKMBRPDM ?&FILE(*N)
The parameter is not displayed until F9 is pressed and the parameters are inputcapable.
- WRKMBRPDM ?%FILE(*N)
The parameter is not displayed until F9 is pressed and the parameters are not inputcapable.

- 24 -

Tips n Facts
-

?/ Reserved for IBM use.

- 25 -

Tips n Facts
Appendix C - Object Authorities and Lock states
Object Authorities
A user can be given one of the following authorities to objects: *ALL, *EXCLUDE,
*USE, *CHANGE.
Object
Authority
*ALL
*EXCLUDE
*USE
*CHANGE

---------------Object-------------OPR
X

MGT
X

EXIST
X

ALTER
X

--------------------Data--------------------REF
X

X
X

READ
X

ADD
X

X
X

UPDATE
X
X

DELETE
X

EXECUTE
X

Note: You can type an "X" or a blank to give or remove object/data authorities. For
some *FILE objects, a "/" may appear in the column. A "/" indicates that the user has
the specified authority to some, but not all of the fields in the file.
-

Object operational authority - It provides the user authority to display the objects
attributes.

Object management authority - It provides authority to specify security, to move


or rename the object, and to add members if the object is a database file.

Object existence authority - It provides authority to control the object's existence


and ownership.

Object alter authority - It provides authority to change the attributes of an object,


such as adding or removing triggers for a database file.

Object reference authority - It provides authority to specify the object as the first
level in a referential constraint.

Read authority - It provides authority to access the contents of the object.

Add authority - It provides authority to add entries to the object.

Update authority - It provides authority to change the content of existing entries


in the object.

Delete authority - It provides authority to remove entries from the object.

Execute authority - It provides authority to run a program or search a library or


directory.

- 26 -

X
X

Tips n Facts
Object Lock states
Objects are allocated on the basis of their intended use and whether they can be
shared. A lock state identifies the use of the object and whether it is shared. The five
lock states are as follows:
-

Exclusive (*EXCL) - The object is reserved for the exclusive use of the requesting
job. No other job can use the object.

Exclusive allow read (*EXCLRD) - The object is allocated to the job that requested
it but other jobs can read the object.

Shared for update (*SHRUPD) - The object can be shared either for update or read
with another job.

Shared no update (*SHRNUP) - The object can be shared with another job if the
job requests either a *SHRNUP lock state or *SHRRD lock state.

Shared for read (*SHRRD) - The object can be shared with another job if the user
does not request exclusive use of the object.

Use WRKJOB (work with job) command and take option 12 to display the lock states
for objects. Use WRKOBJLCK (Work with object locks) to display the lock state for a
specified object.

- 27 -

Tips n Facts
Appendix D - Message queues and Messages
Types of message queues
All messages are sent to the message queue. In addition to the below message
queues, you can create your own message queues for sending messages to system
users and between application programs.
-

Workstation message queue is used for sending and receiving messages


between workstation users and between workstation users and the system
operator.
User profile message queue can be used for communication between users. It
is automatically created when the user profile is created.
Job message queue is used for receiving requests to be processed and for
sending messages that result from processing the requests. It exists for each job
and only exists for the life of job. It consists of an external message queue (*EXT)
and a set of program message queues.
System operator message queue (QSYSOPR) is used for receiving and
replying to messages from the system, display station users, and application
programs.
The history log message queue is used for sending information to the history
log (QHST) from any job in the system.

Types of messages
-

Informational (*INFO) message that conveys information about the condition of


a function.
Inquiry (*INQ) message that conveys information and also asks for a reply.
Notify (*NOTIFY) message that describes a condition for which a program
requires corrective action.
Request (*RQS) message that requests a function from the receiving program.
Completion (*COMP) message that conveys completion status of work.
Diagnostic (*DIAG) message about errors in the processing of a system
function.
Status (*STATUS) message that describes the status of the work done by a
program. Status messages sent to the external message queue (*EXT) is shown at
the display station.
Escape (*ESCAPE) message that describes a condition for which a program
must end abnormally.

The message identifier you specify on the ADDMSGD command is used to refer to the
message and is the name of the message description. The message identifier must
be of 7 characters:
PPPMMNN
Where PPP is the product or application code, MM is the numeric group code and NN
is the numeric subtype code. The number specified as MMNN can be used to further
divide a set of product or application messages. Numeric group and subtype codes
consist of decimal numbers 0 through 9 and the characters A through F.
For example: CPF1234 is message 1234 of CPF.

- 28 -

Tips n Facts
You should use care in using a numeric subtype code of 00 in the message identifier.
If you use a numeric subtype code of 00 for a message that can be sent as an
escape, notify, or status message and that can, therefore, be monitored, a subtype
code of 00 in the Monitor Message (MONMSG) command causes all messages in the
numeric group to be monitored.
Message
Type
Informational
Inquiry
Completion
Diagnostic
Request
Escape
Status
Notify

Valid message types for message queue types


Message Queue Type
External
Program
QSYSOPR
Work
station
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X

User
X
X
X
X

Message types that can be send with different message sending commands
Sending
Message Type
message
*INFO *INQ *RQS *COMP *DIAG *NOTIFY *ESCAP
*STATUS
E
SNDMSG
X
X
SNDUSRMS
X
X
G
SNDPGMMS
X
X
X
X
X
X
X
X
G
SNDBRKMS
X
X
G
SNDMSG (Send message)
-

It can be used on a command line.


It can not use messages in message file for sending messages. It can only use the
message text entered by the user.
It can be used to send message either to a user profile or a message queue.
The type of messages allowed on SNDMSG are *INFO, *INQ.

E.g. SNDMSG

MSG('AS/400 MESSAGE FILE') TOUSR(#VYERRAP) +


MSGTYPE (*INQ) RPYMSGQ (#VYERRAP)

SNDPGMMSG (Send program message)


-

It can not be used on a command line.


It can use messages in message file for sending messages. It can also use the
message text entered by the user.
It can be used to send message either to a user profile or a message queue.
The type of messages allowed on SNDPGMMSG are *INFO, *INQ, *RQS, *COMP,
*DIAG, *NOTIFY, *ESCAPE, *STATUS.

- 29 -

Tips n Facts
-

For *NOTIFY, *ESCAPE, *STATUS messages Message Id and Message file are
mandatory. It does not take message text entered by the user.

E.g.

For status message:


SNDPGMMSG MSGID(A000010) MSGF(MSGF1) TOPGMQ(*EXT) +
MSGTYPE(*STATUS)
For message at display station:
SNDPGMMSG MSGID(A000010) MSGF(MSGF1)

SNDUSRMSG (Send user message)


-

It can not be used on a command line.


It can use messages in message file for sending messages. It can also use the
message text entered by the user.
It can be used to send message either to a user profile or a message queue.
The type of messages allowed on SNDMSG are *INFO, *INQ.

E.g. SNDUSRMSG MSG('AS/400 MESSAGE FILES') TOUSR(#VYERRAP)


SNDBRKMSG (Send break message)
- It can be used on a command line.
- It can not use messages in message file for sending messages. It can only use the
message text entered by the user.
- It can be used to send message only to a work station message queue.
- The type of messages allowed on SNDMSG are *INFO, *INQ.
E.g. SNDBRKMSG MSG('AS/400 MESSAGE FILES') +
TOMSGQ (QPADEV000D)
Defining substitution variables
Consider the message File &1 not found in message file. Here &1 is the substitution
variable. The value in &1 is populated to make the message more meaningful as
follows:
Add message Id P000001 in message file MSGF1 with message text as File &1 not
found. And define substitution variable &1 is as FMT ((*CHAR 10) in the message
file.
SNDPGMMSG MSGID(P000001) MSGF(MGS1) MSGDTA(ORDHDR)
&1 is replaced with ORDHDR. Now the message will be displayed as File ORDHDR
not found.
Please note that the command RMVMSG
message queue.

CLEAR(*ALL) removes all messages from

- 30 -

Tips n Facts
Appendix E - %BINARY and %SWITCH built-in Functions
Using the %BINARY built-in Function
The binary built-in function (%BINARY or %BIN) interprets the contents of a specified
CL character variable as a signed binary integer. The syntax of the binary built-in
function is:
%BIN (character-variable-name starting-position length)
The starting position and length are optional. You can use the binary built-in function
with both the IF and CHGVAR commands. The following are examples of the binary
built-in function:
DCL VAR(&B2) TYPE(*CHAR) LEN(2) VALUE(X'001C')
DCL VAR(&N) TYPE(*DEC) LEN(3 0)
CHGVAR &N %BINARY (&B2)
The content of variable &B2 is treated as a 2-byte signed binary integer and
converted to its decimal equivalent of 28. It is then assigned to the decimal variable
&N
DCL VAR(&N) TYPE(*DEC) LEN(5 0) VALUE(107)
DCL VAR(&B4) TYPE(*CHAR) LEN(4)
CHGVAR %BIN (&B4) &N
The value of the decimal variable &N is converted to a 4-byte signed binary
number and is placed in character variable &B4 Variable &B4 will have the value of
X'0000006B'.
DCL VAR(&P) TYPE(*CHAR) LEN(100)
DCL VAR(&L) TYPE(*DEC) LEN(5 0)
CHGVAR &L VALUE(%BIN(&P 1 2) * 5)
The first two characters of variable &P is treated as a signed binary integer,
converted to its decimal equivalent, and multiplied by 5. The product is assigned to
the decimal variable &L.

- 31 -

Tips n Facts
Using the %SWITCH built-in Function
The switch built-in function (%SWITCH) compares one or more of eight switches with
the eight switch settings already established for the job and returns a logical value of
'0' or '1'. The initial values of the switches for the job are determined first by the
Create Job Description (CRTJOBD) command; the default value is 00000000. You can
change this if necessary using the SWS parameter on the SBMJOB, CHGJOB, or JOB
command. Other high-level languages may also set job switches.
If, in the comparison of your %SWITCH values against the job values, every switch is
the same, a logical value of '1' (true) is returned. If any switch tested does not have
the value indicated, the result is a '0' (false). The syntax of the %SWITCH built-in
function is:
%SWITCH (8-character-mask)
The 8-character mask is used to indicate which job switches are to be tested, and
what value each switch is to be tested for. Each position in the mask corresponds
with one of the eight job switches in a job. Position 1 corresponds with job switch 1,
position 2 with switch 2, and so on. Each position in the mask can be specified as one
of three values: 0, 1, or X.
0

The corresponding job switch is to be tested for a 0 (off).

The corresponding job switch is to be tested for a 1 (on).

X
The corresponding job switch is not to be tested. The value in the switch does
not affect the result of %SWITCH.
If %SWITCH (0X111XX0) is specified, job switches 1 and 8 are tested for 0s; switches
3, 4, and 5 are tested for 1s; and switches 2, 6, and 7 are not tested. If each job
switch contains the value (1 or 0 only) shown in the mask, the result of %SWITCH is
true '1'.
On the IF command, %SWITCH can be specified on the COND parameter as the
logical expression to be tested. In the following example, 0X111XX0 is compared to
the predetermined job switch setting: IF COND(%SWITCH(0X111XX0)) THEN(GOTO
C)
If job switches 1, 3, 4, 5, and 8 contain 0, 1, 1, 1, and 0, respectively, the result is
true and the procedure branches to the command having the label C. If one or more
of the switches tested do not have the values indicated in the mask, the result is
false, and the branch does not occur.
On the CHGVAR command, you can specify %SWITCH to change the value of a logical
variable. The value of the logical variable is determined by the results of comparing
your %SWITCH settings with the job switch settings. If the result of the comparison is
true, the logical variable is set to '1'. If the result is false, the variable is set to '0'. For
instance, if the job switch is set to 10000001 and this procedure is processed:
PGM
DCL &A *LGL
CHGVAR VAR(&A) VALUE(%SWITCH(10000001))
.
.

- 32 -

Tips n Facts
ENDPGM
Then the variable &A has a value of '1'.

- 33 -

Tips n Facts
Appendix F - Data Queues
-

Data queues are a type of system object that you can create to which one HLL
program can send data. They are the fastest means of asynchronous
communication between two jobs. To receive and send data to DQ has fewer
overheads than using database files, message queues or data areas. They should
not be used for storing large volumes of data and for long term storage of data.
They are similar to message queues in that programs can send and receive data
from them. While only one program can have receive pending on a message
queue more than one program can have a receive pending on a message queue
at the same time.

To clear a data queue:


PGM
DCL
VAR(&QNAME) TYPE(*CHAR) LEN(10) VALUE('DTAQ1')
DCL
VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE('MYLIB1')
CALL
PGM(QCLRDTAQ) PARM(&QNAME &LIB)
ENDPGM
To send data to a data queue:
PGM
DCL
DCL
DCL
DCL

VAR(&QNAME) TYPE(*CHAR) LEN(10) VALUE('DTAQ1')


VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE('MYLIB1')
VAR(&FLDLEN) TYPE(*DEC) LEN(5) VALUE(17)
VAR(&FIELD) TYPE(*CHAR) LEN(17) +
VALUE ('Sample data queue')
CALL
PGM(QSNDDTAQ) PARM(&QNAME &LIB &FLDLEN +
&FIELD)
ENDPGM
To receive data from data queue:
PGM
DCL
DCL
DCL
DCL
DCL
CALL

VAR(&QNAME) TYPE(*CHAR) LEN(10) VALUE('DTAQ1')


VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE('MYLIB1')
VAR(&FLDLEN) TYPE(*DEC) LEN(5) VALUE(20)
VAR(&FIELD) TYPE(*CHAR) LEN(20)
VAR(&WAIT) TYPE(*DEC) LEN(5 0) VALUE(1)
PGM(QRCVDTAQ) PARM(&QNAME &LIB &FLDLEN +
&FIELD &WAIT)
ENDPGM
-

The commands using all the parameters:


CALL

PGM(QSNDDTAQ) PARM(&QNAME &LIB &FLDLEN +


&FIELD &KEYLEN &KEY)
CALL
PGM(QRCVDTAQ) PARM(&QNAME &LIB &FLDLEN +
&FIELD & WAIT &ORDER &KEYLEN &KEY &SENDRLEN &SNDR)

- 34 -

Tips n Facts
&QNAME is 10-length character field that names the data queue.
&LIB is 10-length character field that names the library containing data queue.
&FLDLEN is 5-digit packed decimal variable, which specifies the number of characters
sent to/received from the data queue.
&FIELD is a character field of length equal to the value in &FLDLEN.
&KEYLEN is a 3-digit packed decimal variable, which specifies the length of the key
sent to/received from the data queue.
&KEY is a character field of length equal to the value in &KEYLEN.
&WAIT is a 5-digit packed decimal variable, which waits for the time specified in this
variable if there are no entries in the data queue.
&ORDER is a 2-length character field that retrieves a message using the specified
character key like GT: or LT: or NE: etc
&SNDRLEN is a 3-digit packed decimal field that sends the length of the sender
identification parameter. It must be zero or equal to or greater than 8.
&SNDR is a character field that identifies the variable to contain the sender
identification information associated with the received message.
Appendix G - Data area
-

A local data area cannot be created, deleted or allocated.

A local data area can not be referred to from any other job. Other programs within same
job can refer it.

A Program Initialization Parameter data area (PIP) is created for each pre-start job
when the job is started. The size of PDA is 2000 bytes but the number of
parameters contained in it is not restricted.

A data area is an object used to hold data for access by any job running on the
system. It can be used to store information of limited size, independent of the
existence of programs and files.

A local data area (*LDA) is created for each job in the system with a length of
1024 and type *CHAR. It can not be referred to from any other job. It can not be
created, deleted or allocated. No library is associated with it.

The contents of the submitting jobs LDA is copied in to submitted jobs LDA.
Hence, the contents of LDA exist across routing step boundaries.

A group data area (*GDA) is created when an interactive job becomes a group job
with a length of 512 and type *CHAR. It can not be referred to from by jobs
outside the group. It can not be created, deleted or allocated. No library is
associated with it.

- 35 -

Tips n Facts
Appendix H - SEU Colors and Attributes
-

You need to embed the hex value for the display attribute (highlight, blink,
underline, color, etc.) directly in the source statement to achieve this.
Create a member by name SEUFMTCODE of type TEXT in source physical file
QRPGLESRC.
Do the following override and compile interactively the SEUCODES program of
type RPGLE:
OVRDBF FILE (DUMMY) TOFILE (MYLIB1/QRPGLESRC) MBR (SEUFMTCODE)
Call the program SEUCODES, which will keep lines for various attributes in
member SEUFMTCODE. Copy the line that you want into the member you are
editing and type over it.
The code for SEUCODES program
FDUMMY o e
*
D Normal
s
D RI
s
D HI
s
D RI_HI
s
D UL
s
D RI_UL
s
D HI_UL
s
D ND
s
D BL
s
D RI_BL
s
*
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
C
write
C
eval
*

Disk

RENAME(QRPGLESRC:SEUFMTCODE)

1 Inz(x'20')
1 Inz(x'21')
1 Inz(x'22')
1 Inz(x'23')
1 Inz(x'24')
1 Inz(x'25')
1 Inz(x'26')
1 Inz(x'27')
1 Inz(x'28')
1 Inz(x'29')
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
SRCDTA = '
SEUFMTCODE
*inlr = *on

' + RI + ' RI'


' + HI + ' HI'
' + RI_HI + ' RI_HI'
' + UL + ' UL'
' + RI_UL + ' RI_UL'
' + HI_UL + ' HI_UL'
Non-display next'
' + ND + ' ND'
' + BL + ' BL'
' + RI_BL + ' RI_BL'

- 36 -

Tips n Facts

Appendix I - Selecting Records Using the OPNQRYF Command


In all of the following examples, it is assumed that a single-format database file
(physical or logical) is being processed. (The FILE parameter on the OPNQRYF
command allows you to specify a record format name if the file is a multiple format
logical file.)
To request a selection against a character constant
OPNQRYF FILE(FILEA) QRYSLT('CODE *EQ "D" ')
To request a selection against a numeric constant:
OPNQRYF FILE(FILEA) QRYSLT('AMT *GT 1000.00')
When comparing a charcter field value to a CL variable
OPNQRYF FILE(FILEA) QRYSLT('"' *CAT &CHAR *CAT '" *EQ FIELDA')
Notice that apostrophes and quotation marks enclose the CL variables and *CAT
operators. (only character CL variables can be used)
When comparing a numeric field value to a CL variable
OPNQRYF FILE(FILEA) QRYSLT(&CHARNUM *CAT ' *EQ NUM')
Notice that apostrophes enclose the field and operator only. (only character CL
variables can be used)
Selecting records using the contains function
To process all records in which the Addr field contains the street named BROADWAY
you can specify:
OPNQRYF FILE(FILEA) QRYSLT('ADDR *CT "BROADWAY" ')
Mapping fields for packed numeric data fields
In this example, if DATE was a date data type, it could be specified as follows:
OPNQRYF FILE(FILEA) QRYSLT ('YEAR *EQ 88') MAPFLD((YEAR '%YEAR(DATE)'))
Note: Mapped field definitions are always processed before the QRYSLT parameter is
evaluated.
You could accomplish the same result by specifying the substring on the QRYSLT
parameter and dropping one of the mapped field definitions as follows:
OPNQRYF FILE(FILEA) +
QRYSLT('%SST(CHAR6 5 2) *EQ "88" ') +
MAPFLD((CHAR6 '%DIGITS(DATE)'))
Using the "wildcard" function
You would not select the other records because a comparison is made with blanks
added to the value you specified. The way to select all four names is to specify:
QRYSLT('NAME *EQ %WLDCRD("JOHNS*")')

- 37 -

Tips n Facts
Appendix J - User Defined Commands
The AS/400 control program lets users define a command that calls a program to
perform some function. Users can define commands by using a command definition
statement.
Command Statements
The command definition statement of each command contains one or more of the
following command statements:
-

CMD (Command) - Specifies the prompt text for the command (Only one
statement)
DEP (Dependent) - Defines the relationship among parameters
ELEM (Element) - Defines an element in a list used as a parameter value (A
maximum of 300 statements)
PARM (Parameter) - Defines a parameter or key parameter for a command (A
maximum 75 300 statements)
PMTCTL (Prompt Control) - Defines conditions under which certain parameters are
prompted
QUAL (Qualifier) - Defines a qualifier of a name used as a parameter (A maximum
of 300 statements)

Command Processing Program


The command processing program (CPP) is the program that the command analyzer
calls to perform the function requested. The CPP can be a CL program, another HLL
program. The CPP must accept the parameters as defined by the command definition
statements. A command processing program is mandatory.
Validity Checking program
To ensure that the valid values are entered for the required parameters, You may
write your own validity checking program. A Validity Checking program is optional.
Prompt Override Program
You can write prompt override programs to supply current values for parameter
defaults when prompting the command. For example, prompt override programs are
frequently used on Change commands to supply values for parameters with a default
value of *SAME. A prompt override program is optional.
Command Creation
Let us create command similar to WRKMBRPDM, by name WM with the following
functionality:
- When WM command is taken it will prompt for source file and library.
- After you enter valid values it will show that PDM with the source file and library
the user has entered.
- If incorrect values are entered, the validation program sends error messages.
We need three sources as follows:
- WM of type CMD - Command program.
- WMPRC of type CLLE - Command processing program.
- WMVAL of type CLLE - Command validation program.
- While compiling the command program take prompt to enter the processing
program and validation program.

- 38 -

Tips n Facts

The code for the Command Program (WM)


CMD
PARM
PARM

PROMPT('WORK WITH MEMBERS USING PDM')


KWD(FILE) TYPE(*NAME) LEN(10) PROMPT('File')
KWD(LIB) TYPE(*NAME) LEN(10) PROMPT('Library')

The code for Command Processing Program (WMPRC)


PGM
PARM(&File &Library)
DCL
VAR(&File) TYPE(*CHAR) LEN(10)
DCL
VAR(&Library) TYPE(*CHAR) LEN(10)
WRKMBRPDM FILE(&LIBRARY/&FILE)
ENDPGM

The code for Command Validity Checking Program (WMVAL)


PGM

PARM(&FILE &LIBRARY)

DCL
DCL

VAR(&FILE) TYPE(*CHAR) LEN(10)


VAR(&LIBRARY) TYPE(*CHAR) LEN(10)

/* Check for the existence of Library on the system

*/

CHKOBJ
OBJ(&LIBRARY) OBJTYPE(*LIB)
MONMSG
MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPD0006) MSGF(QCPFMSG) MSGDTA('0000 +
Library . . does not exist on the +
System.') MSGTYPE(*DIAG)
SNDPGMMSG MSGID(CPF0002) MSGF(QCPFMSG) MSGTYPE(*ESCAPE)
ENDDO
/* Check for the existence of Source File in the specified Library */
CHKOBJ
OBJ(&LIBRARY/&FILE) OBJTYPE(*FILE)
MONMSG
MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPD0006) MSGF(QCPFMSG) MSGDTA('0000 +
File . . does not exist in specified +
Library.') MSGTYPE(*DIAG)
SNDPGMMSG MSGID(CPF0002) MSGF(QCPFMSG) MSGTYPE(*ESCAPE)
ENDDO
ENDPGM

- 39 -

Vous aimerez peut-être aussi