COBOL allows conditions to be assigned names.
Basically, we use Condition-names to indicate when an AT END condition is reached. The syntax of 88 condition name is as follows:
05 MASTER-FILE-SW PIC X(1) VALUE 'N'.
88 EOF-FILE VALUE 'Y'.
READ MASTER-FILE
AT END MOVE 'Y' TO MASTER-FILE-SW.
READ MASTER-FILE
AT END SET EOF-FILE TO TRUE.
Output:
2.
Output:
WS-A: S
Note: Only level 88 items may have multiple values.
3.
Output:
NOT END OF FILE
Remarks: The 88 condition-name isn't set to TRUE. Hence the output.
Basically, we use Condition-names to indicate when an AT END condition is reached. The syntax of 88 condition name is as follows:
88 condition name VALUE literal
An 88 level entry is usually coded in the WORKING-STORAGE section. The 88 level has only a VALUE clause associated with it. The Values which we provide in the VALUE clause should be of same data type defined in the preceding level. For example,
05 MASTER-FILE-SW PIC X(1) VALUE 'N'.
88 EOF-FILE VALUE 'Y'.
Here, we have defined 88 condition name as an End of File switch for the Master file. Assuming the 88 condition name as a tube light, we've got two ways to switch on the light (to signify the end of file). We can either MOVE 'Y' to MASTER-FILE-SW field or set EOF-FILE condition name to TRUE. The COBOL code will be as follows:
READ MASTER-FILE
AT END MOVE 'Y' TO MASTER-FILE-SW.
READ MASTER-FILE
AT END SET EOF-FILE TO TRUE.
Remember, we can't MOVE 'Y' to EOF-FILE. You can only MOVE the value to the data field defined with a PIC clause (MASTER-FILE-SW in this example) and use the 88 level as a condition. If the MASTER-FILE-SW is equal to 'Y', we call that condition as EOF-FILE.
Examples:
1.Output:
WS-A BEFORE SET:
WS-A AFTER SET:A
Remarks: If SW is set to true, then the value of WS-A field will be 'A' else the value will be a space.2.
Output:
WS-A: S
Remarks: WS-SW is a condition that is met if WS-A field has a value 'S' or 'X' or 'N'. When displaying the field after setting the condition name to TRUE, it shows the first value.
Note: Only level 88 items may have multiple values.
3.
Output:
NOT END OF FILE
Remarks: The 88 condition-name isn't set to TRUE. Hence the output.
Q&A:
Given a scenario like below, which condition name will be set before and after executing the initialize statement? Post your answers in the comments section.
01 VAR-1 PIC X(1) VALUE 'A'.
88 CHAR VALUE 'A' THRU 'Z'.
88 NUMERIC VALUE '0' THRU '9'.
88 SPECIAL VALUE '$','%',' ','&'.
88 STRING VALUE '*','#'.
(...)
INITIALIZE VAR-1
References:
That's it! Thanks for reading.
Should you have any questions or suggestions, please let me know through comments.
References:
Structured COBOL programming - 8th edition - STERN / STERN.
COBOL Coding ground by Tutorials point.
COBOL Coding ground by Tutorials point.
Answer to last question will be 'Special' as VAR-1 will have value as spaces.
ReplyDeleteBefore : CHAR
ReplyDeleteAfter: Special
You're right! Thanks for reading this post.
Delete