View previous topic :: View next topic
|
Author |
Message |
sophia
New User
Joined: 30 Jun 2007 Posts: 19 Location: United States
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
sophia
New User
Joined: 30 Jun 2007 Posts: 19 Location: United States
|
|
|
|
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?
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest you put in a display within each loop to "track" what happens. . .
Seeing each iteration displayed may help clarify. |
|
Back to top |
|
|
sophia
New User
Joined: 30 Jun 2007 Posts: 19 Location: United States
|
|
|
|
Is there an available PC cobol for download that I can use to test this? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
Back to top |
|
|
|