-
Functionalities of a CL program (6)
- 1) To call program interactively or in batch mode.
- 2) To control the sequencing of those programs.
- 3) Process files and other objects.
- 4) To monitor for all kind of messages.
- 5) To Make communication between different jobs.
- 6) Change the attribute of an object and then process it.
-
Limitations of CL (comparison to RPG) (5)
- 1) Cannot ADD or UPDATE records in database files.
- 2) It has limited printing capability.
- 3) It cannot use Program described files.
- 4) It doesn’t support subfile
- - a single output message subfile is a special type of subfile that is supported well in CL.
- 5) We cannot declare more than one object (file) in a CL program
- - In CLLE, we can use more than 1 file to read with OPENID concept
-
OPNID in DCLF
- .
- DCLF FILE(STATETBL) OPNID(STATE1) - table
- DCLF FILE(DSPTAX) OPNID(STATE2) - DSPF
- .
- RCVF OPNID(STATE1)
- .
- - STATETBL table has field STNAME
- - STNAME can be referenced as &STATE1_STNAME w/i CLP
- .
- CHGVAR VAR(&STATE2_STNAME) VALUE(&STATE1_STNAME)
- .
- SNDF OPNID(STATE2)
- RCVF OPNID(STATE2)
-
To joins two strings "as is"
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 *CAT &LNAME1)
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 || &LNAME1)
-
*CAT
- - or ||
- - Joins two strings "as is"
- .
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 *CAT &LNAME1)
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 || &LNAME1)
-
To joins two strings with a single blank space between
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 *BCAT &LNAME1)
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 |> &LNAME1)
-
*BCAT
- - or |>
- - Joins two strings with a single blank space between
- .
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 *BCAT &LNAME1)
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 |> &LNAME1)
-
To joins two strings trimming first string
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 *TCAT &LNAME1)
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 |< &LNAME1)
-
*TCAT
- - or |<
- - Joins two strings trimming first string
- .
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 *TCAT &LNAME1)
- CHGVAR VAR(&FLNAME) VALUE(&FNAME1 |< &LNAME1)
-
To display all the messages in message file QCPFMSG with its basic message description.
- DSPMSGD RANGE(*FIRST *LAST)
- DETAIL(*BASIC)
-
CL command to determine which logical fles are depend on a Specifc physical flee?
- DSPDBR
- - Display Data Base Relations
- - provides relational information about database files
- - It identifies the
- - physical and logical files dependent on a specific file
- - files that use a specific record format
- - file members that are dependent on a specific file member
- .
- DSPDBR FILE(CUSTOMERST)
-
DSPDBR
- - Display Data Base Relations
- - provides relational information about database files
- - It identifies the
- - physical and logical files dependent on a specific file
- - files that use a specific record format
- - file members that are dependent on a specific file member
- .
- DSPDBR FILE(CUSTOMERST)
-
CL command to redirect the fle named in RPG program?
OVRDBF
-
CL command to change the contents of a variable
- CHGVAR
- .
- CHGVAR VAR(&S_ACC) VALUE(&ID1_ACC)
-
What function does the CHGVAR command perform in a CLP pgm?
- Allows you to change the contents of a variable
- .
- CHGVAR VAR(&S_ACC) VALUE(&ID1_ACC)
-
What is Open Data Path in a CLP pgm?
- - temporary object which is used to create dynamic access path for a file.
- - describes the order in which records are to be read
- - Access paths can be kept on the system...
- - permanently (physical or logical file)
- - temporarily (OPNQRYF)
- - contains the information
- - file name
- - format name
- - current record pointer
- - record selection information
- - ect.
- - has only one cursor
- - each program that shares the same ODP has only one image of the cursor
-
OPNQRYF
- - build a temp access path over a file with selections
- - creates only a temporary file for processing the data
- - Query for iSeries® can be used to perform some of the functions that the OPNQRYF command performs.
- .
- OPNQRYF FILE(lib-name/file-name +
- Member-name +
- Record-format-name) +
- OPTION(open-option) +
- FORMAT(lib-name/file-name +
- Record-format name) +
- QRYSLT(query selection) +
- KEYFLD(field name)
- .
- - FILE: File to be processed.
- - OPTION: In which mode the file is to be processed.
- - (*INP *OUT *UPD *DLT *ALL)
- - FORMAT: File format
- - QRYSLT:
- - *ALL
- - includes all records
- .
- FILE(LIB / PF) QRYSLT(*ALL)
- .
- - *BCAT
- - We can use *BCAT to insert the variable’s value in an expression with blanks in between.
- .
- FILE (LIB / PF) QRYSLT (‘EMPNO *EQ ‘ *BCAT &A)
- .
- - %WLDCRD
- - It will fetch all the records where party name starts from S.
- .
- QRYSLT (‘PARTY_NAME *EQ %WLDCRD (“S* “)’)
- .
- - *CT
- - It will fetch all the records where party name contains the particular character ‘S’.
- .
- QRYSLT (‘PARTY_NAME *CT “S” ‘)
- .
- - %RANGE
- - It will fetch all the records where party number falls in the range 101 and 201
- .
- QRYSLT (‘PARTY_NUM *EQ %RANGE (101 201)’)
- .
- - KEYFLD:
- - name of one or more key fields that are used to arrange the query records
- - part of the key is ordered by...
- - *ASCEND
- - *DESCEND
- .
- KEYFLD((ORG-CODE *DESCEND) (ACCOUNT))
-
Steps to create and use an OPNQRYF
- PGM PARM()
- DCLF FILE(ANATOLIYK/STATETBL)
- DCL VAR(&ABBREV) TYPE(*CHAR) LEN(2)
- .
- 1) OVRDBF
- .
- OVRDBF FILE(STATETBL) +
- TOFILE(ANATOLIYK/STATETBL) +
- SHARE(*YES)
- .
- 2) OPNQRYF
- .
- OPNQRYF FILE(STATETBL) +
- OPNSCOPE(*ACTGRPDFN) +
- OPTION(*ALL) +
- QRYSLT('STSLTAX *EQ %RANGE(0.040 0.060)') +
- OPNID(ID1)
- .
- 3) Call program that is using file STATETBL
- .
- CALL PGM(WNDSTATPGM) PARM(&ABBREV)
- .
- 4) DLTOVR
- .
- DLTOVR FILE(STATETBL)
- .
- 5) CLOF
- .
- CLOF OPNID(ID1)
-
CPYFRMQRYF
- CPYFRMQRYF
- - to copy overridden file’s selected records from it from the overridden file to a temporary file.
- .
- OVRDBF FILE(STATETBL) +
- TOFILE(ANATOLIYK/STATETBL) +
- SHARE(*YES)
- .
- OPNQRYF FILE(STATETBL) +
- OPNSCOPE(*ACTGRPDFN) +
- OPTION(*ALL) +
- QRYSLT('STSLTAX *EQ %RANGE(0.040 0.060)') +
- OPNID(ID1)
- .
- CPYFRMQRYF FROMOPNID(ID1)
- TOFILE(QTEMP/RESULT) +
- MBROPT(*REPLACE) +
- CRTFILE(*YES)
-
Logical file VS OPNQRYF
- Logical file
- - access path is permanent
- - the same sort order and sequence
- .
- OPNQRYF
- - creates a temporary access path
- - multiple sort order and random filtering
-
Data Types in a CLP?
- *CHAR -character data
- *LGL - logical data (fags, switches of indicators)
- *DEC - numeric data in packed decimal format
- *INT - numeric data in signed integer format
- *UINT - numeric data in unsigned integer format
- *PTR - pointer variables containing a memory address
-
How to declare file in a CLP?
- All the fields and indicators in all the record formats
- .
- DCLF FILE(ABLE) RCDFMT(*ALL)
- .
- To use multiple record formats
- .
- DCLF FILE(BAKER) RCDFMT(REC2 REC6)
- .
- Using Open File Identifier
- .
- DCLF FILE(MYLIB/CHARLES) OPNID(CTLFILE1)
- .
- - variable will be ceclared
- &CTLFILE1_CUSTNUMBER
-
DOWHILE in a CLP?
- DCL VAR(&LGL) TYPE(*LGL) VALUE('0') - will not be processed
- DCL VAR(&LGL) TYPE(*LGL) VALUE('1') - will be processed
- .
- DOWHILE COND(&LGL)
- (group of CL commands)
- ENDDO
-
DOUNTIL in a CLP?
- DCL VAR(&INT) TYPE(*INT) LEN(2) VALUE(10)
- .
- will be processed until the value of &INT is greater than 100
- .
- DOUNTIL COND(&INT *GT 100)
- (group of CL commands)
- CHGVAR VAR(&INT) VALUE(&INT + &VAL)
- ENDDO. will be processed until either a LEAVE or GOTO command is encountered.
- .
- DOUNTIL COND('0')
- (group of CL commands)
- ENDDO
-
DOFOR in a CLP?
- DCL VAR(&INT) TYPE(*INT) LEN(2)
- DCL VAR(&START) TYPE(*INT) LEN(2)
- DCL VAR(&END) TYPE(*INT) LEN(2)
- .
- CHGVAR VAR(&START) VALUE(100)
- CHGVAR VAR(&END) VALUE(0)
- .
- DOFOR VAR(&INT) FROM(&START) TO(&END) BY(-5)
- (group of CL commands)
- ENDDO
-
Command are allowed to processes CL procedure?
- DO,
- DOWHILE,
- DOUNTIL, and
- DOFOR commands are allowed.
-
RCVF command in CLP?
to receive data from a display device or database file.
-
Receive Data from Database File which does not have an open file identifier specified
- DCLF FILE(MENU1)
- RCVF OPNID(*NONE)
-
Receive Data from Database File which has an open file identifier specified
- DCLF FILE(MENU1) OPNID(FILE1)
- RCVF OPNID(FILE1)
-
Process DSPF within CLP using GOTO command
- .
- DCLF FILE(DSPTAX)
- .
- /* Preload DSPF fields */
- CHGVAR VAR(&PGMNAME) VALUE('CLPGM_2')
- ...
- /* Display DSPF */
- LOOP: SNDF RCDFMT(PGMTAX_R1)
- RCVF RCDFMT(PGMTAX_R1)
- .
- IF COND(&IN03 *EQ '1') THEN(DO)
- GOTO CMDLBL(END)
- ENDDO
- .
- GOTO CMDLBL(LOOP)
- .
- END: ENDPGM
-
How would you read a file in a CLP?
- PGM
- DCL VAR(&LOOP) TYPE(*LGL) VALUE('1')
- DCLF FILE(FILE1) OPNID(ID1)
- .
- DOWHILE COND(&LOOP)
- RCVF OPNID(ID1)
- MONMSG MSGID(CPF0864) EXEC(LEAVE) - last record
- ENDDO
- ENDPGM
-
How do you check for errors to prevent a user from getting a halt?
Using MONMSG
-
MONMSG in CLP?
- 1) Monitors for the escape/status/notifcation messages
- 2) Exist in a program at run time and allows us to take the corrective action for those messages.
- .
- MONMSG MSGID(CPF0001) EXEC(GOTO ERROR)
-
Types of monitor message
- Escape Message
- - send to tell your program of an error condition that forced the sender to end the program
- - By monitoring for escape message, you can
- - take corrective actions or
- - end your program.
- .
- Status or Notify Message
- - are send to tell your program of an abnormal condition that is not serious
- enough for sender to end
- - By monitoring for status or notify message
- - your program can detect this
- condition and
- - not allow the function to continue.
-
Levels of MONMSG command
- 1) Program level
- - specified immediately following the last declared command in the CL program
- - will catch all the error escape messages that...
- - exist in the program and doesn't have satisfying command level MONMSG or
- - doesn't have any command level MONMSG
- .
- 2) Specifc command level
- - specified immediately following a CL command.
- - IF
- a) there is any error at a particular CL statement
- b) that error satisfes the condition specifed in MONMSG
- - then the error is caught with this MONMSG.
- .
- MONMSG MSGID (CPF9821 CPF9822 …… CPF9830)
- MONMSG MSGID (CPF0000 MCH0000) EXEC (GOTO ERROR)
-
To display all error messages
WRKMSGD MSGID(*FIRST) MSGF(QCPFMSG) OUTPUT(*PRINT)
-
To call Bound Procedure
CALLPRC PRC(procedure-name) PARM(parameter-values)
-
CALLPRC
- - Call Bound Procedure
- .
- CALLPRC PRC(procedure-name) PARM(parameter-values)
-
Are you required to pass all parameters to a CL PGM that is expecting parms?
- YES
- .
- Calling program
- CALL PROGB PARM(&A &B &C ABC) - calling CLP
- PGM PARM(&C &B &A &D) - called CLP
- .
- Calling procedure
- MAIN: PGM PARM(&TEXT)
- DCL VAR(&TEXT) TYPE(*CHAR) LEN(10)
- CALLPRC PRC(PROC1) PARM('0')
- CALLPRC PRC(PROC1) PARM('1' &TEXT)
- CALLPRC PRC(PROC1) PARM('1' 'Goodbye')
- ENDPGM
- .
- PROC1: PGM PARM(&P1 &P2)
-
How would you create a variable, which is a partial subset of a parameter variable
within a CLP programe?
- DCL &NAME *CHAR VALUE(INVOICE)
- DCL &SNAME *CHAR
- .
- CHGVAR VAR(&SNAME) VALUE(%SST(&NAME 1 2)) /* &SNAME = IN */
-
CL command to converts the format of a date in a CL program or procedure
- CVTDAT DATE(date-to-be-converted) +
- TOVAR(CL-variable) +
- FROMFMT(old-format) +
- TOFMT(new-format) +
- TOSEP(new-separators)
-
CVTDAT
- - converts the format of a date in a CL program or procedure
- .
- CVTDAT DATE(date-to-be-converted) +
- TOVAR(CL-variable) +
- FROMFMT(old-format) +
- TOFMT(new-format) +
- TOSEP(new-separators)
- .
- CVTDAT DATE(&DATE) +
- TOVAR(&CVTDAT) +
- FROMFMT(*MDY) +
- TOFMT(*DMY) +
- TOSEP(*SYSVAL)
-
CL command to display the network attributes of the system
DSPNETA
-
DSPNETA
- displays the network attributes of the system
-
CL command to change the network attributes of the system
CHGNETA
-
CHGNETA
- changes the network attributes of the system
-
CL command to retrieve the network attributes of the system.
RTVNETA
-
RTVNETA
- retrieve the network attributes of the system.
-
RTVSYSVAL
- - brings system values into program or procedure
- .
- RTVSYSVAL SYSVAL(system-value-name) RTNVAR(CL-variable-name)
- .
- DCL VAR(&TIME) TYPE(*CHAR) LEN(6)
- RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME)
-
What CL command will return the time currently on the system?
- RTVSYSVAL
- .
- DCL VAR(&CURDATE) TYPE(*CHAR) LEN(6)
- DCL VAR(&CURDTIME) TYPE(*CHAR) LEN(20)
- DCL VAR(&CURTIME) TYPE(*CHAR) LEN(6)
- .
- RTVSYSVAL SYSVAL(QDATE) RTNVAR(&CURDATE)
- RTVSYSVAL SYSVAL(QDATETIME) RTNVAR(&CURDTIME)
- RTVSYSVAL SYSVAL(QTIME) RTNVAR(&CURTIME)
- .
- &CURDATE = '061918'
- &CURDATETIME = '20180619090253046081'
- &CURTIME = '090254'
-
How to debug CLPe?
- 1) Recompile CLP with
- - Debugging view . . . . *ALL or *SOURCE
- .
- 2) Start Debugger
- - For CLP - Control Language
- - STRISDB - Start Interactive Source Debugger
- - For CLLE - Control Language ILE
- - STRDBG - Start Debugger
- - With
- - Update production files . . . . > *YES
- - OPM source level debug . . . . . > *YES
- - Set Break Pointer
- - F6=Break
- .
- 3) Call CLP
- - F10=Step
- - F11=Display variable
- - F12=Run
- .
- 4) ENDDBG
-
CPYFRMQRYF
- - to copy overridden file’s selected records from it from the overridden file to a temporary file.
- .
- OVRDBF FILE(ACCOUNT)
- TOFILE(IROBO1/ACCOUNT)
- SHARE(*YES)
- .
- OPNQRYF FILE((ACCOUNT)) OPTION(*ALL) QRYSLT('ORG *EQ 190') OPNID(ID1)
-
OUTFILE
- - to store the output information in a file
- .
- DSPFD FILE(IROBO1/ACCOUNT) +
- TYPE(*ACCPTH) +
- OUTPUT(*OUTFILE) +
- OUTFILE(QTEMP/TEMP001)
- .
- TYPE(*ACCPTH)
- - Access paths for physical and logical files are provided
-
RTVDTAARA
- - to retrieve the data area and store the value in a CL variable
- .
- RTVDTAARA DTAARA(SFTP9140 (1 100)) RTNVAR(&RMTSYS)
- .
- - The dataarea from length 1 to 100 will be stored in the variable &RMTSYS.
-
CL command to retrieve User Profile
- RTVUSRPRF USRPRF(*CURRENT) +
- RTNUSRPRF(&USR) +
- MGSQ(&USRMSGQ) +
- MSGQLIB(&USRMSGQLIB)
- .
- - &USR
- - contains the user profile name of the user who called the program
- - &USRMSGQ
- - contains the name of the message queue specified in the user profile.
- - &USRMSGQLIB
- - contains the name of the library containing the message queue associated with the user profile
-
RTVUSRPRF
- - Retrieve User Profile
- .
- RTVUSRPRF USRPRF(*CURRENT) +
- RTNUSRPRF(&USR) +
- MGSQ(&USRMSGQ) +
- MSGQLIB(&USRMSGQLIB)
- .
- - &USR
- - contains the user profile name of the user who called the program
- - &USRMSGQ
- - contains the name of the message queue specified in the user profile.
- - &USRMSGQLIB
- - contains the name of the library containing the message queue associated with the user profile
-
CL command to retrieve Job Attributes
- DCL &CLKNAM TYPE(*CHAR) LEN(10)
- RTVJOBA USER(&CLKNAM)
-
RTVJOBA
- Retrieve Job Attributes
- - USER: The user of the job.
- - NBR: The job number of the job.
- - CURUSER: The current user of the job
- ...
- DCL &CLKNAM TYPE(*CHAR) LEN(10)
- RTVJOBA USER(&CLKNAM)
-
RTVMBRD
- retrieves the description of a specific member
-
RTVOBJD
- Retrieve Object Description
-
CHGOBJD
- - Change Object Description
- .
- CHGOBJD OBJ(STATETBL)
- OBJTYPE(*ALL)
- TEXT(*SAME / new)
-
How to debug BATCH_PGM program, which is submitted to batch
- 1) Submit program to the batch with HOLD *YES
- - SBMJOB
- to submit another job to a job queue to call program - .
- SBMJOB CMD(CALL PGM(BATCH_PGM))
- JOB(TEST1)
- JOBQ(QBATCH)
- HOLD(*YES)
- .
- 2) Find the job name and number of the submitted job
- .
- WRKUSRJOB STATUS(*JOBQ)
- .
- - "Work with User Jobs" screen displayed
- - 5 to display the job's details
- .
- Work with User Jobs
- Opt Job User Type -----Status-----
- 5 TEST1 ANATOLIYK BATCH JOBQ HELD
- .
- Work with Job
- Job: TEST1 User: ANATOLIYK Number: 001959
- .
- 3) Run Start Service Job command - start the remote service operation for a specified job so that other service commands can be entered to service the specified job
- .
- STRSRVJOB JOB(001959/ANATOLIYK/TEST1)
- .
- 4) Start Debug
- .
- STRDBG PGM(*LIBL/BATCH_PGM)
- UPDPROD(*YES)
- OPMSRC(*YES)
- .
- ==> F12
- .
- 5) Relese Job
- .
- WRKJOB JOB(001959/ANATOLIYK/TEST1)
- 43. Release job
- .
- - released job becomes active
- .
- 6) Press F10
- - to enter debug commands
- .
- 7) On the command line give command 'DSPMODSRC' ==> ENTER
- - to display the source and to put the break point
- .
- 8) F3 or F12
- - to return to the "Command Entry" screen
- F3 or F12
- - to return to the "Start Service Job" screen
- .
- 9) ENTER
- - to start the job
- - debugger will stop in the breakpoint line
- .
- 10) Debug the program as an interactive program
- .
- 11) ENDDBG
- .
- 12) ENDSRVJOB
-
How to check for any characters that are not digits (0-9)
- DCL VAR(&SN) TYPE(*CHAR) LEN(10)
- IF COND(%CHECK(’0123456789’ &SN) *NE 0) +
- THEN(SNDPGMMSG (’INVALID CHARACTER FOUND!’))
-
%CHECK / %CHECKR
- - CL built-in functions
- - returns the first/last position of a base string that contains a character that does not appear in the comparator string.
- .
- DCL VAR(&SN) TYPE(*CHAR) LEN(10)
- IF COND(%CHECK(’0123456789’ &SN) *NE 0) +
- THEN(SNDPGMMSG (’INVALID CHARACTER FOUND!’))
- .
- - Check for any characters that are not digits (0-9)
-
%SCAN
- - returns the first position of a search argument in the source string, or 0 if it was not found
- .
- %SCAN(search-argument source-string [starting-position])
- .
- IF COND(%SCAN(’John’ &FNAME) *EQ 0) +
- THEN(SNDPGMMSG (’NOT FOUND!’))
-
How to search characters from the local data area in CLP?
CHGVAR VAR(&POS) VALUE(%SCAN(’Escape’ *LDA))
-
%SUBSTRING
- - %SST
- - produces a character string that is a subset of an existing character string
- .
- %SUBSTRING(character-variable-name starting-position length)
- .
- DCL &NAME *CHAR VALUE(INVOICE)
- IF (%SST(&NAME 1 2) *EQ ’IN’) +
- THEN(CALL INV210 &NAME)
-
%TRIM / %TRIML / %TRIMR
- - with one parameter produces a character string with any (leading and trailing / leading / trailing) blanks removed
- - with two parameters produces a character string with any (leading and trailing / leading / trailing) characters that are in the characters to trim parameter removed
- .
- DCL VAR(&NUM) TYPE(*CHAR) LEN(10) VALUE(’* *1.23* *’)
- DCL VAR(&TRIMMED) TYPE(*CHAR) LEN(10)
- DCL VAR(&DEC) TYPE(*DEC) LEN(3 2)
- .
- CHGVAR &TRIMMED %TRIM(&NUM ’* ’)
- CHGVAR VAR(&DEC) VALUE(&TRIMMED)
-
QCMDEXC
- - API
- -Application Program Interface
- - API to execute command from HLL
- - We can change the command at run time.
- - The commands that are only used in CL program are not permissible here
- .
- CLP
- CALL PGM(QCMDEXC) PARM(command command-length)
- .
- RPGLE
- Dcl-s CmdDsc Char(256);
- Dcl-s CmdLen Packed(15:5);
- .
- Dcl-pr QCMDEXC Extpgm;
- *N Char(256);
- *N Packed(15:5);
- End-pr;
- .
- CmdDsc = 'CRTDTAARA DTAARA(QCMDEXCDTA) TYPE(*CHAR)';
- CmdLen = %Len(%Trim(CmdDsc));
- .
- Monitor;
- QCMDEXC(CmdDsc : CmdLen);
- .
- On-error *ALL;
- Dsply 'Data Area already exists';
- Endmon;
|
|