Page 1 of 1

How to compare with IF condition

PostPosted: Thu Aug 09, 2012 1:43 pm
by nareshv_99
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?

Re: How to compare with IF condition

PostPosted: Thu Aug 09, 2012 2:01 pm
by BillyBoyo
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

Re: How to compare with IF condition

PostPosted: Thu Aug 09, 2012 7:42 pm
by dick scherrer
Hello,

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

How did you decide to code this way?