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

What will the exit do in cobol


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

New User


Joined: 16 Nov 2006
Posts: 43
Location: Bangalore

PostPosted: Thu Mar 22, 2007 12:05 pm
Reply with quote

What will the exit do?

Everyone says that exit will do nothing. Then what's use of that.

Suppose if use exit in Nested If loop. After encountering the exit satement the control comes out of the loop ?

Please clarify on this.
Back to top
View user's profile Send private message
vicky10001
Warnings : 1

Active User


Joined: 13 Jul 2005
Posts: 136

PostPosted: Thu Mar 22, 2007 12:35 pm
Reply with quote

The EXIT statement must be preceded by a paragraph-name and
must appear in a sentence by itself.

If an EXIT paragraph is specified as the last paragraph in a series of
performed paragraphs (i.e., PERFORM THRU), then it identifies the end
of the series of performed paragraphs. When control reaches an EXIT paragraph and such a PERFORM THRU is active, control is transferred
back to the statement following the PERFORM THRU.
When control reaches an EXIT paragraph that is not the end of a range
of paragraphs governed by an active PERFORM THRU, control passes
through the EXIT statement to the first statement of the following
paragraph.

The EXIT statement is also useful as an exit point for a single
performed paragraph, as shown below:
.
.
PERFORM 1000-CALCULATE-TOTALS THRU 1000-EXIT.
.
1000-CALCULATE-TOTALS.
ADD 1 TO TOTAL-NUMBER-EMPS.
IF EMP-SALARY LESS THAN 25000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
IF EMP-SALARY LESS THAN 50000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
IF EMP-SALARY LESS THAN 75000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
1000-EXIT. EXIT.
Back to top
View user's profile Send private message
venosol
Warnings : 1

New User


Joined: 16 Nov 2006
Posts: 43
Location: Bangalore

PostPosted: Thu Mar 22, 2007 1:01 pm
Reply with quote

vicky10001 wrote:
The EXIT statement must be preceded by a paragraph-name and
must appear in a sentence by itself.

If an EXIT paragraph is specified as the last paragraph in a series of
performed paragraphs (i.e., PERFORM THRU), then it identifies the end
of the series of performed paragraphs. When control reaches an EXIT paragraph and such a PERFORM THRU is active, control is transferred
back to the statement following the PERFORM THRU.
When control reaches an EXIT paragraph that is not the end of a range
of paragraphs governed by an active PERFORM THRU, control passes
through the EXIT statement to the first statement of the following
paragraph.

The EXIT statement is also useful as an exit point for a single
performed paragraph, as shown below:
.
.
PERFORM 1000-CALCULATE-TOTALS THRU 1000-EXIT.
.
1000-CALCULATE-TOTALS.
ADD 1 TO TOTAL-NUMBER-EMPS.
IF EMP-SALARY LESS THAN 25000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
IF EMP-SALARY LESS THAN 50000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
IF EMP-SALARY LESS THAN 75000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
1000-EXIT. EXIT.



Consider the statements.

PERFORM 100-PARA THRU 500-PARA
100-PARA.
ADD 1 TO TOTAL-NUMBER-EMPS.
120-PARA.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
520-PARA.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
450-PARA.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
500-PARA.
EXIT.

Now the control goes back to PERFORM. If we don't use the 500-PARA and we PERFORM 100-PARA THRU 450-PARA. Then also the control will go back to PERFORM after 450-PARA.

Now If I use 500-PARA AFTER 520-PARA. When control comes to exit statement it will go to 450-PARA which is a normal way.

In both the cases EXIT is not mandatory. Am I correct. Is there any other advantage.

My question is If I use in IF ELSE condition then how will be the execution. See the below example and clarify me.


IF X > 0

IF Y < 3

IF WS-COUNT = 20

EXIT

ELSE

DISPLAY ' I AM HERE'
END-IF
END-IF
END-IF
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Mar 22, 2007 3:42 pm
Reply with quote

Quote:
My question is If I use in IF ELSE condition then how will be the execution. See the below example and clarify me.


It will be trated as continue statement. icon_smile.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: Thu Mar 22, 2007 10:36 pm
Reply with quote

Hello,

Please refer to the prior replies quoting the manual. If you actually did what the quoted manual says you could not code:

Quote:
IF X > 0

IF Y < 3

IF WS-COUNT = 20

EXIT

ELSE

DISPLAY ' I AM HERE'
END-IF
END-IF
END-IF


Your "EXIT" does not follow the rules above.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Mar 23, 2007 11:22 am
Reply with quote

Dick,
It is allowed to code EXIT like the example mentioned above.
As I already stated, it will be trated as CONTINUE.
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: Fri Mar 23, 2007 7:20 pm
Reply with quote

Hello Abhijit,

I've no doubt that it may "be gotten away with" - i do not believe it should be used. As the prior post showed from the Fine Manual, the only proper way to code an EXIT is to make it the only statement in a paragraph and it really has only one good use - to terminate a "perform thru".

There are many things we can get away with that we still should not use. If, in that example, a CONTINUE makes sense, a CONTINUE should be coded, not the mis-used EXIT. Think of some night a year or 2 later when there is a problem in that program and the person called to fix the problem is not the author (indeed, the author may not even work there any more) - how much time might they waste trying to figure out why that bit of potentially mis-leading code was in the program. . .

IMHO icon_smile.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Mar 26, 2007 11:23 am
Reply with quote

I agree with you Dick on that. I never used EXIT like the example Venu gave us and will never need to. icon_smile.gif
Back to top
View user's profile Send private message
Josh_winkelstein

New User


Joined: 28 Mar 2007
Posts: 1
Location: Lansing MI USA

PostPosted: Wed Mar 28, 2007 1:48 am
Reply with quote

As previously noted, the EXIT statement is primarily or exclusively valid as a way to exit a PERFORM THRU structure.

A somewhat less obvious thing about this is that once you have reached the end of processing in the 9999-SOMETHING paragraph, you can GO TO the 9999-EXIT paragraph and still have a fully structured program. You can use this to skip any statements you know you don't have to execute if some condition is fulfilled, and thereby increase the efficiency of your code.

Unfortunately, the prohibition against the use of GO TO is often so strong that that the use of it in this situation, while valid and structured, will be denied or prohibited without any consideration.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top