COBOL 88 level number with Examples

COBOL 88 Level Number or Condition Names 

88 level number in COBOL is one of the most used declarations in mainframes development and it is considered as a special level number which is used to improve the readability of COBOL programs. As it gives a name to a condition, it is also called as ‘Condition Names’. Level number 88 is used to declare these items and it is declared as a subordinate to another data item of level numbers 01 to 49.

COBOL 88 Level Uses:

– Used to check the declared conditions in the program flow.
– Simplifies the IF and Perform UNTIL conditions by directly using these names in the program.

Example:

01 WS-GENDER-FLAG PIC X(01).
     88 MALE VALUE 'M'.
     88 FEMALE VALUE 'F'.

In the program flow, WS-GENDER-FLAG gets populated with either M or F from a database or file. After populating the value, either MALE or FEMALE gets SET accordingly. And these 88 level names can be used in conditions in the program to validate the value present in that field.

MOVE WW-TABLE-GENDER TO WS-GENDER-FLAG

IF MALE
    PERFORM P100-GET-MALE-DTLS
ELSE
    PERFORM P200-GET-FEMALE-DTLS
END-IF

In this way, the condition names can be used directly in the IF conditions where it avoids using of WS-GENEDER-FLAG=’M’ etc.

Multiple Values in 88 Level:

Very useful part of condition names is, it can be validated against multiple values.For example: If there is a requirement to process based on the Continent and the input is the country codes.

01 WS-CONTINT-FLAG PIC X(02) VALUE SPACES.
   88 WS-ASIA          VALUES 'IN' 'PK' 'NP' 'BD' 'CH'.
   88 WS-AMERICA       VALUES 'US' 'CN' 'MX' 'BR'.

So in the program, if any of the above values gets populated respective flag gets SET and that can be used in the program conditions.

MOVE WS-DB2-CNTRY-CD TO WS-CONTINT-FLAG

IF WS-ASIA
    PERFORM P5000-GET-ASIA-DTLS
ELSE
    PERFORM P6000-GER-AMERICA-DTLS
END-IF.
Multiple values by THRU:

If the values given are continuous values then option ‘THRU’ can be given while declaring.

01 WS-NUMBER-CHECK PIC 9(02).
    88 FIRST-10    VALUE 1 THRU 10.
    88 SCND-10     VALUE 11 THRU 20.
    88 THRD-10     VALUE 21 THRU 30.

These condition names can be used in the program and process accordingly.

COBOL 88 Level SET:

Condition names can be set to true or False by using SET verb. It can also be set by moving any value to its group item.

Example: A bank process needs to identify whether the the card he is using is a Debit or Credit and based on that it needs to perform a different functionalities across the program. So here Declare a 88 level and set them based on the business logic.

01 WS-CARD-FLAG PIC X(01) VALUE SPACES.
   88 DEBIT-CARD    VALUE 'D'.
   88 CREDIT-CARD   VALUE 'C'.

IF WS-CUST-ACNT-NUM(1:4)= '5000'
   SET DEBIT-CARD TO TRUE
ELSE
   IF WS-CUST-ACNT-NUM(1:4) = '6000'
      SET CREDIT-CARD TO TRUE
   END-IF
END-IF

IF DEBIT-CARD
    PERFORM D3000-DEBIT-CARD-PROCESS
ELSE
    IF CREDIT-CARD
      PERFORM D4000-CREDIT-CARD-PROCESS
    END-IF
END-IF.
COBOL 88 Level SET when Multiple values are assigned.

When the condition name has multiple values assigned and a SET verb is used then the first value specified in the VALUE clause gets moved into the variable.
As an example if FIRST-10 filed is SET, then the value present in the WS-NUMBER-CHECK would be 1 as 1 is the first value declared.

Notes:
  • Picture clause should not be given to 88 level items. It’s length is equal to it’s group level item.
  • Multiple values can be given by separating them with spaces or commas.
  • Condition names can be SET to TRUE but SET TO FALSE is an invalid case.
  • 88 Level can be subordinate to any level number from 01 to 49.
  • These are very useful in PERFORM … UNTIL loops.
2 Comments

Leave a Reply to admin Cancel reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner