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.


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 don’t have Arrays and Data structure concept in CL language. We don’t have Subfiles concept in CL Language. We don’t 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.

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

Program information section For programming documentation purposes Example: /* comment area */ 2.Procedure section 1.Program linkage section Makes the beginning of CL program Example: PGM /* linkage section */ 6 .Program linkage section 3.Four sections in CL source member 1.Declarative section 4.Program information section 2.

Example: IF COND () THEN /*STD SEGMENT*/ DO -----ENDDO /* Procedure section */ 7 .Procedure section Specifies that a CL program will do when execution.3.Declarative section Defines files and variables in CL program. Example: DCL /* declarative section */ DCLF 4.

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.  8 . Compile CL program. creating program object.   Type needed CL commands into the source member.

9 decimal positions Character -.15 digits.1 character 9 .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 -.9999 characters Logical -.Types of Variables They are three types are variables in CLP: • • • *CHAR *DEC *LOG Decimal -.


Changing Variables • • • Assign value to the variable value can be literal. Example: • • • • CHGVAR VAR(&B) VALUE(&A) CHGVAR VAR(&C) VALUE(&A / &B) CHGVAR VAR(&A) VALUE(5) CHGVAR VAR(&A) VALUE((&A) + 1) 11 . another variable or an expression pass parameters from one variable to an another variable.

Sample CL Program 12 .

<=. ¬= • • Logical operators: • *AND.*NOT i./ character string operators: • *CAT or || (concatenation) • *BCAT or |> (concatenation with blanks) • *TCAT or |< (concatenation with truncation) Relational operators: • *EQ.*OR.*LT.-.>.*GE.<.*NE OR =.*.*LE.Expressions • • Arithmetic operators: +.*GT.>=.|.e &.¬(square brackets) Logical constants: ‘0’ false ‘1’ • true 13 .

14 .

*CAT OR || 15 .

*BCAT OR |> 16 .

*TCAT OR |< 17 .


IF Condition • 19 .

ELSE 20 .IF .

IF -Condition 21 .

IF -Condition 22 .



DOFOR 25 .

GOTO 26 .

 When exception handler is written in the program then such messages with the popup of ugly screens can be avoided.the message that can be resent using SNDPGMMSG command.Error Handling  When an error condition occurs during the execution of a program. 27 . 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. escape messages identifies the specific error that are occurred. an escap message(*ESCAPE)is sent to the program.  Error messages are stored in a message file.

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

Command Level 29 .

Program Level 30 .


The date restored. The source date. The member text. The file attribute. The following kinds of member information can be retrieved:  The Library name. The date changed. The values are returned (copied) to the specified CL variables.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 days count used and The date and days count was reset. The access path size. The member name. The number of non deleted records. The expiration date. The file type. The open data path status (shared or not shared). The data space size. The last date used. 32 . The number of deleted records. The source type. The number of data members. The date created. The date saved.



Message Types Informational Inquiry Completion Diagnostic Request Escape Status Notify 35 .


when calling program ends. • When you call a program parameters can be passed to that program.control is returned to the next command in the calling 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 .Calling Programs • The call command runs a program and passes control to that program.

 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.  Up to 40 parameters can be specified on CALL and PGM commands.  Parameters Can have Character.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.  Decimal constants are passed as packed decimal data and must be received in the called program by variable defined as *DEC(15 5) .  Parameters passed may be either constants or variables.  Character constant less than 33 positions long are passed to the called program with a length of 32. Decimal or logical Data.

Parameter Passing 39 .

To send or receive information to a workstation from a program a display file is used. SNDF RCDFMT(RECFMT NAME) – Send data to a display file. To read records from a database files. FILE(MINDADB/DSPLYMULT) RCDFMT(MULREC) 40 .File Handling • • • • Declare using DCLF command. 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.

 Prepared by Venkat CH .