MainframeSupports
tip week 7/2011:
In my time as a mainframe programmer I have seen a lot of procedures and functions in PL/I
which are able to remove trailing blanks. Even though PL/I has a large selection of built-in
functions the IBM team behind PL/I did not provide us with a strip function. Luckily this has
changed in the newest version of PL/I called Enterprise PL/I. Now we can all remove our home
grown strip functions and use the authorised version.
As usual the PL/I lab has decided to be different. Removal of trailing blanks is performed
by a function called STRIP in REXX and DB2 (DB2 has a RTRIM function to remove trailing
characters, but it is just a specialized version of STRIP), but in PL/I it is called
TRIM
. The parameters for TRIM are of course also different and when you read the description of
the parameters you end up being quite confused. I hope this overview is more clear:
- The first parameter is the character string you want to remove leading or trailing
characters from. It does not matter whether this parameter is a CHAR or a CHAR VARYING.
- The second parameter specifies the characters you want to remove from the beginning
of the character string in the first parameter. If you specify '' (an empty string) no
leading characters are removed. If you for instance specify 'ab' then all occurences of
a or b will be removed until a character different from a and b turns up.
In other words:
TRIM('aaababbbbccc', 'ab') returns 'ccc'.
- The third parameter specifies the characters you want to remove from the end
of the character string in the first parameter. If you specify '' (an empty string) no
trailing characters are removed. If you for instance specify 'yz' then all occurences of
y or z will be removed until a character different from y and z turns up.
In other words:
TRIM('aaababbbbcccdddzzzzzyyyzzzyyy', 'ab', 'yz') returns 'cccddd'.
The conclusion is that trailing blanks will be removed using the following TRIM:
mynonstrippedvariable = 'some nonsense ';
put skip list('theStrippedResult=<' !! TRIM(mynonstrippedvariable, '', ' ') !! '>');
This example will print: theStrippedResult=<some nonsense>. By the way the result of
TRIM is always a CHAR VARYING.
Previous tip in english
Sidste danske tip
Tip list