Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
Hi mijanurit,
Check the answers for your query,
The SET verb is used for a number of unrelated functions in COBOL, so instead of dealing with it as a single topic, we will deal each format as we examine the construct to which it is most closely related.
Quote:
SET {ConditionName} ... TO TRUE
A Condition Name set to true when one of the condition values mentioned in its VALUE clause is moved into its associated data-item. But you can also set a Condition Name to true using the SET verb.
When the SET verb is used to set a Condition Name, the first condition value specified after the VALUE clause in the definition is moved to the associated data-item. Thus, the value of the associated data-item is changed.
So, any operation which changes the value of the data-item may change the status of the associated Condition Names, and any operation which changes the status of a Condition Name may change the value of its associated data-item.
It is not (at present) possible to set a condition name to False.
Using the SET verb with Sequential Files
The SET verb is most often used to set an end of file Condition Name when reading Sequential Files. The animation below demonstrates how to set up and use an end of file Condition Name.
PROCEDURE DIVISION.
Begin.
OPEN INPUT StudentFile
READ StudentFile
AT END SET EndOfStudentFile TO TRUE
END-READ
PERFORM UNTIL EndOfStudentFile
DISPLAY StudentId SPACE StudentName SPACE CourseCode
READ StudentFile
AT END SET EndOfStudentFile TO TRUE
END-READ
END-PERFORM
CLOSE StudentFile
STOP RUN.
In this example, the EndOfStudentFile Condition Name is attached to the StudentDetails record. When EndOfStudentFile is set to true, every character of the record is filled with HIGH-VALUES (the highest ASCII value the character can hold).
More examples
Example1:
The following declares a condition name, EOF-FLAG:
Quote:
01 READ-FLAG PIC 9.
88 EOF-FLAG VALUE 1.
The following SET statement uses the condition name EOF-FLAG:
Quote:
SET EOF-FLAG TO TRUE.
The SET statement above is equivalent to the following MOVE statement:
Quote:
MOVE 1 TO READ-FLAG
.
Example2:
You cannot set a condition name to FALSE, but you can define two
condition names, one for the true case and one for the false case. The
following example illustrates this:
Quote:
01 FIRST-TIME-FLAG PIC X VALUE "Y".
88 FIRST-TIME VALUE "Y".
88 FIRST-TIME-OFF VALUE "N".
The following example uses the SET statement on both condition names:
Quote:
IF FIRST-TIME
PERFORM INIT-SECTION
SET FIRST-TIME-OFF TO TRUE
END-IF
NOTE
In COBOL II the 88 levels can be set rather than moving their associated values to the related data item. (Web note: This change is not one of COBOL II's better specifications.)