MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cobol IF statement Question

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
tempuser
Beginner


Joined: 05 Oct 2005
Posts: 28
Topics: 20
Location: INDORE

PostPosted: Fri Oct 07, 2005 10:52 am    Post subject: Cobol IF statement Question Reply with quote

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


Joined: 09 May 2003
Posts: 131
Topics: 64

PostPosted: Fri Oct 07, 2005 10:58 am    Post subject: Reply with quote

The statement is true only if the value is other than 1 and 2 i.e zero in your example
Back to top
View user's profile Send private message
tempuser
Beginner


Joined: 05 Oct 2005
Posts: 28
Topics: 20
Location: INDORE

PostPosted: Fri Oct 07, 2005 11:24 am    Post subject: Reply with quote

Thnak you Vijay!!
Back to top
View user's profile Send private message
neilxt
Beginner


Joined: 01 Mar 2004
Posts: 23
Topics: 1

PostPosted: Tue Sep 19, 2006 4:39 pm    Post subject: Re: Cobol IF statement Question Reply with quote

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
View user's profile Send private message Send e-mail
Arunprasad.K
Beginner


Joined: 18 Jan 2006
Posts: 18
Topics: 5
Location: Chennai, India

PostPosted: Wed Sep 20, 2006 7:55 am    Post subject: Difference between 88 level and 01 level Reply with quote

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
View user's profile Send private message Send e-mail
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Wed Sep 20, 2006 8:37 am    Post subject: Reply with quote

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
Code:

ALL ARE SAME

_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Wed Sep 20, 2006 8:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Arunprasad.K
Beginner


Joined: 18 Jan 2006
Posts: 18
Topics: 5
Location: Chennai, India

PostPosted: Thu Sep 21, 2006 8:46 am    Post subject: Reply with quote

Thank you shekar123.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group