Previous Topic Next topic Print topic


IF-THEN-ELSE

The IF-THEN-ELSE command sequence is used to conditionally execute commands, or groups of commands if used in conjunction with the DO-END command sequence.

Syntax

IF {LASTCC|MAXCC} operator number
THEN[ command |
 DO
 command set
 END]
[ELSE[command |
 DO
 command set
 END]]

Parameters

LASTCC

specifies that the condition code value that resulted from the immediately preceding function command is to be compared, as indicated by the operator, to the number following the operator. See Condition codes

MAXCC

specifies that the maximum condition code value that has been established by any previous function command or by a SET command is to be compared, as indicated by the operator, to the number following the operator to determine whether the THEN action is to be performed.

operator

specifies the comparison to be made between the variable and the following number. Can be one of:

Operator Description
= or EQ Equal
¬= or NE Not equal
> or GT Greater than
< or LT Less than
>= or GE Greater than or equal
<= or LE Less than or equal
number

specifies the decimal integer that is to be compared with MAXCC or LASTCC. Both LASTCC and MAXCC are initialized to zero upon entry to access method services.

Any value can be used in the comparison. Refer to Condition Codes for the standard values set by MFJAMS, but you can set any value by use of the SET statement; for example:

...
IF LASTCC = 0 THEN
 DO
   SET LASTCC = 2 
 END
IF LASTCC = 2...

Comments

Condition codes that are tested in the IF-THEN-ELSE command sequence or set by the SET command cannot be passed from one job step to the next. However, the maximum condition code value established by any previous functional command or SET command is passed to the operating system when the access method services processor returns control to the system.

When an IF command appears in a THEN or ELSE clause, it is called a nested IF command. The maximum level of nesting allowed is 10, starting with the first IF specified. Within a nest of IF commands, the innermost ELSE clause is associated with the innermost THEN clause, the next innermost ELSE clause with the next innermost THEN clause, and so on. Should there be an IF command that does not require an ELSE clause, follow the THEN clause with a null ELSE clause (ELSE), unless the nesting structure does not require one.

If THEN or ELSE is not followed by a continuation character or by a command in the same record, the THEN or ELSE results in no action. The null command supports an ELSE command that balances an IF-THEN-ELSE command sequence, and allows null THEN commands. The null command is, in essence, a THEN or ELSE command that is not followed by a command continuation character.

To indicate a null ELSE command, specify:

ELSE

To indicate a null THEN command, specify:

IF ... THEN
ELSE ...
Previous Topic Next topic Print topic