A conditional statement lets you specify alternative program actions, depending on the true or false value of a condition. COBOL lets you specify any of these simple conditions:

  • Class condition - For testing whether data is alphabetic, uppercase alphabetic, lowercase alphabetic, numeric, DBCS, Kanji, or consists entirely of the characters listed in the definition of a user-defined class-name. When testing whether a data item is numeric, the outcome will depend on the evaluation of the sign digit. The compiler option NUMPROC(PFD) which bypasses invalid sign processing may affect the outcome of a test for numeric value.
  • Condition-name condition - For testing a level-88 condition name to discover whether or not a data item contains a particular value or range of values
  • Relation condition - For comparing two items
  • Sign condition - For testing whether a numeric operand is less than, greater than, or equal to zero
  • Switch-status condition - For testing whether an UPSI switch is on or off

You can create combined conditions by use of logical connectives (AND, OR, or NOT) and you can combine combined conditions. Use level-88 items to define condition-names you can test to control the processing of switches and flags.

Condition-Names (Switches and Flags)

Some program decisions are based on whether the value of a data item is true or false, on or off, yes or no. Define level-88 items with meaningful names to act as switches to control these two-way decisions in your program. For example, to test for an end-of-file condition for an input file named IN-FILE, you could use the following data definitions:

Condition-Names (Switches and Flags)

The level-88 description says a condition named WS-EOF-CN is turned on when WS-STATUS-IND has a value of 'Y'. Referencing WS-EOF-CN in your Procedure Division expresses the same condition as testing for WS-STATUS-IN = 'Y'. For example, consider the following statement:


The above statement causes the report to be printed only if your program has read through to the end of the IN-FILE and if the WS-STATUS-IND has been set to 'Y Some program decisions are based not on an on or off condition of a data item, but instead, depend on the particular value (or range of values) of a data item. To test for more than two specific values, you can assign more than one condition-name to a field by using multiple level-88 items. When condition is used to give more than just on or off values to a field, the field is generally referred to as a flag, not a switch. Consider a program that checks the status of a Software Configuration Library object's status. The status is read from a file which contains a field SCM-STATUS that gives the status of the object, namely OPEN, LOAN, RETURNED, REVIEWED and PROMOTED. In the input file's record description you can code a field for the status code using the 88-level items:


The code in the Procedure Division for testing these condition-names will look like this:

Procedure Division for testing these condition-names

Flags and switches make your code easier to modify. If you need to change the values for a condition, you have to change only the level-88 condition-name value. The name of the condition as you use it in the Procedure Division need not be changed. For example, a program that uses a condition-name to test a field for a given numeric range-a salary range-need not be changed. If the program must be modified to check for a different salary range, you would need to change only the condition-name value in the Data Division. You do not need to make changes in the Procedure Division.

Resetting Condition-Names (Switches and Flags)

Throughout your program, you may need to reset your switches to on or off, or change your flags back to the original values they have in their data descriptions. To do so, you can use either a SET statement or define your own data item to use. The syntax of the SET statement is as follows:

SET condition-name TO TRUE"

When you use the SET condition-name TO TRUE statement, the switch or flag is set back to the original value it was assigned in its data description. For a level-88 item with multiple values (such as 88 RECORD-IS-ACTIVE-CN VALUE "A" "O" "S"), SET RECORD-IS-ACTIVE-CN TO TRUE assigns the first value ("A" in this case). We have seen the overview of a COBOL program in this chapter. We have also seen structured programming practices and how to code programs efficiently using statements like PERFORM, IF, EVALUATE, DO, DO...WHILE, etc.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

IBM Mainframe Topics