IF command (COBOL)
The IF command lets you conditionally perform a command. You can optionally specify an ELSE clause on the IF command. If the test expression evaluates to false and an ELSE clause exists, the command associated with the ELSE clause is performed. The keywords cannot be abbreviated.
.---------. V | >>-IF--condition--+------+----command-+-------------------------> '-THEN-' >--+-------------------+--END-IF--;---------------------------->< | .---------. | | V | | '-ELSE----command-+-'
- condition
- A simple relation condition with the following form: Item-1 operator Item-2. Item-1 and Item-2 can
be a data-item or a literal. The operator can be one of the following
operations:
- >
- <
- =
- NOT =
- >=
- <=
- NOT <
- NOT >
- command
- A valid Debug Tool command.
When IF commands are nested and ELSE clauses are present, a given ELSE or END-IF is associated with the closest preceding IF clause within the same block.
Unlike COBOL, Debug Tool requires terminating punctuation (;) after commands. The END-IF keyword is required.
Usage notes
- An ELSE clause should always be included if the IF clause causes Debug Tool to get more input (for example, an IF containing USE or other commands that cause Debug Tool to be restarted because an AT-condition occurs).
- The COBOL NEXT SENTENCE phrase is not supported.
- Comparison combinations with windowed date fields are not supported.
- Comparisons between expanded date fields with different DATE FORMAT clauses are not supported.
- If the DATA option of the PLAYBACK ENABLE command is in effect, the IF command can be used while you replay recorded statements by using the PLAYBACK commands.
- For optimized COBOL programs, the IF clause cannot reference any variables discarded by the optimizer.
- If a COBOL variable is defined as National and it is an operand in a relation condition with an alphabetic, alphanumeric operand, or National numeric, the operand that is not National is converted to Unicode before that comparison is done, except for Group items. See Enterprise COBOL for z/OS Language Reference for more information about using COBOL variables in conditional expressions.
Refer to the following topics for more information related to the material discussed in this topic.
- Related references
- Allowable comparisons for the IF command (COBOL)