You are on page 1of 11

CL Commands

The following is a list of commands that are frequently used in CL


procedures. You can use this list to select the appropriate command
for the function you want. IBM provides online information on how to
determine the command you might need. Refer to the CL section of
the Programming category in the iSeries Information Center for this
information. Familiarity with the function of these commands will help
you to understand subsequent topics in this chapter. Superscript 1
indicates the commands that you can use only in CL programs and
procedures.
System
Function
Change
Procedure
Control

Command

Command Function

CALL (Call)

Calls a program

CALLPRC (Call
Procedure) 1

Calls a procedure.

RETURN (Return) Returns to the command


following the command that
caused a program or
procedure to be run
CL Procedure
Limits

CL Procedure
Logic

PGM (Program) 1 Indicates the start of CL


procedure source
ENDPGM (End
Program) 1

Indicates the end of CL


procedure source

IF (If) 1

Processes commands
based on the value of a
logical expression

ELSE (Else) 1

Defines the action to be


taken for the else (false)
condition of an IF command

DO (Do) 1

Indicates the start of a Do


group

ENDDO (End Do) Indicates the end of a Do


1
group

CL Procedure
Variables

Conversion

GOTO (Go To) 1

Branches to another
command

CHGVAR
(Change
Variable)1

Changes the value of a CL


variable

DCL (Declare) 1

Declares a variable

CHGVAR
(Change
Variable)1

Changes the value of a CL


variable

CVTDAT (Convert Changes the format of a


Date) 1
date
Data Areas

CHGDTAARA
(Change Data
Area)

Changes a data area

CRTDTAARA
(Create Data
Area)

Creates a data area

DLTDTAARA
(Delete Data

Deletes a data area

Area)

Files

DSPDTAARA
(Display Data
Area)

Displays a data area

RTVDTAARA
(Retrieve Data
Area) 1

Copies the content of a data


area to a CL variable

ENDRCV (End
Receive) 1

Cancels a request for input


previously issued by a
RCVF, SNDF, or SNDRCVF
command to a display file

DCLF (Declare
File) 1

Declares a display or
database file

RCVF (Receive
File) 1

Reads a record from a


display or database file

RTVMBRD
Retrieves a description of a
(Retrieve Member specific member of a
Description) 1
database file
SNDF (Send File) Writes a record to a display
1
file
SNDRCVF
(Send/Receive
File) 1

Writes a record to a display


file and reads that record
after the user has replied

WAIT (Wait) 1

Waits for data to be received


from an SNDF, RCVF, or
SNDRCVF command issued
to a display file

Messages

MONMSG
(Monitor
Message) 1

Monitors for escape, status,


and notify messages sent to
a program's message queue

RCVMSG
(Receive
Message) 1

Copies a message from a


message queue into CL
variables in a CL procedure

RMVMSG
(Remove
Message) 1

Removes a specified
message from a specified
message queue

RTVMSG
(Retrieve
Message) 1

Copies a predefined
message from a message
file into CL procedure
variables

SNDPGMMSG
(Send Program
Message) 1

Sends a program message


to a message queue

SNDRPY (Send
Reply) 1

Sends a reply message to


the sender of an inquiry
message

SNDUSRMSG
(Send User
Message)

Sends an informational or
inquiry message to a display
station or system operator

Miscellaneous CHKOBJ (Check Checks for the existence of


Commands
Object)
an object and, optionally, the
necessary authority to use
the object
PRTCMDUSG
(Print Command
Usage)

Produces a cross-reference
listing for a specified group
of commands used in a

specified group of CL
procedures
RTVCFGSRC
(Retrieve
Configuration
Source)

Generates CL command
source for creating existing
configuration objects and
places the source in a
source file member

RTVCFGSTS
(Retrieve
Configuration
Status) 1

Gives applications the


capability to retrieve
configuration status from
three configuration objects:
line, controller, and device.

RTVJOBA
(Retrieve Job
Attributes) 1

Retrieves the value of one or


more job attributes and
places the values in a CL
variable

RTVSYSVAL
Retrieves a system value
(Retrieve System and places it into a CL
Value) 1
variable

Program
Creation
Commands

RTVUSRPRF
(Retrieve User
Profile) 1

Retrieves user profile


attributes and places them
into CL variables

CRTCLMOD
(Create CL
Module)

Creates a CL module

DLTMOD (Delete Deletes a module


Module)
DLTPGM (Delete Deletes a program

Program)
CRTBNDCL
Creates a bound CL
(Create Bound
program.
Control Language
Program)
CRTCLPGM
(Create CL
Program)

Creates an OPM CL
program.

CRTPGM (Create Creates a program from one


Program)
or more modules.
CRTSRVPGM
(Create Service
Program)

Creates a service program


from one or more modules.

Using CL Procedures
CL programming is a flexible tool allowing you to perform a variety of
operations. Each of the following uses is described in greater detail in
individual sections later in this chapter. In general, you can:

Use variables, logic control commands, expressions, and builtin functions to manipulate and process data within a CL
procedure:
PGM
DCL &C *LGL
DCL &A *DEC VALUE(22)
DCL &B *CHAR VALUE(ABCDE)
*
*
*
CHGVAR &A (&A + 30)
*
*
*
IF (&A < 50) THEN(CHGVAR &C '1')
*
DSPLIB ('Q' || &B)
*
IF (%SST(&B 5 1)=E) THEN(CHGVAR &A 12)
*
*
*
ENDPGM

Use a system value as a variable in a CL procedure.

Use a job attribute as a variable in a CL procedure.

Send and receive data to and from a display file with a CL


procedure.

Create a CL procedure to monitor error messages for a job, and


take corrective action if necessary.

PGM

ERROR)

MONMSG MSGID(CPF0001) EXEC(GOTO


CALL PROGA
CALL PROGB
RETURN

ERROR:

SNDPGMMSG MSG('A CALL command


failed') MSGTYPE(*ESCAPE)

ENDPGM
Control processing among procedures and programs and pass
parameters from a CL procedure to other procedures or
programs to override files.

Used as a controlling procedure, a CL procedure can call procedures


written in other languages. The following illustration shows how
control can be passed between a CL procedure and RPG IV* and ILE
COBOL procedures in an application. To use the application, a work

station user would request program A, which controls the entire


application. The illustration shows: The preceding example shows a
single bound program (PGMA) that is called using the CALL
command with PGMA. PGMA consists of:

A CL procedure (PGMA) calling an RPG IV procedure (PGMB)


An RPG IV procedure (PGMB) calling another RPG IV
procedure (PGMC)
An RPG IV procedure (PGMB) calling a CL procedure (PGMD)
A CL procedure (PGMA) calling an ILE COBOL procedure
(PGME)
An ILE COBOL program (PGME) calling a CL procedure
(PGMF)

The procedures can be created as indicated in the following example.


You can enter source for procedures in separate source members.
CRTCLMOD PGMA
CRTRPGMOD PGMB
CRTRPGMOD PGMC
CRTCLMOD PGMD
CRTCBLMOD PGME
CRTCLMOD PGMF
CRTPGM PGM(PGMA) +

PGMF) +

MODULE(PGMA PGMB PGMC PGMD PGME


ENTMOD(*FIRST)

You might also like