Reputation: 31
I have a program with multiple (non-nested) EVALUATE
statements.
The program is not behaving like I expect it to.
My suspicion is the EVALUATE
statement. (I had a similar problem with a SEARCH ~ END-SEARCH
in which control passes to the next sentence, not the next verb.) Is EVALUATE
the same? I've looked at IBM docs but can't find an answer. I hope someone can help me with this.
In the code below, I want to know where control is passed to after the imperative statement of a WHEN
clause has completed.
Here is a code snippet:
1000-PROCESS-TRANSACTIONS.
PERFORM UNTIL END-OF-TRANSACTIONS
EVALUATE TRUE
WHEN WS-TF-TXN-CODE = 'A'
PERFORM 1000-ADD-RECORD THRU
1000-ADD-RECORD-END
WHEN WS-TF-TXN-CODE = 'C'
PERFORM 1000-UPDATE-RECORD THRU
1000-UPDATE-RECORD-END
WHEN OTHER
MOVE 'INVALID TXN CODE, TXN REC= ' TO WS-EF-ERROR-MSG
MOVE WS-TF-DATA-AREA TO WS-EF-DATA-AREA
WRITE ERROR-RECORD FROM WS-ERROR-RECORD
END-EVALUATE
READ TRANS-FILE INTO WS-TRANS-FILE-REC
AT END
MOVE HIGH-VALUES TO EOTF-SWITCH
END-READ
END-PERFORM.
1000-PROCESS-TRANSACTIONS-END.
EXIT.
In the preceding code, where does control pass to after:
PERFORM 1000-ADD-RECORD THRU 1000-ADD-RECORD-END
when the TXN-CODE is 'A'
PERFORM 1000-UPDATE-RECORD THRU 1000-UPDATE-RECORD-END
when the TXN-CODE is 'C'
andWRITE ERROR-RECORD FROM WS-ERROR-RECORD
when theTXN-CODE is OTHER
.Does control pass to the NEXT SENTENCE
, i.e. after the END-PERFORM
scope terminator; or, does control pass to the READ
statement, i.e. after the END-EVALUATE
?
Upvotes: 1
Views: 173
Reputation: 7297
Control only passes to NEXT SENTENCE
if you explicit ask it to by using this (archaic = should not be used in any new code) statement. NEXT STATEMENT
is a jump instruction "wherever the next period is".
The control flow of EVALUATE
is the same as with SEARCH
- the program goes on after the matching terminator END-xyz
.
The "gotcha" is possibly in one of the PERFORM ... THROUGH
which are coded within the EVALUATE
:
GO TO
so don't ever reach the coded THROUGH
THROUGH
Upvotes: 1