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



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

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

Postby vkumard » Thu Aug 06, 2009 4:58 am

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..
vkumard
 
Posts: 1
Joined: Thu Aug 06, 2009 4:42 am
Has thanked: 0 time
Been thanked: 0 time

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

 

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

Postby dick scherrer » Thu Aug 06, 2009 6:11 am

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
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post