CL Programming PDF
CL Programming PDF
Explain general programming concepts Explain CLs strengths and weaknesses as a programming language
Creating CL Programs
Library
PF-SRC
CRTMBR CLP
3
Program Processing
CL Command Syntax
Commands are continued from one line to another by placing a plus sign after the command or a parameter
5
CL Command Syntax
Continuing a CL Command
Continuing a CL Command
GRTOBJAUT OBJ(YOURLIBXX/CLSRC) OBJTYPE(*FILE) + USER(INTRO35) AUT(*OBJALTER *OBJEXIST + *OBJMGT *OBJOPR *OBJREF *ADD) SNDMSG MSG('The rain in Spain falls manely on the + lions.') TOUSR(INTRO99)
8
Continuing a CL Command
GRTOBJAUT OBJ(YOURLIBXX/CLSRC) OBJTYPE(*FILE) + USER(INTRO35) AUT(*OBJALTER *OB+ JEXIST *OBJMGT *OBJOPR *OBJREF *ADD) GRTOBJAUT OBJ(YOURLIBXX/CLSRC) OBJTYPE(*FILE) + USER(INTRO35) AUT(*OBJALTER *OB + JEXIST *OBJMGT *OBJOPR *OBJREF *ADD)
CL Programs
Begin with a PGM command and end with an ENDPGM command Comments (non-executable text) may precede the PGM statement Comments begin with a forward slash & an asterisk and end with an asterisk & a forward slash
Programs
Programs read and write data Data can come from storage, the OS, or the person who calls the program Programs can write data to storage, a printer or a workstation
Data Program Data Printout
Operating System
Storage
Data
Data
User
11
You can supply data when calling the program as follows: To receive the data, the program must have a PARM keyword in the PGM statement. The PARM keyword identifies the program variables that will hold the data PARM(&CUSTNAME &ORDAMT)
12
PGM
The parameters specified on the call must match the parameters specified in the PARM keyword CALL pgm1 (Walmart 275)
PGM
PARM(&CUSTNAME &ORDAMT)
If they dont match: CALL pgm1 (275) The program will not be run and you will get the following message:
Program Variables
Programs store input and output in program variables Just like a data base field, a program variable has a:
CL Program Variables
Are defined with a DCL (declare) command A CL program variable name must:
Begin with an ampersand (&) Has a max length of 11 Cannot contain spaces
DCL statements must be at the beginning of the program following the PGM statement
********************** &ORDAMT) TYPE(*CHAR) LEN(15) TYPE(*DEC) LEN(9 2)
15
*************** Beginning of data 0001.00 PGM PARM(&CUSTNAME 0002.00 DCL VAR(&CUSTNAME) 0003.00 DCL VAR(&ORDAMT)
RTVSYSVAL
SYSVAL(QTIME)
SNDUSRMSG - sends a message to the person running the program or a specified users message queue
MSG('I''ll be back')
SNDUSRMSG
SNDUSRMSG
You can build complex messages combining static text and program variables by using string functions
17
String Functions
- eliminates trailing spaces - one trailing space between strings *CAT &CURTIME) *TCAT &CURTIME) *BCAT &CURTIME)
Results in:
I'll be back at 14:09:08 I'll be back at14:09:08 I'll be back at 14:09:08
18
String Functions
start-location size)
Results in:
I'll be back at 14:09
19
0001.00 0002.00 0003.00 0004.00 0005.00 0006.00 0007.00 0008.00 0009.00 0010.00 0011.00 0012.00 0013.00 0014.00 0015.00 0016.00 0017.00 0018.00 0019.00 0020.00 0021.00 0022.00
CL Program
START:
DCL DCL DCL DCL
/* Create info is supplied and the variables defined*/ VAR(&FILENAME) VAR(&MEMNAME) VAR(&LIBNAME) VAR(&MEMTYPE) TYPE(*CHAR) TYPE(*CHAR) TYPE(*CHAR) TYPE(*CHAR) LEN(10) LEN(10) LEN(10) LEN(3) */
+ +
*/
*/
20
Compilation Reports
Library
PF-SRC
MSGQ
Compilation Report
CRTMBR CLP
Compile
21
Compilation Reports
22
Control field commands provide quick movement through the spool file
Move forward 5 pages Move backwards 5 pages Move to page 5 Move forward 5 lines Move backwards 5 lines Move to the right 5 columns Move to the left 5 columns Move to the fifth column Move to the end of the spool file Move to the beginning of the spool file
24
Find Area
Allows you to search for a character string within the compilation report Case sensitive To find a string:
Enter
25
Control Language Source SEQNBR *...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 100DCL VAR(&JOB) TYPE(*CHAR) LEN(7) * CPD0740 10 PGM command missing. 200DCL VAR(&USR) TYPE(*CHAR) LEN(10) 300RTVJOBA JOB(&JOB) * CPD0784 30 Variable &JOB for parameter JOB must be *CHAR, minimum length 10 400RTVJOBA USER(&USER) * CPD0727 40 Variable '&USER ' is referred to but not declared. 500SNDUSRMSG MSG('The job number is' *cat &job *cat + 600 'and the user is ' *cat &user *cat + 700 '.') TOUSR(&USER) * CPD0727 40 Variable '&USER ' is referred to but not declared. * CPD0727 40 Variable '&USER ' is referred to but not declared. 800GOTO CMDLBL(END) * CPD0725 10 End of source file reached without ENDPGM command. * * * * * E N D O F S O U R C E * * * *
26
Error messages
CPD0740
10
27
For every variable and label, the statement numbers that reference each are displayed Errors messages listed here also
Control Language Cross Reference Type *CHAR *CHAR Length References 7 300 500 10 ' declared but not referred to. GRA
5763SS1 V3R2M0 960517 Declared Variables Name Defined &JOB 100 &USR 200 * CPD0726 10 Variable '&USR Defined Labels Label Defined END ****** * CPD0715 30 Label 'END * * * *
R E F E R E N C E
28
Error message total Subtotals by severity level Successful or not message Max severity
Message Summary
Severity Total 0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90 8 0 3 0 2 3 0 0 0 0 Program COMPILEEX not created in library GRADES. Maximum error severity 40. * * * * * E N D O F M E S S A G E S U M
Source code that compiles can still have errors when run or have incorrect output If there is a run time error, the system will display a short message For more info about the problem:
Move
the cursor to the message Press F1 Additional Message Information will be displayed for the message
30
JOBLOG
Most of the time, Additional Message Information will be enough to understand the problem If not, all messages need to be checked. (Not just the one displayed by the system.) Display the JOBLOG by
Pressing
F10 at the Additional Message Information screen Or issue the DSPJOBLOG command
31
Some run time errors are not the result of incorrect programming e.g.
Incorrect
The program should not end when these types of errors occur
The program should check for these conditions and provide user friendly messages
32
MONMSG - allows the program, NOT the OS, to handle specified message(s) The CL command specified in the EXEC keyword is executed when the error occurs If MONMSG placed right after DCLs:
EXEC
CPF9810 - library does not exist CPF9812 - file does not exist This MONMSG results in an error handling routine being executed
MONMSG MSGID(CPF9812)
Can further investigate the cause of the problem Perform complex functions to solve the problem Allow the user to select a course of action from program defined options
35
Message Replies
Messages can be sent that require a reply The reply can be stored in a program variable The reply value can be the basis for conditional statement execution
36
Message Replies
MONMSG MSGID(CPF9810) EXEC(SNDUSRMSG MSG('THE LIBRARY + SPECIFIED DOES NOT EXIST. TO CREATE THE LIBRARY, REPLY + WITH A "Y". TO END THE PROGRAM, REPLY WITH A "N".') + MSGRPY(&REPLY) VALUES(Y N)) IF COND(&REPLY *EQ N) THEN(GOTO END) IF COND(&REPLY *EQ Y) THEN(CRTLIB &LIBNAME)
37
Points to Remember
CL commands can be grouped into programs Compilation reports are used to diagnose compile errors
38