1

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:

  • The PERFORM 1000-ADD-RECORD THRU 1000-ADD-RECORD-END when the TXN-CODE is 'A'
  • The PERFORM 1000-UPDATE-RECORD THRU 1000-UPDATE-RECORD-END when the TXN-CODE is 'C' and
  • The WRITE 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?

Dai
  • 141,631
  • 28
  • 261
  • 374
NicholasM
  • 21
  • 3
  • I am receiving a FILE STATUS 46, reading beyond the end of file on the MASTER [not shown in this snipped.] That says to me, that I'm never executing the READ TRANS-FILE; because, control is passing to: – NicholasM Mar 27 '23 at 12:02
  • For the above code to work, `READ TRANS-FILE` must be done once following `OPEN INPUT TRANS-FILE`. Did that `READ` happen? – Rick Smith Mar 27 '23 at 12:25
  • The first read of both files executed. The first trans rec had a TXN-CODE of C; the record was updated. What's happening is the TRANS-FILE [in the snippet] is never being read again. After the first update, I never get an = condition on the account number; because, the IO buffer has the first TRANS-FILE record in it. I get repeated != condition. Eventually the READ MASTER-FILE [in the 1000-UPDATE-RECORD routine] reads beyond EOF. – NicholasM Mar 27 '23 at 12:51

1 Answers1

1

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
Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
  • The 1000-UPDATE-RECORD-END is being executed. The operation appears to go back and forth between the 1000-PROCESS-TRANSACTIONS and the PERFORM 1000-UPDATE-RECORD routines. Based on your comment, it appears that EVALUATE behaves like the SEARCH verb; and, control passes to the next sentence, i.e. after the END-PERFORM, and not to the READ TRANS-FILE block which is immediately after the END-EVALUATE and which sets the switch that will cause the PERFORM to stop looping. I will try this again, inserting a GO TO and a paragraph header just before the READ TRANS-FILE. – NicholasM Mar 27 '23 at 13:03
  • 1
    @NicholasM Simon is correct. The EVALUATE statement will continue after the END-EVALUATE statement, and thus execute the READ statement. Your problem is not in the EVALUATE statement -- it's elsewhere. – Scott Nelson Mar 27 '23 at 16:36