Start of change

TRIM

The TRIM function returns a character string that contains the characters in the argument with leading spaces, trailing spaces, or both, removed.

The function type depends on the argument type as follows:
Table 1. TRIM function types depending on the argument types
Argument type Function type
Alphabetic Alphanumeric
Alphanumeric Alphanumeric
National National

Format

Read syntax diagramSkip visual syntax diagramFUNCTION TRIM(argument-1 LEADINGTRAILING )
argument-1
Must be a data item of class alphabetic, alphanumeric, or national.
The returned value is:
  • If LEADING is specified, the returned value is a character string that consists of the characters in argument-1 beginning from the leftmost character position that does not contain a space character through the rightmost character position.
  • If TRAILING is specified, the returned value is a character string that consists of the characters in argument-1 beginning from the leftmost character position through the rightmost character position that does not contain a space character.
  • If neither LEADING nor TRAILING is specified, the returned value is a character string that consists of the characters in argument-1 beginning from the leftmost character position that does not contain a space character through the rightmost character position that does not contain a space character.
  • If argument-1 contains all spaces or argument-1 is of length zero, the returned value is of length zero.

Examples

  • FUNCTION TRIM(" Hello, world! ", LEADING) returns "Hello, world! "
  • FUNCTION TRIM(" Hello, world! ", TRAILING) returns " Hello, world!"
  • FUNCTION TRIM(" Hello, world! ") returns "Hello, world!"
  • FUNCTION TRIM(" ") returns ""
  • FUNCTION TRIM("") returns ""
End of change