I'm really new to COBOL and I would like to ask a question. What if I have 2 PIC of characters and I would like to know if they are the same string
77 name1 PIC x(20).
77 name2 PIC x(20).
PROCEDURE DIVISION.
DISPLAY "Type the first name: " WITH NO ADVANCING
ACCEPT name1.
DISPLAY "Type the second name: " WITH NO ADVANCING
ACCEPT name2.
I tried to search on google and found the Search method. But I can't really understand it and I think it will not work on my case since I'm not using a table.
Just to build on @Dai's answer, I'm running on z/OS and every other comparison operator listed on Page 6-8 in that reference worked for me except for the EQUALS
operator as expressed in @Dai's answer.
IS EQUAL TO
IF name1 IS EQUAL TO name2
DISPLAY "Names are the same"
ELSE
DISPLAY "Names are not the same"
END-IF.
IS =
IF name1 IS = name2
DISPLAY "Names are the same"
ELSE
DISPLAY "Names are not the same"
END-IF.
EQUALS
IF name1 EQUALS name2
DISPLAY "Names are the same"
ELSE
DISPLAY "Names are not the same"
END-IF.
results in this JCL condition code 12 compile error:
IGYPS2055-S "EQUALS" was not defined as a class-name. The statement was discarded.
And to confirm @Bruce Martin's comment you can drop the IS
, which is not referenced in the table.
=
IF name1 = name2
DISPLAY "Names are the same"
ELSE
DISPLAY "Names are not the same"
END-IF.