OPS/REXX IF statement compare results shows TRUE when strings differ
search cancel

OPS/REXX IF statement compare results shows TRUE when strings differ

book

Article ID: 396882

calendar_today

Updated On:

Products

OPS/MVS Event Management & Automation

Issue/Introduction

Having the 2 strings below:

string1 = '00'    - 2 consecutive zeroes

string2 = ' 0'     - 1 space and 1 zero

The following "if" statement is resulting true when the strings are clearly different:

if string1 = string2 then say "True"

 

Cause

This is standard REXX behavior. When REXX compares 2 numbers with the equal "=" operator leading zeroes and spaces are ignored so "00" will be considered the same as " 0". This behavior applies to any strings that can be converted to numeric values.

Resolution

To make REXX compare the values of the 2 variables as strings, you should use the "strictly equal" operator "==" instead of the "equal" operator "=". For example:

if string1 == string2 then say "True"

Additional Information

See a list of the REXX operators that includes the "strict" comparison operators:

     =     EQUAL                         ==   STRICTLY EQUAL                    
     >     GREATER THAN                  >>   STRICTLY GREATER THAN             
     <     LESS THAN                     <<   STRICTLY LESS THAN                
     ><    NOT EQUAL                     >>=  STRICTLY GREATER THAN OR EQUAL TO 
     >=    GREATER THAN OR EQUAL TO      <<=  STRICTLY LESS THAN OR EQUAL TO    
     <=    LESS THAN OR EQUAL TO