View previous topic :: View next topic |
Author |
Message |
tempuser Beginner
Joined: 05 Oct 2005 Posts: 28 Topics: 20 Location: INDORE
|
Posted: Fri Oct 07, 2005 10:52 am Post subject: Cobol IF statement Question |
|
|
Hi,
I saw a cobol program code like this.
IF WS-VALUE IS NOT EQUAL TO ('1' AND '2')
How the program will behave
1) IF WS-VALUE is 1 ?
2) IF WS-VALUE is 2 ?
3) IF WS-VALUE is 0 ?
the declaration of WS-VALUE is X(1).
Thanks |
|
Back to top |
|
 |
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Fri Oct 07, 2005 10:58 am Post subject: |
|
|
The statement is true only if the value is other than 1 and 2 i.e zero in your example |
|
Back to top |
|
 |
tempuser Beginner
Joined: 05 Oct 2005 Posts: 28 Topics: 20 Location: INDORE
|
Posted: Fri Oct 07, 2005 11:24 am Post subject: |
|
|
Thnak you Vijay!! |
|
Back to top |
|
 |
neilxt Beginner
Joined: 01 Mar 2004 Posts: 23 Topics: 1
|
Posted: Tue Sep 19, 2006 4:39 pm Post subject: Re: Cobol IF statement Question |
|
|
tempuser wrote: | Hi,
I saw a cobol program code like this.
IF WS-VALUE IS NOT EQUAL TO ('1' AND '2')
How the program will behave
1) IF WS-VALUE is 1 ?
2) IF WS-VALUE is 2 ?
3) IF WS-VALUE is 0 ?
the declaration of WS-VALUE is X(1).
Thanks |
A lot of people have trouble with this because it's not the way English usually works. If in doubt, expand out the "assumed" parts of the statement.
So ...
IF WS-VALUE IS NOT EQUAL TO ('1' AND '2')
is treated by the compiler as ...
IF WS-VALUE IS NOT EQUAL TO '1' AND
WS-VALUE IS NOT EQUAL TO '2'
Note that you can use ("1" OR "2") by moving the NOT outside the "assumed" part. So...
IF NOT (WS-VALUE IS EQUAL TO '1' OR '2')
translates as ...
IF NOT (WS-VALUE IS EQUAL TO '1' OR
WS-VALUE IS EQUAL TO '2') |
|
Back to top |
|
 |
Arunprasad.K Beginner

Joined: 18 Jan 2006 Posts: 18 Topics: 5 Location: Chennai, India
|
Posted: Wed Sep 20, 2006 7:55 am Post subject: Difference between 88 level and 01 level |
|
|
Hi all,
Here I have an question. Can we use a 01 level variable like this?
Code:-
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-A PIC 9(1) VALUE 3.
01 WS-B PIC 9(1) VALUE 3.
01 WS-C PIC 9(1) VALUE 3.
PROCEDURE DIVISION.
IF WS-A = WS-B AND WS-C
DISPLAY 'ALL ARE SAME'
ELSE
DISPLAY 'NOT SAME'
END-IF.
STOP RUN.
Output:-
"ALL ARE SAME "
It is working vise versa. How it is working? Please explain. |
|
Back to top |
|
 |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Wed Sep 20, 2006 8:37 am Post subject: |
|
|
Arunprasad.K,
Yes you can use 01 variable declarations as u have shown.You can also use EVALUATE TRUE ALSO TRUE Syntax to check multiple IF conditions:
Code: |
WORKING-STORAGE SECTION.
01 WS-A PIC 9(1) VALUE 3.
01 WS-B PIC 9(1) VALUE 3.
01 WS-C PIC 9(1) VALUE 3.
PROCEDURE DIVISION.
EVALUATE TRUE ALSO TRUE
WHEN WS-A = WS-B ALSO WS-A = WS-C
DISPLAY 'ALL ARE SAME'
WHEN OTHER
DISPLAY 'NOT SAME'
END-EVALUATE.
STOP RUN.
|
OUTPUT
_________________ Shekar
Grow Technically |
|
Back to top |
|
 |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Wed Sep 20, 2006 8:46 am Post subject: |
|
|
Arunprasad
For all the variables having values 3 ,It is checking for a match for conditions IF WS-A = WS-B and IF WS-A = WS-C
Change WS-C to 4 and run , you will see the condition is not met and NOT SAME will be displayed. _________________ Shekar
Grow Technically |
|
Back to top |
|
 |
Arunprasad.K Beginner

Joined: 18 Jan 2006 Posts: 18 Topics: 5 Location: Chennai, India
|
Posted: Thu Sep 21, 2006 8:46 am Post subject: |
|
|
Thank you shekar123. |
|
Back to top |
|
 |
|
|