How to trim a variable in CLLE??
Thanks Arpit
No standard function TRIM is available in CLLE. However,
Since all variables in CL are fixed length, there is no logical requirement to trim per se.
To join two value without intervening spaces, use the |<
operator, and to include a single space use |>
.
To find the length in characters excluding trailing spaces, you need to do a good ol' fashioned walk backwards on the value using %SST(&VAL &POS 1) to test each character position for a space. Something like:
DCL &LEN *DEC (15 0)
DCL &VAL *CHAR 50 VALUE('Some test data')
DCL &CHR15 *CHAR 15
CHGVAR &LEN 50
LOOP: IF (&LEN > 1 & %SST(&VAL &LEN 1)==' ') (DO)
CHGVAR &LEN VALUE(&LEN - 1)
GOTO LOOP
ENDDO
CHGVAR &CHR15 &LEN
SNDPGMMSG ('The length is' |> &CHR15) /* Can't concat decimal values */
To simply null-terminate a value to, for example, make a call to a C function:
DCL &VAL *CHAR 50 VALUE('Some test text')
DCL &VALNUL *CHAR 51 /* +1 for the null */
DCL &NULL *CHAR 1 VALUE(X'00')
CHGVAR &VALNUL VALUE(&VAL |< &NULL)