Sie sind auf Seite 1von 41

Control Language/400

What is CL

CL stands for Control Language CL is a part of OS/400 AS/400 control language is a set of commands that you use to control operations and request system related functions.

A single CL statement is called a CL command. around 1500 CL commands exits.

A command can be typed on a command line and can be grouped together or compiled into an object into CL program.

CL programs can be used to perform repetitive processing,reducing errors and need for computer operator intervention.
2

Limitations

We can declare only 5 file in CL program. It can be either database or display file.

We can just retrieve the data from a CL File. We dont have Arrays and Data structure concept in CL language. We dont have Subfiles concept in CL Language. We dont have Printer file concept in CL language. Hence CL is called Partly high level language.

CL Program can perform

Start jobs by calling program or submitting jobs for batch processing.

Control sequence of processing with in program and among different programs.

Check for existence of objects with in the system and check for authority.

Create and manage system objects(files, programs and commands)

Handle error conditions used by programs.


Control communication. Send messages between programs, users and other programs.
4

CL Program Source Member


Consists of CL commands and comments. Free format statements can begin from any part of the source member. Blank links can be inserted any where to improve readability. Commands can be entered in positional, keyword or mixed notation. comments begins with /* and ends with */. When a command does not fit into one line of source member statement, continuation characters + or can be used Labels of 10 character length help documentation or can target GOTO commands.

Four sections in CL source member


1.Program information section 2.Program linkage section 3.Declarative section 4.Procedure section

1.Program information section


For programming documentation purposes Example: /* comment area */

2.Program linkage section


Makes the beginning of CL program Example: PGM /* linkage section */

3.Declarative section
Defines files and variables in CL program. Example: DCL /* declarative section */ DCLF

4.Procedure section
Specifies that a CL program will do when execution. Example: IF COND () THEN /*STD SEGMENT*/ DO -----ENDDO /* Procedure section */
7

Procedure for creating CL Program

Create a library using CRTLIB command

Create a source physical file using CRTSRCPF command


For each specific program add a member to the source physical file.

Type needed CL commands into the source member.


Compile CL program, creating program object.

Types of Variables
They are three types are variables in CLP:

*CHAR *DEC *LOG Decimal -- 15 digits, 9 decimal positions Character -- 9999 characters Logical -- 1 character

Maximum lengths for each of the three types are:


The default lengths for each of the three types are:


Decimal -- 15 digits, 5 decimal positions Character -- 32 characters Logical -- 1 character


9

Declaration of Variables
DCL DCL DCL DCL DCL VAR(&STATE) TYPE(*CHAR) LEN(2) VALUE(AP) VAR(&A) TYPE(*DEC) LEN(2 0) VALUE(10) VAR(&A) TYPE(*LGL) VALUE(0) VAR(&A) TYPE(*DEC) LEN(2 0) VALUE(10) VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE(KARISHMA)

10

Changing Variables
Assign value to the variable value can be literal, another variable or an expression pass parameters from one variable to an another variable.

Example: CHGVAR VAR(&B) VALUE(&A) CHGVAR VAR(&C) VALUE(&A / &B) CHGVAR VAR(&A) VALUE(5) CHGVAR VAR(&A) VALUE((&A) + 1)

11

Sample CL Program

12

Expressions
Arithmetic operators: +,-,*,/ character string operators: *CAT or || (concatenation) *BCAT or |> (concatenation with blanks) *TCAT or |< (concatenation with truncation) Relational operators: *EQ,*GT,*LT,*GE,*LE,*NE OR =,>,<,>=,<=, =

Logical operators: *AND,*OR,*NOT i.e &,|,(square brackets)


Logical constants: 0 false 1

true

13

14

*CAT OR ||

15

*BCAT OR |>

16

*TCAT OR |<

17

%SST OR %SUBSTRING

18

IF Condition

19

IF - ELSE

20

IF -Condition

21

IF -Condition

22

DOWHILE

23

DOUNTIL

24

DOFOR

25

GOTO

26

Error Handling

When an error condition occurs during the execution of a program, an escap message(*ESCAPE)is sent to the program. escape messages identifies the specific error that are occurred. When exception handler is written in the program then such messages with the popup of ugly screens can be avoided. Error messages are stored in a message file. IBM supplied file is (WRKMSGF)QSYS/QCPFMSG. Errors that result in escape messages can be monitored using MONMSG command. MONMSG command can be specified at command level and a program leve Message identifiers have three charter prefix allowed by four position ID. CPF0000 RCVMSG message can be used to receive escape message sent to CL program.the message that can be resent using SNDPGMMSG command.

27

MONMSG

The monitor message(MONMSG) command is used to monitor escape messages, notify,and status messages sent to the program message Queue of the program in which the command being used. Up to 1000 MONMSG commands can be specified in a program. When a MONMSG is compiled in a control language (CL) program, it establishes monitor for the arrival of the specified messages. The specific message identifiers or generic message identifiers can be monitored. When the action specified in the MONMSG command has been performed, and th action does not end with a GOTO or RETURN command, control returns to the command in the program that follows the command that sent the message. The action ends with a GOTO command,control branches to the command in the program specified in the GOTO command.if the action ends with a RETURN command,control returns to the program that called the program that contain the MONMSG command. When using program level MONMSG the EXEC parameter if specified can contain only GOTO command.

28

Command Level

29

Program Level

30

RTVJOBA and RTVSYSVAL

31

RTVMBRD
The Retrieve Member Description (RTVMBRD) command is used in a CL program to retrieve (return) the member-level information (in CL variables) from a database file. The values are returned (copied) to the specified CL variables. The following kinds of member information can be retrieved: The Library name, The member name, The file attribute, The file type, The source type, The source date, The date created, The expiration date, The member text, The number of non deleted records, The number of deleted records, The open data path status (shared or not shared), The data space size, The access path size, The date changed, The date saved, The date restored, The number of data members, The last date used, The days count used and The date and days count was reset.

32

RTVMBRD

33

Sending Messages
SNDMSG SNDBRKMSG SNDPGMMSG SNDUSRMSG

34

Message Types
Informational Inquiry Completion Diagnostic Request Escape Status Notify

35

Object Related
DSPOBJD WRKOBJ RTVOBJD RNMOBJ CRTDUPOBJ CHKOBJ ALCOBJ DLCOBJ

36

Calling Programs
The call command runs a program and passes control to that program.when calling program ends,control is returned to the next command in the calling program. When you call a program parameters can be passed to that program. When program is called it is placed in the call stack. Example: PGMA PGMB PGMC PGM PGM PGM -----------------------------------------------------------------------------CALL PGMB CALL PGMC -------------------------------------------------------------------ENDPGM RETURN RETURN

Defining parameters
Parameters are defined on PARM keyword of CALL or TFRCTL command. With in a called program incoming parameters to be declared with DCL command and must appear in PGM command. The order of parameters passed must be same in the CALL command used in calling program and the PGM command used in the called program. Parameters passed may be either constants or variables. Up to 40 parameters can be specified on CALL and PGM commands. Parameters Can have Character, Decimal or logical Data. Character constant less than 33 positions long are passed to the called program with a length of 32. Decimal constants are passed as packed decimal data and must be received in the called program by variable defined as *DEC(15 5)

Parameter Passing

39

File Handling
Declare using DCLF command. To send or receive information to a workstation from a program a display file is used. To read records from a database files. Only 5 files can be declared for processing and only input operations are allowed on database file

Examples: DCLF File processing SNDRCVF RCDFMT(CONCAT) --you r going to see the display file screen RCVF RCDFMT(RECFMT NAME) receive data from the display file. SNDF RCDFMT(RECFMT NAME) Send data to a display file. FILE(MINDADB/DSPLYMULT) RCDFMT(MULREC)

40

Prepared

by Venkat CH

Das könnte Ihnen auch gefallen