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

Terminate from the perform loop


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

New User


Joined: 28 Apr 2005
Posts: 99

PostPosted: Thu Nov 15, 2007 4:12 pm
Reply with quote

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
View user's profile Send private message
VinayCM

New User


Joined: 06 Nov 2007
Posts: 36
Location: Bengaluru

PostPosted: Thu Nov 15, 2007 4:40 pm
Reply with quote

I think EXIT statement may work.... Otherwise you can use GO TO (Next Para Name) inside IF loop.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Thu Nov 15, 2007 4:43 pm
Reply with quote

Deepa & Vinay,

Quote:
Otherwise you can use GO TO (Next Para Name)


Check your shop standards before GOTO is used.
Back to top
View user's profile Send private message
VinayCM

New User


Joined: 06 Nov 2007
Posts: 36
Location: Bengaluru

PostPosted: Thu Nov 15, 2007 4:51 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Nov 15, 2007 4:55 pm
Reply with quote

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
View user's profile Send private message
Varun Singh

New User


Joined: 01 Aug 2007
Posts: 25
Location: Delhi

PostPosted: Thu Nov 15, 2007 4:55 pm
Reply with quote

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'

icon_biggrin.gif
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Thu Nov 15, 2007 5:37 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Nov 15, 2007 6:12 pm
Reply with quote

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
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Thu Nov 15, 2007 6:21 pm
Reply with quote

Hi,

Code the following code.

In IF condition, code the following line.

WS-SUB = PMFC-A-OCCURS +1

KSK
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Thu Nov 15, 2007 6:35 pm
Reply with quote

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
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Thu Nov 15, 2007 6:44 pm
Reply with quote

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
View user's profile Send private message
Deepa.m

New User


Joined: 28 Apr 2005
Posts: 99

PostPosted: Mon Nov 19, 2007 12:36 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Nov 19, 2007 1:28 pm
Reply with quote

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
View user's profile Send private message
Deepa.m

New User


Joined: 28 Apr 2005
Posts: 99

PostPosted: Mon Nov 19, 2007 2:32 pm
Reply with quote

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
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Tue Nov 20, 2007 10:37 am
Reply with quote

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
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
This topic is locked: you cannot edit posts or make replies. REXX - Do - Not able to LOOP CLIST & REXX 10
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts REXX - Dataset checking in a do forev... CLIST & REXX 6
No new posts Need to read duplicate rows from tabl... DB2 3
This topic is locked: you cannot edit posts or make replies. Cobol db2 program going in loop COBOL Programming 4
Search our Forums:

Back to Top