Escolar Documentos
Profissional Documentos
Cultura Documentos
CL Programming
1
Copyright 2009 by Janson Industries
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
Copyright 2009 by Janson Industries
Creating CL Programs
Library
CRTMBR
Programmer PF-SRC
*PGM
CLP
CL
Compile
Commands
LPEX CRTMBR
SEU CLP
3
Copyright 2009 by Janson Industries
Programs
Programs are comprised of many
programming language instructions
Instructions are written on lines or
statements.
Each statement/line in a member is
assigned a statement/line number.
CL commands (instructions) can
span many lines
4
Copyright 2009 by Janson Industries
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.
5
Copyright 2009 by Janson Industries
CL Command Syntax
The format for a CL Command is:
COMMAND PARAMETER PARAMETER ….
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
6
Copyright 2009 by Janson Industries
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 PARAMETER
7
Copyright 2009 by Janson Industries
Continuing a CL Command
The + is not preceded by space(s) if the
continuation is in the middle of the:
Command word
Parameter keyword
COMM+
AND PARAMETER PARMETER
COMMAND PARAMETER PARA+
METER
COMM +
AND PARAMETER PARMETER
COMMAND PARAMETER PARA +
METER
8
Copyright 2009 by Janson Industries
Continuing a CL Command
If a parameter value(s) allows
spaces, then the + is preceded by
space(s)
GRTOBJAUT OBJ(YOURLIBXX/CLSRC) OBJTYPE(*FILE) +
Operating
Data Program Data Printout
System
Data
Data User
Storage
12
Copyright 2009 by Janson Industries
User Supplied Program Data
You can supply data when calling the
program as follows:
CALL pgm1 (‘chardata’ numeric ‘chardata’….)
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
18
Copyright 2009 by Janson Industries
String Functions
Concatenation - joins two strings together
*CAT
*TCAT - eliminates trailing spaces
*BCAT - one trailing space between strings
20
Copyright 2009 by Janson Industries
CL Program
000100 START: PGM PARM(&LIBNAME &FILENAME &MEMNAME &MEMTYPE)
000200
000300 /* Create info is supplied and the variables defined*/
000400
000500 DCL VAR(&FILENAME) TYPE(*CHAR) LEN(10)
CRTMBR
PF-SRC *PGM
CLP sg
MSGQ
n M
e t io
p l
m
Co
CRTMBR Compilation
CLP Compile Report
22
Copyright 2009 by Janson Industries
RDi Unsuccessful Compilations
Library
CRTMBR EVFEVENT
PF-SRC *PGM *FILE
CLP PF-DTA
CRTMBR CRTMBR
CLP Compile Error Msgs ___
23
Copyright 2009 by Janson Industries
RDi Unsuccessful Compilations
The EVFEVENT member will be
displayed in Error List
Error msgs displayed in Commands log
24
Copyright 2009 by Janson Industries
Verifying in RDi
Does everything compiling does
except create the object
Why bother?
To compile you must be able to
communicate to the IPS
Verifying doesn't require
communicating to the IPS
Verifying faster than compiling
No verifier for CL programs!!
25
Copyright 2009 by Janson Industries
26
Copyright 2009 by Janson Industries
Compilation Reports
In a spool file with the same
name as member
Can be viewed
Using Navigator's Viewer
WRKSPLF
27
Copyright 2009 by Janson Industries
Display spool files and double click the spool file
28
Copyright 2009 by Janson Industries
29
Copyright 2009 by Janson Industries
WRKSPLF
Work with All Spooled Files
Bottom
Parameters for options 1, 2, 3 or command
===>
F3=Exit F10=View 4 F11=View 2 F12=Cancel F22=Printers F24=More keys
30
Copyright 2009 by Janson Industries
Compilation Reports
General Information
Source Code Listing
Cross reference table
Error message summary
31
Copyright 2009 by Janson Industries
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 V6R1M0 100517 Control Language GRA
Program . . . . . . . . . . . . . . . . . . . : COMPILEEX
Library . . . . . . . . . . . . . . . . . . : GRADES
Source file . . . . . . . . . . . . . . . . . : GRADES
Library . . . . . . . . . . . . . . . . . . : GRADES
Source member name . . . . . . . . . . . . . : COMPILEEX 10/30/09 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 . . . . . . . . . . . . . . . : V6R2M0
Authority . . . . . . . . . . . . . . . . . . : *LIBCRTAUT
Sort sequence . . . . . . . . . . . . . . . . : *HEX
Language identifier . . . . . . . . . . . . . : *JOBRUN
32
Copyright 2009 by Janson Industries
Searching the report
Control field commands provide quick
movement through the spool file
33
Copyright 2009 by Janson Industries
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
34
Copyright 2009 by Janson Industries
Source Code Listing
Displays source code
Error messages placed after incorrect statements
36
Copyright 2009 by Janson Industries
Cross Reference table
For every variable and label, the statement
numbers that reference each are displayed
Errors messages listed here also
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
40
Copyright 2009 by Janson Industries
5250 Run Time Errors
The system generated message will be
displayed at the bottom of the screen
Programming Development Manager (PDM)
_______________________________________________________________________________
F3=Exit F4=Prompt F9=Retrieve F10=Command entry
F12=Cancel F18=Change defaults
Parameters passed on CALL do not match those required. +41
Copyright 2009 by Janson Industries
5250 Run Time Errors
Click on message and press Page Down to
display more of the message text
Programming Development Manager (PDM)
Selection or command
===> call library99/testpgm parm("library98")___________________________________
_______________________________________________________________________________
F3=Exit F4=Prompt F9=Retrieve F10=Command entry
F12=Cancel F18=Change defaults
Error found on CALL command. 42
Copyright 2009 by Janson Industries
5250 Run Time Errors
For more info about the problem:
Move the cursor to the message
Press F1
Additional Message Information will
be displayed for the message
Additional Message Information will
display
The original message
Reasons for the error
Step to correct the error
43
Copyright 2009 by Janson Industries
5250 Run Time Errors
Additional Message Information
Message ID . . . . . . : CPD0172
Date sent . . . . . . : 05/15/09 Time sent . . . . . . : 10:41:52
Cause . . . . . : The parameters passed on the CALL command do not match the
parameters required by program TESTPGM in library LIBRARY99. Correct program
not found or correct parameters not passed. The number of parameters or the
type of parameters passed on the CALL command must match those expected by
the program called.
Recovery . . . : If correct program not found, change or specify the
library name on the command or in a library list. Change the CALL command
and then try the command again.
Bottom
Press Enter to continue.
Display the JOBLOG by
Pressing F10 at the Additional Message
Information screen
Or issue the DSPJOBLOG command then
F10 and Page Up
45
Copyright 2009 by Janson Industries
JOBLOG
Display All Messages
System:
Job . . : QPADEV0004 User . . : USFL1AD001 Number . . . : 098011
Bottom
Press Enter to continue.
46
Copyright 2009 by Janson Industries
RDi Run Time Errors
The Commands log will display:
The original command
All the JOBLOG messages
Additional message info for the messages
47
Copyright 2009 by Janson Industries
Run Time Errors
As mentioned, some run time errors are
not the result of incorrect programming:
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
48
Copyright 2009 by Janson Industries
Monitoring for Messages
MONMSG - allows the program, NOT
the OS, to handle specified message(s)
The CL command 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
49
Copyright 2009 by Janson Industries
Monitoring for Messages
CPF9810 - library does not exist
MONMSG MSGID(CPF9810) EXEC(CRTLIB &LIBNAME)
CPF9812 - file does not exist
MONMSG MSGID(CPF9812) EXEC(CALLSUBR SUBR(NOFILE))
The above MONMSG invokes an error
handling subroutine called NOFILE
MONMSG MSGID(CPF9812)
No EXEC keyword means the error will
be ignored
50
Copyright 2009 by Janson Industries
Defining a Subroutine
SUBR/ENDSUBR commands surround
the subroutine code
SUBR keyword in SUBR commands
assigns a name
000400
: :
020500 SUBR SUBR(NOFILE)
020600 /* Subroutine executable statements */
000400
: :
020500 SUBR SUBR(NOFILE)
020600 /* Subroutine executable statements */
Perform complex functions to solve
the problem
Allow the user to select a course of
action from program defined options
53
Copyright 2009 by Janson Industries
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
54
Copyright 2009 by Janson Industries
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)
55
Copyright 2009 by Janson Industries
Creating CL Commands
Creating a CL command entails
identifying a program and prompt screen
to be called when the command is
issued.
So, a program and prompt screen must
be created before creating a command
CL command objects have type = *CMD
A prompt screen makes it easier for a
user to supply data to a program
56
Copyright 2009 by Janson Industries
Creating a CL Command
Programmer specifies:
Name of new command
Library Prompt screen member
Program to run for command
NEWCMD PGMTORUN
PF-SRC *PGM
*CMD
CLP
59
Copyright 2009 by Janson Industries
Prompt Screens
Special CL commands to define
prompt screens
CMD - only required command. The
keyword PROMPT defines the screen
title
PARM - used to define an entry
60
Copyright 2009 by Janson Industries
PARM command
PARM keywords used to define a field:
KWD - defines the fields keyword
TYPE - type of data the field will accept
LEN - length of field
CHOICE - text that will appear to the right
of the field regarding value choices
PROMPT - text that will appear to the left
of the field, describes the field
DFT - defines a default value for the field
VALUES/RSTD - identifies the only valid
values for the field 61
Copyright 2009 by Janson Industries
Prompt Screen Source Example
CMD PROMPT('CREATE MEMBER')
PARM KWD(LIB) TYPE(*CHAR) LEN(11) +
CHOICE('NAME') +
PROMPT('LIBRARY') DFT(YOURLIB)
PARM KWD(FILE) TYPE(*CHAR) LEN(11) +
CHOICE('NAME') +
PROMPT('SOURCE FILE')
PARM KWD(MBR) TYPE(*CHAR) LEN(11) +
CHOICE('NAME') +
PROMPT('SOURCE MEMBER')
PARM KWD(TYPE) TYPE(*CHAR) LEN(3) +
62
Copyright 2009 by Janson Industries CHOICE('CLP RPG PF CBL LF') +
Prompt Screen Example
CMD PROMPT('CREATE MEMBER')
PARM
SOURCEKWD(TYPE)
MEMBER . . . TYPE(*CHAR)
. . . . . . LEN(3) NAME
___________ +
CHOICE('CLP RPG
MEMBER TYPE . . . . . . . . . . ___
PF CBLCLPLF') +
RPG PF CBL LF
PROMPT('MEMBER TYPE')
63
Copyright 2009 by Janson Industries
Creating the command - CRTCMD
Create Command (CRTCMD)