SET TO TRUE
Part of the Decisions and Loops section of Coddy's COBOL Programming journey. Lesson 7 of 20.
SET a condition name TO TRUE moves its value into the field. The program names the state, not the code behind it:
01 ORDER-STATUS PIC X VALUE "N".
88 IS-NEW VALUE "N".
88 IS-PAID VALUE "P".SET IS-PAID TO TRUE *> ORDER-STATUS = "P"When an 88 lists several values, SET moves the first one:
88 PASS-GRADE VALUE "B" "C".SET PASS-GRADE TO TRUE *> GRADE = "B"A flag is a one-character field with a condition name for each state. One part of a program sets it and another tests it:
01 REVIEW-FLAG PIC X VALUE "N".
88 NEEDS-REVIEW VALUE "Y".
88 NO-REVIEW VALUE "N".To switch a flag back, SET its other condition name TO TRUE: SET NO-REVIEW TO TRUE.
Challenge
EasyRead PAID-AMT. When it covers ORDER-TOTAL (250), set IS-PAID to true. Then print the status code: Status: P or Status: N
Example input, one line per ACCEPT: 250.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. ORDERST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PAID-AMT PIC 9(4).
01 ORDER-TOTAL PIC 9(4) VALUE 250.
01 ORDER-STATUS PIC X VALUE "N".
88 IS-NEW VALUE "N".
88 IS-PAID VALUE "P".
PROCEDURE DIVISION.
ACCEPT PAID-AMT.
*> Set IS-PAID when the order is covered
DISPLAY "Status: " ORDER-STATUS.
STOP RUN.