MainframeSupports
tip week 14/2007:

MainframeSupport wishes you a happy easter. The next tip will be published the 16th of april.

MainframeSupport ønsker dig en god påske. Ugens tip udkommer næste gang den 16. april.

REXX is a fairly popular programming language on the mainframe platform, but what do we really know about this versatile language. Some of us (particularly me) has been very surprised by the way REXX compares. The surprise comes from the fact that REXX does not have any data types. Variables are not declared as in almost all other programming languages. The following example illustrates the problem:

/* REXX */
A = '2 '
B = ' 2'
IF A = B
THEN
  SAY 'A = B'
ELSE
  SAY 'A <> B'
IF A == B
THEN
  SAY 'A == B'
ELSE
  SAY 'A /== B'

What will this tiny REXX program do? In other languages the program would not work because it is filled with syntax errors. PL/1 and COBOL cannot handle the comparison A == B, while C, C++ and Java rejects the comparison A = B. In REXX both comparisons are valid and the surprising result is that A = B is true while A == B is false.

When you use A = B REXX will evaluate the contens of the two variables before the comparison. If they both evaluates to something numeric (as it is the case here) then REXX will perform a numeric comparison. If your background in programming languages on the mainframe is PL/1 or COBOL this result is not very logical. I have spent many hours tracing problems like this in REXX until I realised what the problem was all about.

To solve such a problem it comes in handy that REXX offers A == B, which means that REXX will compare A and B one byte at a time without any prior evaluation. A side effect of A == B is that two strings having different lengths, like 'ABC' and 'ABC  ' are not equal. REXX has other socalled strict comparison operators like << and >> which means one byte at a time comparison and not much bigger or less than as in math. Nice to know is that the opposite of == is /==.

Previous tip in english        Sidste danske tip        Tip list