Sie sind auf Seite 1von 6

CL Programs:

A CL program or procedure can be as simple or as complex as you want. To consolidate several activities normally done by the system operator at the beginning of the day (to call programs A, B, and C, for example), you can create a CL procedure called STARTUP with the following code: PGM /* STARTUP */

CALL PGM(A) CALL PGM(B) CALL PGM(C) ENDPGM In this example, the Programmer Menu is used to create the program. You can also use the Programming Development Manager (PDM) or Remote System Explorer (RSE), which are functions of the WebSphere Development Studio for System i licensed program. To enter, create, and use this program or procedure, follow these steps.

To enter CL source, follow these steps: 1. Select option 8 (Edit source) on the Programmer Menu and specify STARTUP in the Parm field. (This option creates a source member named STARTUP that will also be the name of the program.) 2. Specify CLLE in the Type field and press the Enter key.

3. On the SEU display, use the I (insert) line command to enter the CL commands (CALL is a CL command). Columns........: 1 71 Edit QGPL/QCLSRC Find......: _____________________________________________ STARTUP FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ************** Beginning of data *********************************** ....... ....... ....... ....... ....... ....... When you have finished entering the source statements, complete these steps: 1. Press F3 to exit from SEU. 2. Accept the default on the exit display (option 2, Exit and update member) and press the Enter key to return to the Programmer Menu. 3. Select option 3 (Create object) to create a program from the source statements you entered. You do not have to change any other information on the display. Note: The referenced programs (A, B, and C) do not have to exist when the program STARTUP is created. When the program is created, you can call it from the Programmer Menu by selecting option 4 (Call program) and specifying STARTUP in the Parm field. If you want to run this example program, however, the referenced programs must exist by the time the CALL commands are run.

IF command in a CL program or procedure


The If (IF) command is used to state a condition that, if true, specifies a statement or group of statements in the program or procedure to be run. The Else (ELSE) command can be used with the IF command to specify a statement or group of statements to be run if the condition expressed by the IF command is false. The command includes an expression, which is tested (true or false), and a THEN parameter that specifies the action to be taken if the expression is true. The IF command is formatted as follows: IF COND(logical-expression) THEN(CL-command)

The logical expression on the COND parameter can be a single logical variable or constant, or it must describe a relationship between two or more operands; the expression is then evaluated as true or false. If the condition described by the logical expression is evaluated as true, the program or procedure processes the CL command on the THEN parameter. This can be a single command or a group of commands. If the condition is not true, the program or procedure runs the next sequential command. Both COND and THEN are keywords on the command, and they can be omitted for positional entry. The following are syntactically correct uses of this command: IF COND(&RESP=1) THEN(CALL CUS210) IF (&A *EQ &B) THEN(GOTO LABEL) IF (&A=&B) GOTO LABEL Blanks are required between the command name (IF) and the keyword (COND) or value (&A). No blanks are permitted between the keyword, if specified, and the left parenthesis enclosing the value. The following example is about conditional processing with an IF command. Processing branches in different ways depending on the evaluation of the logical expression in the IF commands. Assume, for instance, that at the start of the following code, the value of &A is 2 and the value of &C is 4. IF (&A=2) THEN(GOTO FINAL) IF (&A=3) THEN(CHGVAR &C 5) . . . FINAL: IF (&C=5) CALL PROGA ENDPGM In this case, the program or procedure processes the first IF command before branching to FINAL, skipping the intermediate code. It does not return to the second IF command. At FINAL, because the test for &C=5 fails, PROGA is not called. The program or procedure then processes the next command, ENDPGM, which signals the end of the program or procedure, and returns control to the calling program or procedure. Processing logic would be different if, using the same code, the initial values of the variables were different. For instance, if at the beginning of this code the value of &A is 3 and the value of &C is 4, the first IF statement is evaluated as false. Instead of processing the GOTO FINAL command, the program or procedure ignores the first IF statement and moves on to

the next one. The second IF statement is evaluated as true, and the value of &C is changed to 5. Subsequent statements, not shown here, are also processed consecutively. When processing reaches the last IF statement, the condition &C=5 is evaluated as true, and PROGA is called. A series of consecutive IF statements are run independently. For instance: PGM /* DCL &A.. DCL &B.. DCL &C.. DCL &D.. DCL &AREA *CHAR LEN(5) VALUE(YESNO) DCL &RESP.. IF (&A=&B) THEN(GOTO END) IF (&C=&D) THEN(CALL PGMA) /* /* IF #1 IF #2 /* */ */ */ /* IF #4 */ IFFY */

IF (&RESP=1) THEN(CHGVAR &C 2)

IF #3

IF (%SUBSTRING(&AREA 1 3) *EQ YES) THEN(CALL PGMB) CHGVAR &B &C . . . END: ENDPGM

If, in this example, &A is not equal to &B, the next statement is run. If &C is equal to &D, PGMA is called. When PGMA returns, the third IF statement is considered, and so on. An embedded command is a command that is completely enclosed in the parameter of another command. In the following examples, the Change Variable (CHGVAR) command and the DO command are embedded: IF (&A *EQ &B) THEN(CHGVAR &A (&A+1))

IF (&B *EQ &C) THEN(DO) . .

. ENDDO Parent topic: Controlling processing within a CL program or CL procedure Related reference *AND, *OR, and *NOT operators DO command and DO groups in a CL program or procedure ELSE command in a CL program or procedure Embedded IF commands in a CL program or procedure Related information CL command finder If (IF) command

DO command and DO groups in a CL program or procedure


The Do (DO) command allows you to process a group of commands together. The group is defined as all those commands between the DO command and the corresponding End Do Group (ENDDO) command. Processing of the group is typically conditioned on the evaluation of an associated command. Do groups are most frequently associated with the IF, ELSE, or MONMSG commands. Here is an example of a Do group.

If the logical expression (&A=&B) is true, then the Do group is processed. If the expression is not true, then processing starts after the ENDDO command; the Do group is skipped. In the following procedure, if &A is not equal to &B, the system calls PROCB. PROCA is not called, nor are any other commands in the Do group processed.

Do groups can be nested within other Do groups, up to a maximum of 25 levels of nesting. There are three levels of nesting in the following example. Note how each Do group is completed by an ENDDO command.

In this example, if &A in the first nest does not equal 5, PGMC is called. If &A equals 5, the statements in the second Do group are processed. If &AREA in the second Do group does not equal YES, procedure ACCTSPAY is called, because processing moves to the next command after the Do group. The CL compiler does not indicate the beginning or ending of Do groups. If the CL compiler notes any unbalanced conditions, it is not easy to detect the actual errors. Parent topic: Controlling processing within a CL program or CL procedure Related reference IF command in a CL program or procedure Related information CL command finder Do Group (DO) command

Das könnte Ihnen auch gefallen