IBM Extension

TRIM

The TRIM function returns the given string with any leading and trailing blanks removed, or the given string with any leading and trailing specified characters removed.

The type of the function is alphanumeric, DBCS or national depending on the class of its argument.

Format:

Read syntax diagramSkip visual syntax diagramFUNCTION TRIM(argument-1argument-2)
argument-1
Must be a nonnumeric literal, or data item of class alphabetic, alphanumeric, DBCS or national. Argument-1 identifies the source string for the trim.
argument-2
If specified, it must be a nonnumeric literal, or data item of the same class as argument-1. It specifies the characters to trim off. If not specified, the trim character defaults to blank.

If argument-2 is not specified, the returned value is an alphanumeric, DBCS or national character string consisting of the characters of argument-1 with any leading and trailing blanks removed. The blank character is a one byte space character (' ' or X'40') when argument-1 is of class alphanumeric, or one double-byte space (X'4040') when argument-1 is of class DBCS, or one national space (X'0020' or X'3000') when argument-1 is of class national.

If argument-2 is specified, all characters in argument-2 will be trimmed off from both ends of the string. The returned value is an alphanumeric, DBCS or national character string consisting of the characters of argument-1 with any leading and trailing characters specified in argument-2 removed.

The length of the returned string depends on the content and the class of argument-1. It is the length of the returned string in number of character positions. If argument-1 is a DBCS or national data item, then the length is in DBCS or national character positions.

End of IBM Extension