NicholasM
NicholasM

Reputation: 31

EVALUATE statement: Where does control pass to?

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:

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

Answers (1)

Simon Sobisch
Simon Sobisch

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:

  • they may "jump around" anywhere, especially via GO TO so don't ever reach the coded THROUGH
  • the paragraphs may not be in order and therefore may not ever reach the coded THROUGH

Upvotes: 1

Related Questions