CL 400
CL 400
CL 400
Programming
Introduction To CL
Programming
OS/400
Object on AS/400
Library List
Introduction To CL
Programming
Library list associated with a job consists of
four parts
1) System libraries
2) Product libraries
3) Current library
4) user libraries
Some system libraries are Qsys , Qusersys ,
Qhlpsys
Introduction To CL
Programming
Introduction To CL
Programming
CL Commands
Basic CL command
To see the Jobs library lis
DSPLIBL
DSPJOB
EDTLIBL
CRT
PF , PL , DSPF
DLT
F, PGM , CLPGM , CBLPGM
CHGXXX , DSPXXX , WRKXXX
Introduction To CL
Programming
CL Commands Syntax 1
Keyword Form
DSPLIB LIB(PAYLIB) OUTPUT(*PRINT)
Positional Form
DSPLIB PAYLIB *PRINT
COMBINATION FORM
DSPLIB PAYLIB OUTPUT(*PRINT)
Introduction To CL
Programming
CL Commands Syntax 2
Introduction To CL
Programming
Introduction To CL
Programming
Introduction To CL
Programming
Program Structure
PGM (&Parm1, & Parm2 ) ..Optional
DCLF (Max. of One)
DCL Variable
MONMSG (Program level monitor messages)
Logic with CL Commands
IF , ELSE
CL COMMAND
MONMSG (Command Level )
ENDPGM
Introduction To CL
Programming
Type
*DEC
*CHAR
*LGL
Len(Default)
Max.
Values
(15 5)
(32)
1
(15 9)
(9999)
Default (0)
Default(B)
Default(0)
Arithmetic Operation
*EQ , *GT
Introduction To CL
Programming
*LT
*EQ
*GT
*LE
*NL
*NG
*GE
*NE
*AND
*OR
*NOT
Less Than
Equal To
Greater Than
Introduction To CL
Programming
Do Statement
IF COND(&BALANCE *LT 1000)
THEN (DO)
CALL PGM1
CALL PGM1
ENDDO
GOTO command
Branching within program
Introduction To CL
Programming
PGMB
PGM
.
.
.
Call PGMC
...
.
.
.
TFRCTLPGMD
.
PGMD
.
.
.
RETURN
PGMC
PGM
.
.
.
ENDPGM
Introduction To CL
Programming
Introduction To CL
Programming
SNDRCVF RCDFMT(FILFMT)
SNDF RCDFMT(FILFMT)-- Control given to file for reading
RCVF RCDFMT(FILFMT)--- control given to program
Introduction To CL
Programming
Introduction To CL
Programming
Introduction To CL
Programming
Linkage Section(COBOL)
01
01
Customer
IN98
PIC
PIC
1.
Procedure Division
S99999 .
Introduction To CL
Programming
Character Variable
&B
Length
Length
7
7
7
Converted Result
0023.00
-003.90
-123.67
5.2
5.2
5.2
Converted Result
23.00
-03.90
-123.67
Introduction To CL
Programming
Program Menu
GO MENUA
Menu : MENUA
RUN *PGM: PGMA
Return code specify next step
Menu Name
Lib. Name
Return code
*PGM: PGMA
Set Return Code
End Of Program
Introduction To CL
Programming
Introduction To CL
Programming
Create Menu
CRTMNU
MENU(NAME)
PGM(*MENU)
CURLIB(*NOCHG)
PRDLIB(*NOCHG)
REPLACE(*YES)
TEXT(*BLANK)
TYPE(*PGM)
Introduction To CL
Programming
Program Testing
Debug Environment
Trace
Processing Sequence
Value of Variable
Breakpoints
Stop at breakpoints
Display or change variables
Command Entry
CRTCLPGM
Introduction To CL
Programming
Introduction To CL
Programming
Program Testing
Example :
Introduction To CL
Programming
Program Testing
Example :
Introduction To CL
Programming
Program Testing
Tracing Example :
STRDBG PGM(PGMA) DFTPGM(*PGM)
ADDTRC PGMVAR(&VAR1 &VAR2) STMT(LABEL1 LABEL2 1200)
CALL PGMA
DSPTRCDTA OUTPUT(*, *PRINT) (Display Trace points)
CLRTRCDTA
ENDDBG
In Breakponits user is given control but tracing it is not like that
Introduction To CL
Programming
Introduction To CL
Programming
%Substring
C L P
0 0 7
%switch
Introduction To CL
Programming
Data area
Introduction To CL
Programming
CHGDTAARA
RTVDTAARA
DSPDTAARA
ALCOBJ
Introduction To CL
Programming
SYSTEM Attributes
RTVSYSVAL
CHGSYSVAL
USR PROFILE
RTVJOBA
CHGJOB
RTVUSRPRF
CHGUSRPRF
CHGPRF
Introduction To CL
Programming
Introduction To CL
Programming
Introduction To CL
Programming
Introduction To CL
Programming
following types:
Informational (*INFO). A message that conveys
information about the condition of a function.
Introduction To CL
Programming
R FMT001CA06(06 Display Maesge)
.
R MENUSFL
TEXT(MESSGAE SFL DATA)
SFL
SFLMSGRCD(24)
MSGKEY SFLMSGKEY
MENUPGMQ
SFLPGMOQ
R MENUSFLC
TEXT(Menu SFL Control)
LOCK
SFLCTL(MENUSFL)
SFLPAG(1)
51 SFLDSP
51 SFLDSPCTL
51 SFLEND
51 SFLINZ
SFLPGMOQ
CL 400 ver 1.0
Introduction To CL
Programming
Introduction To CL
Programming
Introduction To CL
Programming
PGM
ALCOBJ OBJ ((LIB/FILE *FILE *EXCL)) WAIT(0)
CALL PGM(PGM1)
DLCOBJ OBJ( LIB/FILE *FILE *EXCL))
ENDPGM
Introduction To CL
Programming
PGM
/*Program level MONMSG */
MONMSG MSGID(CPF9801) EXEC(GOTO ERROR)
MONMSG MSGID(CPF7302)
/*CHECK FOR MASTRE FILE */
CHKOBJ PAYMAST *FILE
CHKOBJ GLMAST *FILE
/*NEW WORK FILE*/
AGAIN: CRTPF QTEMP/WORK
MONMSG MSGID(CPF7302) EXEC(DO)
Introduction To CL
Programming
MONMSG MSGID(CPF7302) EXEC(DO)
DLTF QTEMP/WORK
GOTO AGAIN
/*NEW TRANS FILE IF NONE EXISTS */
CRTPF LIB/PAYTRN
CALL PAYMONTHLY
RETURN
ERROR: SNDUSRMSG MSG(Master file missing (a) check *libl for
+ paylib (b) see supervisor.) MSGTYPE(*INFOR)
TOMSGQ(*EXT)
ENDPGM
Introduction To CL
Programming
Introduction To CL
Programming
Introduction To CL
Programming
CMD
PROMPT('Create New project')
PARM
KWD(PROJECT) TYPE(*NAME)
LEN(10) +
MIN(1)
PROMPT('Project name')
PARM
KWD(SHRTNAM) TYPE(*CHAR) LEN(4)
+
MIN(1) PROMPT('Short project
name')
PARM
KWD(TEXT) TYPE(*CHAR)
LEN(25) +
PROMPT(TEXT)
Introduction To CL
Programming
______
Introduction To CL
Programming
Introduction To CL
Programming
Data Queue
Open Query File
Introduction To CL
Programming
Data Queues
Data Queues are a type of system object that you create, to
which one HLL program can send data and from which another
HLL program can receive data. The receiving program can be
already waiting for the data or can receive the data later.
Example showing how Data Queues work
Job1
Job2
Job3
DATAQ
Server Job
Introduction To CL
Programming
Data Queues
In the above example, several jobs place entries on a Data Queue.
The entries are handled by a server job.Any number of jobs can be
send to the same queue.
Data queues allow the primary job to route the work to the server
job. This frees the primary job to receive the next work request. Any
number of server jobs can receive from the same data queue.
When no entries are on a data queue, server programs have the
following options
Wait until an entry is placed on the queue
Wait for a specific period of time, if the entry still has not arrived
then continue processing
Do not wait.
CL 400 ver 1.0
Introduction To CL
Programming
Data Queues
Prerequisite for using Data Queues
Data Queues are created using Create Data Queue (CRTDTAQ)
command. For example:
CRTDTAQ DTAQ(MYLIB / INPUT) MAXLEN(128) TEXT(Sample Data
Queue)
The MAXLEN parameter is required and specifies the maximum
length of the entries that can be sent to the data queue
Introduction To CL
Programming
Data Queues
Managing the Storage Used by a Data Queue
When an entry is received from a data queue, the entry is
removed from the data queue but the auxiliary storage is not
freed. The same auxiliary storage is used again when a new entry
is sent to the data queue. The queue grows larger as entries are
sent to the queue and not received.
Performance is better if the size of the queue is kept less than
100 entries. If the data queue grows too large delete the queue
using the Delete Data Queue (DLTDTAQ) command then recreate
the queue using the CRTDTAQ command
Introduction To CL
Programming
Data Queues
Receiving Data with Data Queues
To receive data from a data queue call the QRCVDTAQ program from
the HLL program . For example, in a CL program it is used as follows
CALL PGM (QRCVDTAQ) PARM(&QNAME &LIB &FLDLEN &WAIT +
&ORDER &KEYLEN &KEY &SNDRLEN &SNDR)
The five mandatory parameters are
&QNQME is a 10-byte character field that names the data queue.
&LIB is a 10-byte character field that names the library containing
the
data queue. *LIBL or *CURLIB can be used
&FLDLEN is a 5-digit packed decimal variable with no decimal
positions
&FIELD is a character field of length &FLDLEN. &FIELD is the field
that
receives the data coming from the data queue
CL 400 ver 1.0
Introduction To CL
Programming
Data Queues
&WAIT is a 5-digit packed decimal field with no decimal
positions. When
no entries are in the data queue, the WAIT
parameter specifies the following:
A negative value indicates an unlimited wait request
Zero indicates to continue processing immediately(no
waiting). If no entry exists the call completes immediately
with &FLDLEN set to zero
A positive value specifies the number of seconds to wait
The maximum value, 99999 allows a wait of approximately 28
hours
Introduction To CL
Programming
Data Queues
Sending Data with Data Queues
Call QSNDDTAQ PARM(&QNAME &LIB &FLDLEN &FIELD)
Clearing Data from Data Queues
To clear data from a data queue, call the QCLRDTAQ program from
your HLL program. For example in a CL program it is used as follows
CALL PGM(QCLRDTAQ) PARM (&QNAME &LIB)
The two that must be passed are
&QNAME is a 10-byte character field that names the data queue
& LIB is a 10-byte character field that names the library
containing the
data queue
CL 400 ver 1.0
Introduction To CL
Programming
Data Queues
Advantages of Data Queues
Using Data Queues frees a job from performing some work. If the job
is an interactive job , data queues can provide response time and
decrease the size of the interactive program and its process access
group. This in turn can help overall system performance. For example
If several workstation users enter a transaction that involves updating
and adding to several files, the system can perform better if the
interactive jobs submit the request for the transaction to a single batch
processing job
Data
Introduction To CL
Programming
Data Queues
Advantages of Data Queues
You can send to and receive from data queue in any HLL program
by calling the QSNDDTAQ, QRCVDTAQ programs without exiting the
HLL program or calling a CL program to send or receive the data
More
than one job can receive data from the same data
queue.This is advantageous in certain applications where the
number of entries to be processed is greater than one job can
handle within the desired performance restraints.For example
If several printers are are available to print orders several
interactive jobs could send request to a simple data queue. A
separate job for each printer could receive from the data queue
either in FIFO or LIFO order
CL 400 ver 1.0
Introduction To CL
Programming
Data Queues
Advantages of Data Queues
Data Queues have the ability to attach a sender ID to each
message
being placed on the queue.
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
The Open Query File (OPNQRYF) command opens a file that contains
a set of database records that satisfies a database query request.
Once opened, the file looks like a database file opened by using the
Open Database File (OPNDBF) command, and the records in the file
are accessed by high-level language programs that share the open
data path (ODP). The path is closed, and all query resources are
deallocated, by using the Close File (CLOF) command.
This command is used to do any combination of the following
database
functions:
Join records from more than one file, member, and record format.
Calculate new field values by using numeric and character
operations
on field values and constants.
CL 400 ver 1.0
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
Group
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
Example : Selecting Specific Records
OPNQRYF FILE(ordfile) OPTION(*all)
QRYSLT('orddate=%range("840101" "841231")
& ordamt>100')
KEYFLD((ordamt *descend))
This command uses the QRYSLT parameter to select only records in the
first member of file ORDFILE that have an order date in 1984 and an
order amount greater than 100. Because the FORMAT parameter is
omitted, the open query file has the same record format as file
ORDFILE. The open query file allows all file operations (input, output,
update, and delete). The
KEYFLD specification is used to force the records to be arranged by
descending value of order amount.
CL 400 ver 1.0
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
Five steps involved with Open query file are
OVRDBF
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
Is basically used for
Dynamic
record selection
Dynamic keyed access path
Dynamic keyed access path over join
Dynamic join
Mapped field definitions
Group processing
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
For dynamic keyed access
OVRDBF FileA Share (*yes)
OPNQRYF FileA KEYFLD (CUST)
Call PGMB
For composite key KEYFLD (CUST DATE)
Introduction To CL
Programming
OPEN QUERY FILE (OPNQRYF)
For Group processing
Group