Reputation: 43
Is-it possible to exit a double perform:
PERFORM VARYING J FROM 1 BY 1 UNTIL J>10
PERFORM VARYING K FROM 1 BY 1 UNTIL K>3
IF J=2 and K=2
EXIT PERFORM
ELSE
display "LABEL A ===> PROCEDURE NOM_PROC2 "
"J=/"J"/ AND K=/"K"/"
END-IF
END-PERFORM
END-PERFORM
I tried with EXITI PERFORM but it doesn't work for me.
Upvotes: 3
Views: 959
Reputation: 106
How about:
DisplayLabel section.
PERFORM VARYING J FROM 1 BY 1 UNTIL J>10
PERFORM VARYING K FROM 1 BY 1 UNTIL K>3
IF J=2 and K=2
EXIT SECTION
ELSE
display "LABEL A ===> PROCEDURE NOM_PROC2 "
"J=/"J"/ AND K=/"K"/"
END-IF
END-PERFORM
END-PERFORM
exit section.
Call the DisplayLabel section with "perform DisplayLabel"
Upvotes: 2
Reputation: 13076
Well, if your original code is PL/I and your remit is not to change the structure of a program if it can be avoided, then use GO TO
.
PL/I can exit from a DO
with a STOP
, RETURN
(neither of those is suitable for your situation), LEAVE
or GOTO
.
LEAVE label
or
GOTO label
You would change either of those to
GO TO label
And have identical results. You don't need to change the existing label even, except for a small difference in syntax, and not even have to think about any code after the label.
If you are able to change the structure of the code you already have two good answers. Brian Tiffin's is the neatest, but cschneid's will be more obvious to the majority of COBOL programmers, who will not know how to "vary" more than once on the same PERFORM
.
Upvotes: 0
Reputation: 4116
Use the power of VARYING AFTER performs
perform varying j from 1 by 1 until j > 10
after k from 1 by 1 until k > 3
if j = 2 and k = 2 then
exit perform
else
display "j: " j ", k: " k
end-if
end-perform
prompt$ cobc -xj exitnest.cob
j: 01, k: 01
j: 01, k: 02
j: 01, k: 03
j: 02, k: 01
prompt$
COBOL 2014 (draft) spec has 14.9.27.2
10) At least six AFTER phrases shall be permitted in varying-phrase.
Upvotes: 2
Reputation: 10765
If I understand your question correctly, you want to exit both in-line PERFORMs
with the EXIT PERFORM
. The following technique should work.
01 SWITCHES.
05 EOL-SW PIC X VALUE 'N'.
88 EOL VALUE 'Y'.
88 NOT-EOL VALUE 'N'.
SET NOT-EOL TO TRUE
PERFORM VARYING J FROM 1 BY 1 UNTIL J>10 OR EOL
PERFORM VARYING K FROM 1 BY 1 UNTIL K>3 OR EOL
IF J=2 and K=2
SET EOL TO TRUE
ELSE
display "LABEL A ===> PROCEDURE NOM_PROC2 "
"J=/"J"/ AND K=/"K"/"
END-IF
END-PERFORM
END-PERFORM
From a previous question you indicated you were transliterating PL/I to COBOL. Just as with spoken and written languages, computer languages have idioms and colloquialisms that don't translate well.
I believe that, logically, this is equivalent.
PERFORM VARYING J FROM 1 BY 1 UNTIL J>2
PERFORM VARYING K FROM 1 BY 1 UNTIL K>2
display "LABEL A ===> PROCEDURE NOM_PROC2 "
"J=/"J"/ AND K=/"K"/"
END-PERFORM
END-PERFORM
Upvotes: 3