How to compare with IF condition



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to compare with IF condition

Postby nareshv_99 » Thu Aug 09, 2012 1:43 pm

HI All,
I have below requirement to do
I have to compare IN-VAR1 with W-VAR2(which can have multiple values).

Code Snippet:

WORKING-STORAGE SECTION.
01 WS-WORK-AREAS.

05 IN-VAR1 PIC X(01) VALUE 'Z'.

05 W-VAR1 PIC X(01) VALUE 'A',
'B',
'C',
'D'.

In

PROCEDURE DIVISION.
IF IN-VAR1 IS NOT EQUAL TO W-VAR1 THEN
DISPLAY 'IN-VAR1 IS NOT IN W-VAR1'
ELSE
DISPLAY 'IN-VAR1 IS IN W-VAR1'
END-IF.

I wrote the above cobol program but it is giving me below compilation error.

IGYDS1089-S "'B'" was invalid. Scanning was resumed at the next area "A" item
clause.

could anyone suggest me how to solve this?
nareshv_99
 
Posts: 17
Joined: Sat Feb 18, 2012 3:13 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to compare with IF condition

Postby BillyBoyo » Thu Aug 09, 2012 2:01 pm

A field can only have one VALUE.

An 88 condition-name can have multiple values.

01  W-FIELD-I-WANT-TO-TEST-FOR-SPECIFIC-VALUE PIC X.
    88  W-FIELD-VALUE-IS-ONE-OF-THE-ONES-I-WANT VALUE 'A' 'B' 'C' 'D'.
...

IF W-FIELD-VALUE-IS-ONE-OF-THE-ONES-I-WANT
    DISPLAY ''W-FIELD-I-WANT-TO-TEST-FOR-SPECIFIC-VALUE is what I want"
ELSE
   DISPLAY ''W-FIELD-I-WANT-TO-TEST-FOR-SPECIFIC-VALUE is not what I want"
END-IF
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to compare with IF condition

Postby dick scherrer » Thu Aug 09, 2012 7:42 pm

Hello,

You cannot just "make up" syntax to meet what you want to do. . .

How did you decide to code this way?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post