Issues with string comparison

Posted by Ken Ward on 12-Sep-2018 20:19

I was troubleshooting an issue with our ERP system's report output when i came across a strange behavior of the ABL code.

  DEFINE PUBLIC PROPERTY TEXT AS CHARACTER NO-UNDO  
    SET (INPUT ip-text AS CHAR):

      IF ip-text = ?  THEN RETURN.
      IF ip-text = "" THEN RETURN.
   
.
.
.
END SET.

This does not work as expected when the passed parameter contains only spaces.

In short it appears that in ABL, "       " EQ "" is TRUE.

I know that in many cases this will not matter, but due to the nature of this module, it matters a great deal.

I had to change that check to IF LENGTH(ip-text) = 0 THEN RETURN, so I have resolved the issue for now, but I didn't know that the string comparison worked like that.

Posted by Patrick Tingen on 13-Sep-2018 01:30

Nine times out of ten you benefit from this behavior, especially when you are looking for data in your database that accidentally has a trailing space. It would be very bad for performance if you had to put TRIM statements in all of your queries that involve character fields. So yes, every now and then this gives problems, like in your case, but generally speaking I think you should be glad with this functionality. It's not a bug; it's really a feature!

All Replies

Posted by Rick Terrell on 12-Sep-2018 20:36

Documented behavior.  

Rick Terrell 
Principle Consultant, Professional Services 
Progress

Sent from my iPhone

Posted by marian.edu on 12-Sep-2018 23:54

You can also use COMPARE function for that, but then who does remember all those 4GL functions :)


Marian Edu

Acorn IT 
+40 740 036 212

Posted by Patrick Tingen on 13-Sep-2018 01:30

Nine times out of ten you benefit from this behavior, especially when you are looking for data in your database that accidentally has a trailing space. It would be very bad for performance if you had to put TRIM statements in all of your queries that involve character fields. So yes, every now and then this gives problems, like in your case, but generally speaking I think you should be glad with this functionality. It's not a bug; it's really a feature!

Posted by Torben on 13-Sep-2018 03:48

IF LENGTH(ip-text) = 0 THEN RETURN.

/Torben

Posted by Ken Ward on 13-Sep-2018 08:26

I'd wager that since I was unaware of this behavior, there are probably tons of unnecessary TRIM() calls in our code.

This thread is closed