Page 1 of 1

PERFORM WITH INDEX VARIABLE...Need help on this code

PostPosted: Thu Aug 06, 2009 4:58 am
by vkumard
I'm executing the below code...
CUS-SUB had value of 13
PERFORM VARYING CUS-NDX FROM CUS-SUB BY +1         
    UNTIL CUSTOMER-NOT-FOUND                       
       OR CUST-RANGE-FND       
    IF CUS-NBR (CUS-NDX) = EMRC-EMR-SERVD-ENT-PHNUM
         SET WS-DISP-INX  TO CUS-NDX         
         DISPLAY 'CUS-NDX VALUE=' WS-DISP-INX   
        SET CUST-RANGE-FND TO TRUE                 
    ELSE             
        IF CUS-NBR (CUS-NDX) > EMRC-EMR-SERVD-ENT-PHNUM
            SET CUSTOMER-NOT-FOUND TO TRUE             
        END-IF                                         
    END-IF                                             
END-PERFORM         
SET WS-DISP-INX  TO CUS-NDX         
DISPLAY 'CUS-NDX VALUE=' WS-DISP-INX 



Output:
CUS-NDX VALUE= 13
CUS-NDX VALUE= 14

When I execute this code, the value of WS-DISP-INX displayed as 13 inside the perform and displayed as 14 outside the PERFORM statement..

How the counter value has been incremented?.. Is it right??
I thought index value will come as 13 outside the perform statement..
Because based on the indexed value, am doing subsequent operation further in my program...

please help me why the index field got different values..

Re: PERFORM WITH INDEX VARIABLE...Need help on this code

PostPosted: Thu Aug 06, 2009 6:11 am
by dick scherrer
Hello,

See if this helps clarify:
http://publibz.boulder.ibm.com/cgi-bin/ ... 0/6.2.27.6

This is the link to the Table of Contents for the COBOL Language Reference (which contains the above link) - something you will want to bookmark or download:
http://publibz.boulder.ibm.com/cgi-bin/ ... 0/CONTENTS