IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

HELP IN understanding the PERFORM STATEMENT


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sophia

New User


Joined: 30 Jun 2007
Posts: 19
Location: United States

PostPosted: Fri Jul 02, 2010 10:42 pm
Reply with quote

Hi can anyone give me a refresher about perform statement. I'm reading a code

here's the part of the code

Code:
WS-T-COUNT-4 = 4

PERFORM VARYING WS-T-COUNT FROM 1 BY 1
             UNTIL WS-T-SORTED-YES
                OR WS-T-COUNT > WS-T-COUNT-4
               SET WS-T-CHANGE-NO TO TRUE

               PERFORM VARYING WS-T-INDEX FROM 2 BY 1
                       UNTIL   WS-T-INDEX > WS-T-COUNT-4
                   COMPUTE WS-T-PREV = WS-T-INDEX - 1

                   IF WS-T-ARRAY1-SRT (WS-T-INDEX) >
                      WS-T-ARRAY1-SRT (WS-T-PREV)
                       SET WS-T-CHANGE-YES TO TRUE
                       MOVE WS-TABLE-ROW (WS-T-INDEX) TO
                            WS-TABLE-ROW (WS-T-LAST)
                       MOVE WS-TABLE-ROW (WS-T-PREV)  TO
                            WS-TABLE-ROW (WS-T-INDEX)
                       MOVE WS-TABLE-ROW (WS-T-LAST)  TO
                            WS-TABLE-ROW (WS-T-PREV)
                   END-IF

                   IF WS-T-ARRAY1-SRT (WS-T-INDEX) =
                      WS-T-ARRAY1-ID-SRT (WS-T-PREV)
                       IF WS-T-ARRAY2-SRT (WS-T-INDEX) <
                          WS-T-ARRAY2-SRT (WS-T-PREV)
                           SET WS-T-CHANGE-YES TO TRUE
                           MOVE WS-DECL-TABLE-ROW (WS-T-INDEX) TO
                                WS-TABLE-ROW (WS-T-LAST)
                           MOVE WS-TABLE-ROW (WS-T-PREV)  TO
                                WS-TABLE-ROW (WS-T-INDEX)
                           MOVE WS-TABLE-ROW (WS-T-LAST)  TO
                                WS-TABLE-ROW (WS-T-PREV)
                       END-IF
                   END-IF
               END-PERFORM
               IF WS-T-CHANGE-NO
                   SET WS-T-SORTED-YES TO TRUE
               END-IF
           END-PERFORM.



My question is after the first loop of the program does it stays in the second perform first until the condition are met or because of the end-perform it goes back to the first perform statement check condition then goes again to the second perform for condition check and processing?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jul 02, 2010 10:58 pm
Reply with quote

It will stay in the second (inner) PERFORM until the condition is met. It will then do the IF statement and go back for the outer PERFORM. COBOL tracks which PERFORM is associated with which END-PERFORM for you.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Jul 02, 2010 11:00 pm
Reply with quote

If I understand the question correctly, the first (inner) END-PERFORM only deals with second (inner) PERFORM.
The second (inner) PERFORM will loop back from the first (inner) END-PERFORM until a condition of that PERFORM is met.
Logic will then continue with the first (outer) PERFORM looping to the second (outer) END-PERFORM until a condition of that PERFORM is met.
Back to top
View user's profile Send private message
sophia

New User


Joined: 30 Jun 2007
Posts: 19
Location: United States

PostPosted: Fri Jul 02, 2010 11:11 pm
Reply with quote

Thanks! so perform number two will be repetitively called inside performing the IF condition until it would reach to a point that it will satisfy the until condition then goes back to perform one. Then the counter in perform 1 will be incremented then calls again perform 2. is that the correct looping here?
icon_confused.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jul 03, 2010 12:00 am
Reply with quote

Hello,

Suggest you put in a display within each loop to "track" what happens. . .

Seeing each iteration displayed may help clarify.
Back to top
View user's profile Send private message
sophia

New User


Joined: 30 Jun 2007
Posts: 19
Location: United States

PostPosted: Sat Jul 03, 2010 12:09 am
Reply with quote

Is there an available PC cobol for download that I can use to test this?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jul 03, 2010 12:20 am
Reply with quote

Hello,

You might try here:
www.cobug.com/cobug/docs/freeCompilers0098.html
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
No new posts SYNCSORT/ICETOOL JOINKEYS SORT Statem... DFSORT/ICETOOL 13
Search our Forums:

Back to Top