| IBM MAINFRAME HELP & SUPPORT FORUMS Technical Forums for IBM Mainframe Applications like COBOL, JCL, CICS, DB2, FileAid, DFSORT, Endevor, Xpediter, CoolGen, CA-7&11, AbendAid, IMS, IDMS, PL/I, MqSeries, SyncSort, Assembler, ChangeMan, Easytrieve, InterTest, REXX, CLIST etc...
|
| View previous topic :: View next topic |
| Author |
Message |
ashishsawhney
Joined: 21 Feb 2005
Posts: 3
|
| Posted: Mon Feb 21, 2005 3:12 pm Post subject: Difference between ELSE IF and ELSEIF |
|
|
What is the difference between these two pieces of code:--
CODE A
Code:
IF CASE = 1
PERFORM X
ELSE
IF CASE = 2
PERFORM Y
ELSE
IF CASE = 3
PERFORM Z
ELSE
PERFORM DEFAULT-ROUTINE
END-IF
END-IF
END-IF
CODE B
Code:
IF CASE = 1
PERFORM X
ELSE IF CASE = 2
PERFORM Y
ELSE IF CASE = 3
PERFORM Z
ELSE
PERFORM DEFAULT-ROUTINE
END-IF
as you can see there are 3 END-IF in CODE A and only one END-IF in CODE B ... so my question is how does the COBOL compiler know about it? |
|
| Back to top |
|
sunnyk
Joined: 20 Oct 2004
Posts: 59
|
| Posted: Mon Feb 21, 2005 5:18 pm Post subject: |
|
|
Hi,
In any case( code A or CODE B) only one condition will be true at a time.Right!!.So it will look for an END-IF of the satisfied IF condition which IS TRUE.Like if CASE=1,it will "PERFORM X" and come out of the loop looking for END-IF.
So even if you give one END-IF instead of three,there won`t be any problem as ur CODE B suggests.
ANY UPDATES WELCOME.
Thanx
Sunny |
|
| Back to top |
|
ashishsawhney
Joined: 21 Feb 2005
Posts: 3
|
| Posted: Mon Feb 21, 2005 5:47 pm Post subject: |
|
|
but then what is the need of coding three end-if if the problem is geeting solve by coding only one....
secondly, i m interested in finding...how do a cobol compiler look in this two very codes....seperately?????
well thanks for ur quick reply |
|
| Back to top |
|
mmwife
Joined: 30 May 2003
Posts: 1508
|
| Posted: Mon Feb 21, 2005 7:56 pm Post subject: |
|
|
I don't have access to a CPU but I'd say that code B won't compile unless perhaps it's terminated by a period.
Putting the IF on the same line as the ELSE doesn't change the code presented in code A. With the exception of the missing END-IFs they are identical. COBOL "squeezes" out the extra spaces during interpretation. |
|
| Back to top |
|
sunnyk
Joined: 20 Oct 2004
Posts: 59
|
| Posted: Mon Feb 21, 2005 9:20 pm Post subject: |
|
|
Hi Jack,
Thats not the case.Even without a period,it will compile successfully.I tried that.
So any suggestions please add.
Thanks
sunny |
|
| Back to top |
|
ramesh_chirumamillait
Joined: 19 Feb 2005
Posts: 1
Location: nill
|
| Posted: Mon Feb 21, 2005 9:21 pm Post subject: regaring that if construct |
|
|
here the answer is correct but eventhough the compiler give the error.because for every if construct corresponding end-if has to be there.
so i think it will be error .compulsary there will be three end-ifs has to be there.....
ramesh.ch |
|
| Back to top |
|
sunnyk
Joined: 20 Oct 2004
Posts: 59
|
| Posted: Mon Feb 21, 2005 11:01 pm Post subject: |
|
|
| No dear...try that out on your own.PLEASE.It will work fine with one END-IF also anf with no period after END-IF too. |
|
| Back to top |
|
muthukumarapandian
Joined: 08 Oct 2004
Posts: 44
Location: chennai, india
|
| Posted: Sun Feb 27, 2005 5:16 pm Post subject: |
|
|
Hi,
it will work well one scope terminator is enough for this program. |
|
| Back to top |
|
madhusudhana
Joined: 04 Mar 2005
Posts: 3
Location: bangalore
|
| Posted: Mon Mar 07, 2005 4:42 pm Post subject: HI ashishsawhney |
|
|
| if your are using tyree IF statements there is no need to give three END-IF statements one is enough. and at final you give PERIOD. YOU WON;T get any compilation error. try this. |
|
| Back to top |
|
Arun Joseph
Joined: 30 Mar 2005
Posts: 13
Location: India
|
| Posted: Wed Mar 30, 2005 9:14 pm Post subject: |
|
|
| I think the requerement of a period as scope terminator depends on the COBOL version. Like VS-Cobol, OS/370 and OS/390. So try it depending on the COBOL version |
|
| Back to top |
|
| |