View previous topic :: View next topic
|
Author |
Message |
Deepa.m
New User
Joined: 28 Apr 2005 Posts: 99
|
|
|
|
Hello
I need to perform a loop varying ws-sub by 1 to 1 until a condition is met
like for example
PERFORM VARYING WS-SUB FROM 1 BY 1 UNTIL
WS-SUB > PMFC-A-OCCURS
if a(ws-sub) = b then
<some statements>
(statement to break the loop)
end-if
end-perform
(some statments)
I want to come out of perform once my if condition is true and need not continue until ws-sub > PMFC-A-OCCURS
Is there any BREAK statement and using Exit may come out of paragraph
What statement should i use to break perform? |
|
Back to top |
|
|
VinayCM
New User
Joined: 06 Nov 2007 Posts: 36 Location: Bengaluru
|
|
|
|
I think EXIT statement may work.... Otherwise you can use GO TO (Next Para Name) inside IF loop. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Deepa & Vinay,
Quote: |
Otherwise you can use GO TO (Next Para Name) |
Check your shop standards before GOTO is used. |
|
Back to top |
|
|
VinayCM
New User
Joined: 06 Nov 2007 Posts: 36 Location: Bengaluru
|
|
|
|
Murali,
It's true that using GOTO is not a standard way of programming but is there any other ways. If there a way please suggest for my future use. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
perform until .....
or ....
or ....
or ....
do something
set an or conditition true
end-perform
do not use go to's in a perform loop, very poor programming practice as well as difficult to debug. |
|
Back to top |
|
|
Varun Singh
New User
Joined: 01 Aug 2007 Posts: 25 Location: Delhi
|
|
|
|
Hey ,
U can make it simple
by using
compute ws-sub = pmfc-a-occurs + 1
Though I have never used break
and I suppose COBOL does not have any verb 'BREAK'
Though it has a verb 'CONTINUE'
|
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Hi Deepa.m,
Use below code
Code: |
if a(ws-sub) = b then
<some statements>
(statement to break the loop)
WS-SUB = WS-SUB + PMFC-A-OCCURS
end-if
end-perform
(some statments) |
Since WS-B will have high value it will come out of that loop |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi There,
u can also use NEXT SENTENCE for this
Code: |
PERFORM VARYING WS-SUB FROM 1 BY 1 UNTIL
WS-SUB > PMFC-A-OCCURS
IF a(ws-sub) = b then
..
NEXT SENTENCE
END-IF
END-PERFORM. |
|
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi,
Code the following code.
In IF condition, code the following line.
WS-SUB = PMFC-A-OCCURS +1
KSK |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
Hi ksk
Quote: |
WS-SUB = PMFC-A-OCCURS [/code]+1
|
no need to add 1 to PMFC-A-OCCURS
Since we are adding it in perform
this is enough
Code: |
WS-SUB = PMFC-A-OCCURS
|
Before it checks again for the condition it will add 1 to WS-SUB since its a loop. |
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
HI Bala Krishna,
Did you read the question properly.
I KNOW WS-SUB would be incremented since it is in perform.
OS wants to come out of the loop forcibly, so she has to add this condition to come out when IF condition becomes true. |
|
Back to top |
|
|
Deepa.m
New User
Joined: 28 Apr 2005 Posts: 99
|
|
|
|
Thnks for the reply.
ws-sub = pmfc-a-occurs + 1 is one solution that strikes everyone but I am looking for some statements that could acheive this force complete perform other than nomal exit through until condition.
I cant use GOTO or EXIT as it may come out of paragrqaph without executing the statements below end-perform in teh same paragraph
So I think "Next Sentence" is good solution but my period "." comes in end-if. Inside which the perform is coded.
So i will go with ws-sub = pmfc-a-occurs
Thanks Guys. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Deepa,
Quote: |
So I think "Next Sentence" is good solution but my period "." comes in end-if. |
If you are providing '.' inside perform, doesn't the loop terminate there? Could you post your PERFORM loop. |
|
Back to top |
|
|
Deepa.m
New User
Joined: 28 Apr 2005 Posts: 99
|
|
|
|
para1.
if not eof
some sentences
PERFORM VARYING WS-SUB FROM 1 BY 1 UNTIL
WS-SUB > PMFC-A-OCCURS
if a(ws-sub) = b then
<some statements>
(statement to break the loop)
else
<some sentences>
end-if
end-perform
<some sentences>
end-if.
<some sentences>
para-1-exit.
exit.
this is my actual para flow. I need to pass the control to bold part once
a(ws-sub) = b is true
thanks,
Deepa. |
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi Deepa,
If you feel some solution strikes you or you know some possible solution, better post that striking solution while you are posting the question. Others won't waste their time to type and to give the solution. Everybody has their own work to do.
KSK |
|
Back to top |
|
|
|