ibm-midrangecontrol-language

How to check if variable is blank in CL?


I have this piece of code.

IF         COND(%TRIM(&BLANK_VAR) *EQ '') THEN(DO)
            CALL       PGM(MY_PROGRAM) PARM(&BLANK_VAR)
ENDDO

I would like to check if &BLANK_VAR is an empty string. However my program won't compile because of error message:

* CPD0126 30  Operand not valid or operator missing in COND.

Is this an issue with %TRIM? I tried using %LEN but it gives me lenght of the variable declared, not the actual data inside.

&BLANK_VAR is 10 characters in length. Do I have to do:

IF COND(&BLANK_VAR *EQ '          ')

Solution

  • The solution is to simply add an actual space in your two single quotes:

    IF         COND(%TRIM(&BLANK_VAR) *EQ ' ') THEN(DO)
                CALL       PGM(MY_PROGRAM) PARM(&BLANK_VAR)
    ENDDO
    

    The reason you are getting the error is that two ' right next to each other is acting as an escaped single quote. This typically allows you to embed single quotes into a literal string but in this case it looks to the compiler like you have an invalid single character string.