cl programming.pdf
DESCRIPTION
CL ProgrammingTRANSCRIPT
![Page 1: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/1.jpg)
![Page 2: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/2.jpg)
Objectives
Explain general programming concepts
Explain CL’s strengths and weaknesses
as a programming language
Show how to create a CL program
Explain what a compilation report is and
how to use it to find program errors
2
![Page 3: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/3.jpg)
Creating CL Programs
Library
PF-SRC
CRTMBR
CLP
Compile
CRTMBR
*PGM
CLP
SEU
Programmer
CL
Commands
3
![Page 4: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/4.jpg)
Program Processing
Programs can execute instructions
3 ways
The default method is sequential,
I.e. in statement number order
Execution can also be conditional
and iterative.
4
![Page 5: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/5.jpg)
CL Command Syntax
The format for a CL Command is:
There is at least one space between
the:
Command
First parameter
Each succeeding parameter
Commands are continued from one
line to another by placing a plus sign
after the command or a parameter
COMMAND PARAMETER PARAMETER ….
5
![Page 6: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/6.jpg)
CL Command Syntax The + must be preceded by at least a
space if the continuation is between:
a command and a parameter
two parameters
COMMAND +
PARAMETER PARAMETER
COMMAND+
PARAMETER PARAMETER
COMMAND PARAMETER PARAMETER +
PARAMETER PARAMETER +
PARAMETER
COMMAND PARAMETER PARAMETER+
PARAMETER PARAMETER6
![Page 7: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/7.jpg)
Continuing a CL Command
COMM+
AND PARAMETER PARMETER
COMMAND PARAMETER PARA+
METER
COMM +
AND PARAMETER PARMETER
COMMAND PARAMETER PARA +
METER
The + is not preceded by space(s) if the
continuation is in the middle of the:
Command word
Parameter keyword
7
![Page 8: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/8.jpg)
Continuing a CL Command
If a parameter value(s) allows
spaces, then the + is preceded by
space(s)
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
![Page 9: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/9.jpg)
Continuing a CL Command
If the continuation is in the middle of
a value, no spaces precede the +
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)
9
![Page 10: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/10.jpg)
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
/* This is an example of a comment. */
10
![Page 11: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/11.jpg)
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
Program
Storage
Operating
System
User
PrintoutData
Data Data
Data
11
![Page 12: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/12.jpg)
User Supplied Program Data
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
CALL pgm1 (‘chardata’ numeric ‘chardata’….)
PGM PARM(&CUSTNAME &ORDAMT)
12
![Page 13: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/13.jpg)
User Supplied Program Data The parameters specified on the call
must match the parameters specified in
the PARM keyword
If they don’t match:
CALL pgm1 (‘Walmart’ 275)
PGM PARM(&CUSTNAME &ORDAMT)
CALL pgm1 (275)
Parameters passed on CALL do not match those required.
The program will not be run and you will
get the following message:
13
![Page 14: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/14.jpg)
Program Variables
Programs store input and output in
program variables
Just like a data base field, a program
variable has a:
Name
Length
Data type
Program variables exist for as long as
the program is running
14
![Page 15: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/15.jpg)
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
*************** Beginning of data **********************
0001.00 PGM PARM(&CUSTNAME &ORDAMT)
0002.00 DCL VAR(&CUSTNAME) TYPE(*CHAR) LEN(15)
0003.00 DCL VAR(&ORDAMT) TYPE(*DEC) LEN(9 2)15
![Page 16: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/16.jpg)
Retrieving Data from OS/400 RTVSYSVAL - retrieves and stores system
parameter values in program variables:
Date
Time
System Default Printer
RTVJOBA - retrieves and stores job
information in program variables:
Job name
User running job
Output queue
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&CURTIME)
RTVJOBA USER(&USERID) 16
![Page 17: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/17.jpg)
Sending Data to a User
SNDUSRMSG - sends a message to the
person running the program or a specified
users message queue
You can build complex messages
combining static text and program variables
by using string functions
SNDUSRMSG MSG('I''ll be back')
SNDUSRMSG MSG(&CUSTNAME) MSGTYPE(*INFO) +
TOUSR(INTRO99)
17
![Page 18: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/18.jpg)
String Functions
Concatenation - joins two strings together
*CAT
*TCAT - eliminates trailing spaces
*BCAT - one trailing space between strings
Results in:
SNDUSRMSG MSG('I''ll be back at ’ *CAT &CURTIME)
SNDUSRMSG MSG('I''ll be back at ’ *TCAT &CURTIME)
SNDUSRMSG MSG('I''ll be back at ’ *BCAT &CURTIME)
I'll be back at 14:09:08
I'll be back at14:09:08
I'll be back at 14:09:08
18
![Page 19: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/19.jpg)
String Functions
Substring - identifies a subset of a string
%SST(string start-location size)
When used with a CHGVAR command,
new strings can be created.
Results in:
CHGVAR VAR(&NOSECTIME) VALUE(%SST(&CURTIME 1 5)
SNDUSRMSG MSG('I''ll be back at ’ *BCAT &NOSECTIME)
I'll be back at 14:09
19
![Page 20: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/20.jpg)
CL Program0001.00 START: PGM PARM(&LIBNAME &FILENAME &MEMNAME &MEMTYPE)
0002.00
0003.00 /* Create info is supplied and the variables defined*/
0004.00
0005.00 DCL VAR(&FILENAME) TYPE(*CHAR) LEN(10)
0006.00 DCL VAR(&MEMNAME) TYPE(*CHAR) LEN(10)
0007.00 DCL VAR(&LIBNAME) TYPE(*CHAR) LEN(10)
0008.00 DCL VAR(&MEMTYPE) TYPE(*CHAR) LEN(3)
0009.00
0010.00 /* The member is created */
0011.00
0012.00 CRTMBR: STRSEU SRCFILE(&LIBNAME/&FILENAME) +
0013.00 SRCMBR(&MEMNAME) +
0014.00 TYPE(&MEMTYPE)
0015.00
0016.00 /* Message to confirm member creation is sent */
0017.00
0018.00 SNDUSRMSG MSG('IT''S DONE, PAPPY!')
0019.00
0020.00 /* The program is ended */
0021.00
0022.00 END: ENDPGM 20
![Page 21: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/21.jpg)
Compilation Reports
Library
PF-SRC
CRTMBR
CLPCompile
CRTMBR
*PGM
CLP
Compilation
Report
MSGQ
21
![Page 22: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/22.jpg)
Compilation Reports
General Information
Source Code Listing
Cross reference table
Error message summary
22
![Page 23: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/23.jpg)
General information area Display Spooled File
File . . . . . : COMPILEEX Page/Line 1/1
Control . . . . . ________ Columns 1 - 78
Find . . . . . . ______________________________
*...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+...
5763SS1 V3R2M0 960517 Control Language GRA
Program . . . . . . . . . . . . . . . . . . . : COMPILEEX
Library . . . . . . . . . . . . . . . . . . : GRADES
Source file . . . . . . . . . . . . . . . . . : GRADES
Library . . . . . . . . . . . . . . . . . . : GRADES
Source member name . . . . . . . . . . . . . : COMPILEEX 10/30/97 17:06:
Source printing options . . . . . . . . . . . : *SOURCE *XREF *GEN *NOSE
Program generation options . . . . . . . . . : *NOLIST *NOXREF *NOPATCH
User profile . . . . . . . . . . . . . . . . : *USER
Program logging . . . . . . . . . . . . . . . : *JOB
Allow RTVCLSRC command . . . . . . . . . . . : *YES
Replace program . . . . . . . . . . . . . . . : *YES
Target release . . . . . . . . . . . . . . . : V3R2M0
Authority . . . . . . . . . . . . . . . . . . : *LIBCRTAUT
Sort sequence . . . . . . . . . . . . . . . . : *HEX
Language identifier . . . . . . . . . . . . . : *JOBRUN
23
![Page 24: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/24.jpg)
Searching the report
Control field commands provide quick
movement through the spool file
P+5 Move forward 5 pages
P-5 Move backwards 5 pages
P5 Move to page 5
+5 Move forward 5 lines
-5 Move backwards 5 lines
W+5 Move to the right 5 columns
W-5 Move to the left 5 columns
W5 Move to the fifth column
B or *BOT Move to the end of the spool file
T or *TOP Move to the beginning of the spool file
24
![Page 25: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/25.jpg)
Find Area
Allows you to search for a character
string within the compilation report
Case sensitive
To find a string:
Enter the text in the find area
Press F16
To find other occurrences of the
string continue to press F16
25
![Page 26: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/26.jpg)
Source Code Listing Displays source code
Error messages placed after incorrect
statements
Control Language Source
SEQNBR *...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+...
100- DCL VAR(&JOB) TYPE(*CHAR) LEN(7)
* CPD0740 10 PGM command missing.
200- DCL VAR(&USR) TYPE(*CHAR) LEN(10)
300- RTVJOBA JOB(&JOB)
* CPD0784 30 Variable &JOB for parameter JOB must be *CHAR, minimum length 10
400- RTVJOBA USER(&USER)
* CPD0727 40 Variable '&USER ' is referred to but not declared.
500- SNDUSRMSG 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.
800- GOTO CMDLBL(END)
* CPD0725 10 End of source file reached without ENDPGM command.
* * * * * E N D O F S O U R C E * * * *
26
![Page 27: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/27.jpg)
Error messages
Comprised of three parts:
Error code
Error message
Severity level
CPD0740 10 PGM command missing.
27
![Page 28: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/28.jpg)
Cross Reference table For every variable and label, the statement
numbers that reference each are displayed
Errors messages listed here also
5763SS1 V3R2M0 960517 Control Language GRA
Cross Reference
Declared Variables
Name Defined Type Length References
&JOB 100 *CHAR 7 300 500
&USR 200 *CHAR 10
* CPD0726 10 Variable '&USR ' declared but not referred to.
Defined Labels
Label Defined References
END ****** 800
* CPD0715 30 Label 'END ' does not exist.
* * * * * E N D O F C R O S S R E F E R E N C E
28
![Page 29: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/29.jpg)
Error Message Summary 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
Severity 20 errors (and higher) stop the compile29
![Page 30: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/30.jpg)
Run Time Errors
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
![Page 31: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/31.jpg)
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
![Page 32: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/32.jpg)
Run Time Errors
Some run time errors are not the
result of incorrect programming e.g.
Incorrect user input
Lack of authority
No data
The program should not end when
these types of errors occur
The program should check for these
conditions and provide user friendly
messages
32
![Page 33: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/33.jpg)
Monitoring for Messages
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 DCL’s:
EXEC performed regardless of the program
statement causing the error
If MONMSG follows a command:
EXEC performed only if the preceding
command caused the specified error
33
![Page 34: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/34.jpg)
Monitoring for Messages
CPF9810 - library does not exist
CPF9812 - file does not exist
This MONMSG results in an error
handling routine being executed
No EXEC keyword means the error
will be ignored
MONMSG MSGID(CPF9810) EXEC(CRTLIB &LIBNAME)
MONMSG MSGID(CPF9812) EXEC(GOTO CMDLBL(NOFILE))
MONMSG MSGID(CPF9812)
34
![Page 35: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/35.jpg)
Error Handling Routines
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
![Page 36: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/36.jpg)
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
![Page 37: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/37.jpg)
Message Replies MSGRPY - Identifies the program
variable to hold the reply
VALUES - Defines the valid values that
can be entered as a reply
IF condition - if true, the statement(s)
following THEN will be performed
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
![Page 38: CL Programming.pdf](https://reader031.vdocuments.us/reader031/viewer/2022012310/55cf9b67550346d033a5f13a/html5/thumbnails/38.jpg)
Points to Remember
CL commands can be “grouped” into
programs
Compilation reports are used to
diagnose compile errors
The JOBLOG helps diagnose run time
errors
Users can create their own CL
commands
38