(Disclaimer: I'm not a COBOL user)
After some quick searching online, I found the OpenCOBOL reference manual ( http://opencobol.add1tocobol.com/OpenCOBOL%20Programmers%20Guide.pdf ) which describes the IS=
relation operator (and its synonyms) working with string types (6.1.4.2.5.) to wit:
When comparing strings, the comparison is made based upon the program’s collating sequence (see section 4.1.2). When the two string arguments are of unequal length, the shorter is assumed to be padded (on the right) with a sufficient number of SPACES as to make the two strings of equal length. String comparisons take place on a corresponding character-by-character basis until an unequal pair of characters is found. At that point, the relative position of where each character in the pair falls in the collating sequence will determine which is greater (or less) than the other.
COBOL defines IS=
, IS EQUAL TO
, and EQUALS
as equivalent operators, so you'll want something like this:
IF name1 EQUALS name2
DISPLAY "Names are the same"
ELSE
DISPLAY "Names are not the same"
As the documentation states, your program's collation settings define how string comparison is performed, which means that potentially "Peter
", "PETER
", and "Péter
" might be treated as equivalents.
The note about different lengths is interesting, the implicit right-padding means that these two strings are considered equal: ("Foo
" and "Foo__
") but not ("Foo
" and "__Foo
").