Previous Topic: Character-oriented FunctionsNext Topic: The POSITION Function


The TRIM Function

The TRIM function removes repeated occurrences of a specific character from the beginning and/or end of another character string. The return value of the TRIM function is the resulting character string. This function is very similar to the REXX STRIP function. The syntax for the TRIM function is:

TRIM(LEADING|TRAILING|BOTH 'trimchar' FROM 'target string'/colname)

The default value for the first keyword is BOTH and the default value for the trim character is a blank. The statement TRIM('target string'/colname) is equivalent to trimming leading and trailing blanks from a string value. The FROM keyword is only required when the trim character is specified.

In this example the character '2' is removed from the end of the USER_ID column value:

“SELECT APPL_ID  TRIM(TRAILING  '2' FROM USER_ID)
FROM APPLICATIONS WHERE NAME = 'APPL10'”

The REXX variable returned for the TRIM function is:

TRIM_USER_ID.1=TSOUSR