You are on page 1of 37

Tips n Facts

(Version 1)

An e-book on AS/400 programming (OS/400 & CL/400)

-1TCS Internal

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: Ramakrishna Rao YVS Senior Software Engineer Signal Tree Solutions India Limited Mail to: Venkata.Yerrapatruni@signaltreesolutions.com

-2TCS Internal

Tips n Facts CONTENTS

THE FREQUENTLY ASKED QUESTIONS...............................................................................................7 Messages.........................................................................................................................................................7 HOW CAN WE COPY MESSAGES FROM ONE MESSAGE FILE TO ANOTHER ?......................................................................7 WHAT COMMANDS CAN BE SPECIFIED IN THE EXEC PARAMETER OF PROGRAM LEVEL MONMSG AND COMMAND LEVEL MONMSG?...................................................................................................................................................7 WHAT MESSAGE TYPES ARE MONITORED BY MONMSG COMMAND?.......................................................................7 Libraries.........................................................................................................................................................7 WHAT ARE PRODUCT LIBRARIES?........................................................................................................................7 WHAT IS THE SIGNIFICANCE OF QTEMP LIBRARY?...............................................................................................7 IF NO CURRENT LIBRARY EXISTS IN WHICH LIBRARY DOES A CREATE COMMAND CREATE THE OBJECT?.............................7 IS LIBRARY LIST AN OBJECT? IN WHICH ORDER IT IS SEARCHED ?...............................................................................7 WHAT IS THE MAXIMUM NUMBER OF LIBRARIES ALLOWED IN THE USER PART OF THE LIBRARY LIST?...............................8 WHAT IS THE DIFFERENCE BETWEEN PRODUCTION AND TEST LIBRARIES?...................................................................8 WHAT IS THE SIGNIFICANCE OF THE VALUES *LIBL, *ALLUSR AND *USRLIBL FOR THE LIBRARY PARAMETER ON ANY COMMAND ?................................................................................................................................................8 Database Files................................................................................................................................................8 WHAT IS A FLAT FILE?.......................................................................................................................................8 IF A CL PROGRAM CONTAINS THE REFERENCE TO A FLAT FILE, HOW CAN THE DATA BE RETRIEVED IN THE PROGRAM?.......8 HOW MANY RECORD-FORMATS CAN A DATABASE FILE HAVE, WHICH IS DECLARED IN CL?............................................8 WHAT COMMANDS ARE ALLOWED ON A DATABASE FILE DECLARED IN CL?................................................................8 DO I NEED TO DECLARE THE FIELDS OF A FILE, WHICH IS DECLARED IN A CL?............................................................8 HOW CAN I DEFINE A FILE MEMBER?....................................................................................................................8 WHAT HAPPENS IF A FILE IS CREATED WITH EXPIRY DATE LESS THAN CURRENT DATE?..................................................9 WHAT IS THE SIGNIFICANCE OF DYNSLT KEYWORD IN A LOGICAL FILE?.................................................................9 ARE KEY FIELDS MANDATORY FOR LOGICAL FILES? CAN LOGICAL FILES BE JOURNALED?..............................................9 HOW MANY COLUMN HEADINGS CAN BE SPECIFIED FOR A FIELD IN A PHYSICAL FILE?....................................................9 WHAT ARE VARIOUS TYPES OF ACCESS PATH MAINTENANCE?....................................................................................9 WHY WOULD YOU PREFER OPNQRYF TO LF? WHEN WOULD YOU PREFER AN LF?................................................9 WHAT IS FIELD REFERENCE FILE?......................................................................................................................9 WHAT IS THE USE OF RGZPF?..........................................................................................................................9 UNDER WHAT CIRCUMSTANCES WE WILL NOT BE ABLE TO DELETE A PF? ..................................................................9 WHEN DO WE USE CLOF COMMAND?...............................................................................................................10 Display files..................................................................................................................................................10 HOW ACTUALLY SNDRCVF WORKS? .............................................................................................................10 WHAT IS DIFFERENCE BETWEEN COMMAND ATTENTION (CA**) AND COMMAND FUNCTION (CF**) KEYS?...............10 WHAT WOULD BE THE EFFECT ON A FIELD WITH THE FOLLOWING DISPLAY ATTRIBUTES: REVERSE IMAGE, UNDERLINE, AND HIGH INTENSITY WHEN USED TOGETHER ?.............................................................................................................10 WHAT IS THE DIFFERENCE BETWEEN NON-DISPLAY AND HIDDEN FIELDS?................................................................10 OVRDBF & OPNQRYF............................................................................................................................10 WHAT IS THE NECESSARY COMMAND NEEDED BEFORE OPNQRYF AND WHY?........................................................10 WHAT IS THE SIGNIFICANCE OF SECURE PARAMETER ON OVRDBF COMMAND?..................................................10 WHAT IS THE SIGNIFICANCE OF SEQONLY PARAMETER ON OPNQRYF COMMAND?............................................11 PDM..............................................................................................................................................................11 WHAT IS THE SEQUENCE IN WHICH PDM OPTIONS ARE PROCESSED? ......................................................................11 WHAT ARE THE GROUPINGS OPTIONS ON PDM?..................................................................................................11 Commands...................................................................................................................................................11 IS THERE ANY SIMILARITY BETWEEN THE COMMANDS ALCOBJ AND CHKOBJ?....................................................11 WHAT DOES DSPPGMREF DO?....................................................................................................................11 WHAT ACTUALLY RCLRSC COMMAND DOES? ..................................................................................................11 WHAT IS THE DIFFERENCE BETWEEN THE COMMANDS CALL, RETURN, TFRCTL?............................................12 WHY CANT RETRIEVE COMMANDS BE USED ON THE COMMAND LINE?......................................................................12 -3TCS Internal

Tips n Facts
Operators.....................................................................................................................................................12 WHAT ARE THE VARIOUS CONCATENATION OPERATORS IN A CL PROGRAM?.............................................................12 WHAT ARE THE VARIOUS TYPES OF OPERATORS THAT CAN BE USED IN CL?..............................................................13 General.........................................................................................................................................................13 WHAT IS THE DIFFERENCE IN ASSIGNING VALUE TO A CHARACTER VARIABLE WITH APOSTROPHES AND WITH OUT APOSTROPHES IN A CL PROGRAM? ....................................................................................................................13 IS RECURSION ALLOWED ON CL PROGRAMS?.......................................................................................................13 DO ALL THE OBJECTS REFERRED TO IN A CL PROGRAM, NEED TO EXIST AT THE TIME OF THE CL PROGRAM COMPILATION? ....................................................................................................................................................................13 WHAT IS THE DIFFERENCE BETWEEN CONTINUING A SOURCE STATEMENT WITH A PLUS SIGN (+) AND A MINUS SIGN (-)? . 14 WHAT IS ASYNCHRONOUS COMMUNICATION?.......................................................................................................14 WHAT ARE THE DIFFERENT WAYS TO PASS DATA BETWEEN PROGRAMS? WHICH ONE IS THE MOST EFFICIENT WAY?.........14 EXPLAIN ABOUT CUA AND SAA?...................................................................................................................14 WHAT IS JOB DESCRIPTION?.............................................................................................................................14 WHAT IS AN AUTHORIZATION LIST?....................................................................................................................14 WHAT ARE THE VALID DATA TYPES ON AS/400?................................................................................................14 WHAT IS THE DIFFERENCE BETWEEN INTERACTIVE AND BATCH JOBS?......................................................................15 THE TIPS.........................................................................................................................................................16 TO VIEW THE PROGRAM SOURCE WE GENERALLY USE 2 OR 5 OPTION ON PDM. IS THERE ANY OTHER WAY TO IT?.........16 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?..............................................................16 HOW CAN I KNOW THE SYSTEM DATE, ITS FORMAT ETC.?.......................................................................................16 CAN I RETRIEVE A CL SOURCE, WHICH I HAVE DELETED BY MISTAKE?....................................................................16 CAN I AVOID SOURCE LISTING WHILE COMPILING A CL PROGRAM?.........................................................................16 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 ?..............................................................................................................................16 WHAT ARE THE VARIOUS METHODS OF MINIMIZING THE PROGRAM OBJECT SIZE?........................................................16 WHAT IS OBSERVABILITY?................................................................................................................................17 WHAT IS OPTIMIZATION?..................................................................................................................................17 WHAT IS THE SIGNIFICANCE OF CPROBJ COMMAND?.........................................................................................17 HOW DO I KNOW WHETHER AN OBJECT IS COMPRESSED OR NOT?.............................................................................17 HOW CAN YOU RETRIEVE THE PROGRAM NAME IN A CL PROGRAM?........................................................................17 CAN I PASS A NUMERIC VARIABLE FOR THE CALL TO A PROGRAM FROM COMMAND LINE?............................................18 HOW CAN YOU READ A PARTICULAR MEMBER OF A PHYSICAL FILE IN YOUR PROGRAM? ..............................................18 GENERALLY STRISDB IS USED FOR DEBUGGING CLP. CAN I DEBUG A CLP USING STRDBG COMMAND? ............18 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?......................................................................................................................................18 CAN I KNOW IN WHAT ALL CL PROGRAM OBJECTS A PARTICULAR COMMAND IS BEING USED?.....................................18 IS IT POSSIBLE TO HAVE DIFFERENT DESCRIPTIONS FOR A SOURCE AND ITS OBJECT?....................................................18 HOW CAN WE TAKE A BACK UP OF THE SPOOL FILE?.............................................................................................18 HOW CAN I KNOW ALL THE COMMANDS STARTING WITH A PARTICULAR STRING?.......................................................19 WHAT IS THE SIGNIFICANCE OF MRGSRC (MERGE SOURCE) COMMAND?..............................................................19 HOW CAN I SEARCH FOR A STRING IN ALL THE MEMBERS OF A SOURCE PHYSICAL FILE?..............................................19 WHAT ARE USER-DEFINED OPTIONS?..................................................................................................................19 CAN I USE CPYF COMMAND FOR COPYING A LOGICAL FILE?.................................................................................19 HOW CAN I KNOW THE DEPENDANT LOGICAL FILES ON A PHYSICAL FILE?.................................................................19 HOW CAN I KNOW ALL THE FILES USING THE FORMAT OF A PHYSICAL FILE?..............................................................19 FOR WHAT ALL INFORMATION I CAN USE DSPFD COMMAND?...............................................................................19 CAN I KNOW THE RECORD COUNT IN A FILE USING RUNQRY COMMAND?.............................................................20 CAN I SELECT RECORDS FROM A FILE BASED ON CERTAIN CRITERIA USING RUNQRY COMMAND?..............................20 HOW DO I SPECIFY THE OR AND AND SELECT/OMIT CONDITIONS IN THE DDS OF A LOGICAL FILE?.....................20 CAN I AVOID UNDERLINING OF INPUT FIELDS ON DISPLAY FILE SCREEN?...................................................................20 CAN I RETAIN THE SCREEN AFTER CLOSING THE DISPLAY FILE?...............................................................................20 CAN YOU COPY THE RECORDS CREATED BY THE OPNQRYF TO OTHER FILES? .......................................................20 HOW TO PRINT THE HELP FOR ONE CL COMMAND KEYWORD PARAMETER ? ..............................................................20 -4TCS Internal

Tips n Facts
WE CAN RESTORE THE SOURCE CHANGES BUT NOT THE SOURCE DATE FOR A PARTICULAR LINE OF CODE. IS THERE ANY WAY OUT? ............................................................................................................................................................20 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? ...................................................................21 IS IT POSSIBLE TO USE SQL IN CL PROGRAMS?...................................................................................................21 ...................................................................................................................................................................21 HOW CAN I AVOID STATUS MESSAGE WHILE RUNNING COMMANDS LIKE CPYF, OPNQRY ETC. IN A CL PROGRAM? . .21 HOW TO USE QCMDEXC?............................................................................................................................21 THE FACTS....................................................................................................................................................23 APPENDIX A - USING COMMAND PROMPTS.........................................................................................24 APPENDIX B - SELECTIVE PROMPTING CHARACTER......................................................................24 APPENDIX C - OBJECT AUTHORITIES AND LOCK STATES.............................................................25 OBJECT AUTHORITIES......................................................................................................................................25 OBJECT LOCK STATES......................................................................................................................................26 APPENDIX D - MESSAGE QUEUES AND MESSAGES............................................................................27 TYPES OF MESSAGE QUEUES..............................................................................................................................27 TYPES OF MESSAGES........................................................................................................................................27 SNDMSG (SEND MESSAGE)...........................................................................................................................28 SNDPGMMSG (SEND PROGRAM MESSAGE)....................................................................................................28 SNDUSRMSG (SEND USER MESSAGE)...........................................................................................................29 SNDBRKMSG (SEND BREAK MESSAGE).........................................................................................................29 DEFINING SUBSTITUTION VARIABLES...................................................................................................................29 APPENDIX E - %BINARY AND %SWITCH BUILT-IN FUNCTIONS.................................................30 USING THE %BINARY BUILT-IN FUNCTION.....................................................................................................30 USING THE %SWITCH BUILT-IN FUNCTION......................................................................................................31 APPENDIX F - DATA QUEUES......................................................................................................................32 TO CLEAR A DATA QUEUE:................................................................................................................................32 TO SEND DATA TO A DATA QUEUE:.....................................................................................................................32 TO RECEIVE DATA FROM DATA QUEUE:................................................................................................................32 APPENDIX G - DATA AREA ..........................................................................................................................33 APPENDIX H - SEU COLORS AND ATTRIBUTES...................................................................................34 APPENDIX I - SELECTING RECORDS USING THE OPNQRYF COMMAND...................................35 TO REQUEST A SELECTION AGAINST A CHARACTER CONSTANT ................................................................................35 TO REQUEST A SELECTION AGAINST A NUMERIC CONSTANT:....................................................................................35 WHEN COMPARING A CHARCTER FIELD VALUE TO A CL VARIABLE .........................................................................35 WHEN COMPARING A NUMERIC FIELD VALUE TO A CL VARIABLE ..........................................................................35 SELECTING RECORDS USING THE CONTAINS FUNCTION............................................................................................35 MAPPING FIELDS FOR PACKED NUMERIC DATA FIELDS............................................................................................35 USING THE "WILDCARD" FUNCTION....................................................................................................................35 APPENDIX J - USER DEFINED COMMANDS............................................................................................36 COMMAND STATEMENTS..................................................................................................................................36 ......................................................................................................................................................................36 COMMAND PROCESSING PROGRAM.....................................................................................................................36 VALIDITY CHECKING PROGRAM.........................................................................................................................36 -5TCS Internal

Tips n Facts
PROMPT OVERRIDE PROGRAM...........................................................................................................................36 COMMAND CREATION......................................................................................................................................36 The code for the Command Program (WM)...........................................................................................37 The code for Command Processing Program (WMPRC).....................................................................37 The code for Command Validity Checking Program (WMVAL)........................................................37

-6TCS Internal

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.

-7TCS Internal

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.

-8TCS Internal

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. Under what circumstances we will not be able to delete a PF? - When there are dependent Logical Files -9TCS Internal

Tips n Facts
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 TCS Internal

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 TCS Internal

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 TCS Internal

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 & *CAT || ADD + *EQ = *OR | *BCAT |> SUB *GT > *TCAT |< MULT * *LT < DIV / *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 1 A 0000000001 A 1

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 TCS Internal

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 T Time Z Timestamp - 14 TCS Internal

Tips n Facts
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 TCS Internal

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) e.g. DSPPFM FILE(REFUND/QRPGSRC) MBR(LRBLAJ) 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) e.g. DSPPFM FILE(REFUND/LPINVTYP) 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. e.g. RTVCLSRC PGM(refund/LC#NREX) SRCFILE(mainp/QCLSRC) program LC#NREX is created in library MAINP 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. CHGPGM PGM(REFUND/LRBLAJ) FRCCRT(*YES) What are the various methods of minimizing the program object size? - Removal of observability - Optimization - Compression - 16 TCS Internal

Tips n Facts

What is observability? - 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)) - 17 TCS Internal

Tips n Facts
ENDPGM Please note that the below statement will retrieve the calling program name: CHGVAR VAR(&CALLING) VALUE(%SST(&SENDER 56 10)) 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 TCS Internal

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 TCS Internal

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 TCS Internal

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 positions. Thus, to replace a library list, the call to the QCMDEXC program would look like this:

- 21 TCS Internal

Tips n Facts
CALL PGM (QCMDEXC) PARM ('CHGLIBL LIBL (QGPL NEWLIB QTEMP)' 31)

- 22 TCS Internal

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. The command MOVOBJ is used to move the object from one library to another. 13. DCL, DCLF commands must precede all other commands except the PGM command. 14. The system message file is QCPFMSG. You can view all the exception messages in this message file. 15. CL cannot be used for processing sub files within display files. However message sub files can be processed. 16. CL cannot be used to update or add records in database files. However, it can read records from the database files. 17. The only way, a program can determines that no messages were received by a RCVMSG command if the message text is blank. 18. 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. 19. Only one file can be declared in a CL.

- 23 TCS Internal

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 input-capable. - WRKMBRPDM ?%FILE(*N) The parameter is not displayed until F9 is pressed and the parameters are not input-capable. ?/ Reserved for IBM use.

- 24 TCS Internal

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 X X MGT X EXIST X ALTER X REF X --------------------Data- -------------------READ X X X ADD X UPDATE X DELETE X EXECUTE X X 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.

- 25 TCS Internal

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.

- 26 TCS Internal

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. 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. - 27 TCS Internal

Tips n Facts
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

Message Type

User X X X X

Informational Inquiry Completion Diagnostic Request Escape Status Notify

Message types that can be send with different message sending commands Sending Message Type message *INFO *INQ *RQS *COMP *DIAG *NOTIFY *ESCAPE *STATUS SNDMSG X X SNDUSRMSG X X SNDPGMMSG X X X X X X X X SNDBRKMSG X X 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. MSG('AS/400 MESSAGE FILE') TOUSR(#VYERRAP) + MSGTYPE (*INQ) RPYMSGQ (#VYERRAP)

E.g. SNDMSG

SNDPGMMSG (Send program message) E.g. 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. For *NOTIFY, *ESCAPE, *STATUS messages Message Id and Message file are mandatory. It does not take message text entered by the user. For status message: SNDPGMMSG MSGID(A000010) MSGF(MSGF1) TOPGMQ(*EXT) + MSGTYPE(*STATUS)

- 28 TCS Internal

Tips n Facts
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 queue. CLEAR(*ALL) removes all messages from message

- 29 TCS Internal

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.

- 30 TCS Internal

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 1 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)) . . ENDPGM Then the variable &A has a value of '1'.

- 31 TCS Internal

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 CALL ENDPGM To receive data from data queue: PGM DCL DCL DCL DCL DCL CALL 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) 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) 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') PGM(QSNDDTAQ) PARM(&QNAME &LIB &FLDLEN + &FIELD)

- 32 TCS Internal

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.

- 33 TCS Internal

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 * D Normal D RI D HI D RI_HI D UL D RI_UL D HI_UL D ND D BL D RI_BL * C C C C C C C C C C C C C C C C C C C C C * e s s s s s s s s s s eval write eval write eval write eval write eval write eval write eval write eval write eval write eval write eval Disk 1 1 1 1 1 1 1 1 1 1 RENAME(QRPGLESRC:SEUFMTCODE) Inz(x'20') Inz(x'21') Inz(x'22') Inz(x'23') Inz(x'24') Inz(x'25') Inz(x'26') Inz(x'27') Inz(x'28') Inz(x'29') ' + 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'

SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE SRCDTA = ' SEUFMTCODE *inlr = *on

- 34 TCS Internal

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*")')

- 35 TCS Internal

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.

- 36 TCS Internal

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 DCL DCL PARM(&FILE &LIBRARY) 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

- 37 TCS Internal

You might also like