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

Is END-IF is mandetory in IF statment?


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

New User


Joined: 14 Sep 2005
Posts: 54
Location: Chennai

PostPosted: Tue Mar 09, 2010 8:35 pm
Reply with quote

Hi All,
Is END-IF is mandetory in IF statment?
I did try to compile the program with out END-IF, its compiled successfully.
Just I want to know how it will be execute it?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Mar 09, 2010 8:36 pm
Reply with quote

What's wrong with trying it out yourself as you have already compiled the program.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Mar 09, 2010 9:08 pm
Reply with quote

There is a link to manuals at the top of this page. If you click on it, find the COBOL Language Reference manual, and read you can find out everything you want to know about the IF statement.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Tue Mar 09, 2010 9:28 pm
Reply with quote

sashi wrote:
Is END-IF is mandetory in IF statment?
No....
Quote:
Just I want to know how it will be execute it?
It depends on where the period is....

Delimited scope statements
In general, a DELIMITED SCOPE statement uses an explicit scope terminator to turn a conditional statement into an imperative statement. The resulting imperative statement can then be nested. Explicit scope terminators can also be used to terminate the scope of an imperative statement. Explicit scope terminators are provided for all COBOL statements that can have conditional phrases.
Unless explicitly specified otherwise, a delimited scope statement can be specified wherever an imperative statement is allowed by the rules of the language.


The scope of an IF statement can be terminated by any of the following:
An END-IF phrase at the same level of nesting
A separator period
If nested, by an ELSE phrase associated with an IF statement at a higher level of nesting


ps. are you GMs just trying to boost your post count? icon_rolleyes.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Mar 09, 2010 9:37 pm
Reply with quote

CICS Guy wrote:
ps. are you GMs just trying to boost your post count? icon_rolleyes.gif
Nah, just trying to invoke a sense of adventure in the OP by trying to get him/her to actually try something before posting.

Sado necrophillia equine if you ask me icon_rolleyes.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Mar 09, 2010 9:38 pm
Reply with quote

No, I'm trying to encourage independent learning and manual reading. But it goes ever so slowly ....
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Tue Mar 09, 2010 9:48 pm
Reply with quote

expat wrote:
just trying to invoke a sense of adventure in the OP by trying to get him/her to actually try something before posting.
Robert Sample wrote:
No, I'm trying to encourage independent learning and manual reading. But it goes ever so slowly ....
I've personally (speaking for myself) noticed that a helping hand (or in this case a url) aids in the learning process....

BTW,
expat wrote:
Sado necrophillia equine if you ask me :roll
Sado(?) a dead horse?....I did flunk Latin more times than I passed it...grin....
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Mar 10, 2010 10:24 am
Reply with quote

Robert Sample wrote:
No, I'm trying to encourage independent learning and manual reading. But it goes ever so slowly ....
My own attempts at behavior modification have had very little success. icon_sad.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: Wed Mar 10, 2010 10:36 am
Reply with quote

I believe we have had more success than is shown. . .

Just look at how many people view these discussions. . .

Many take away info that is never recorded within our forum.

The more we show the way to an answer (rather than only an answer) the more we influence those who will learn.

imho,

d
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Mar 10, 2010 2:45 pm
Reply with quote

sashi wrote:
Is END-IF is mandetory in IF statment?
I did try to compile the program with out END-IF, its compiled successfully.
Just I want to know how it will be execute it?
It's not only with "IF statement", actually, in this context, IF should not raise your eye-brows, instead "end scope terminator (".")" can be of your interest, as CICS Guy has said. (...most probably you have used the period, please show us your actual code to be sure)
Back to top
View user's profile Send private message
manikawnth

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Wed Mar 10, 2010 2:58 pm
Reply with quote

YOu got no compiler errors.
It means you have to be more careful where u placed the period.
You might have placed the period 5 to 10 statements down the line where u actually want to end and still the compiler assumes it as scope terminator (As it cant read ur mind icon_smile.gif ).
Make it a habit of placing an end-if as scope terminator (instead of period) for readability and maintainability unless you are very sure that nobody else will touch your code in future.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Mar 19, 2010 9:01 pm
Reply with quote

I know most people know this, but I just want to mention the behavior of NEXT SENTENCE : It goes to the next period !

You can't just replace periods with scope terminators if you leave next sentence.

Use of 'NEXT SENTENCE' is not allowed here.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Mar 20, 2010 12:00 am
Reply with quote

As GuyC points out, not knowing how NEXT SENTENCE works can get you in big trouble. I much prefer using CONTINUE and scope terminators.
Back to top
View user's profile Send private message
ElHachu

New User


Joined: 12 Mar 2010
Posts: 9
Location: Madrid

PostPosted: Sat Mar 20, 2010 5:36 pm
Reply with quote

I agree with Anuj Dhawan, The sentences that will be executed would be all before the period:

IF [conditions]

[sentences]

.

Or

IF [conditions]

[sentences]

ELSE

[more sentences]

.

And as Terry says, be careful with NEXT SENTENCE. Many companys do not allow using it.
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 How to use Read/Find statment.... Java & MQSeries 4
No new posts S0C7 ABEND when no arithmatic statment ABENDS & Debugging 26
No new posts SYNTAX ERROR in OUTFIL statment in my... JCL & VSAM 11
No new posts Insead of STRING STATMENT COBOL Programming 7
No new posts cobol statment starting with ON COBOL Programming 6
Search our Forums:

Back to Top