Natural for Mainframes Version 8.2.5 for Mainframes
 —  System Functions  —

*TRIM - Remove Leading and/or Trailing Blanks

*TRIM (operand

,

LEADING

)
TRAILING

Format/length: same as operand (A, U or B)/DYNAMIC.

This document covers the following topics:


Function

The Natural system function *TRIM removes all leading and/or trailing blanks from an alphanumeric or a binary string. The content of the operand is not modified. When using a dynamic variable as operand, the length of this variable is adapted according to the result.

The *TRIM system function may be specified as an operand in any position of a statement wherever an operand of format A, U or B is allowed.

Top of page

Restrictions

When using the system function *TRIM, the following restrictions apply:

Top of page

Syntax Description

Operand Definition Table:

Operand Possible Structure Possible Formats Referencing Permitted Dynamic Definition
operand C S A     A U B                     yes no

Syntax Element Description:

Syntax Element Description
*TRIM(operand, LEADING)
Remove Leading Blanks

When the keyword LEADING is used as a second argument, all leading blanks are removed from the string contained in operand.

*TRIM(operand, TRAILING)
Remove Trailing Blanks

When the keyword TRAILING is used as a second argument, all trailing blanks are removed from the string contained in operand.

*TRIM(operand)
Remove Both Leading and Trailing Blanks

When no keyword is used as a second argument, both the leading and the trailing blanks are removed from the string contained in operand.

Top of page

Examples

The following examples are provided below:

Example 1 - Using an Alphanumeric Argument

DEFINE DATA LOCAL
/*******************************
/* STATIC VARIABLE DEFINITIONS
/*******************************
1 #SRC  (A15) INIT <'  ab  CD  '>
1 #DEST (A15)

/* FOR PRINT OUT WITH DELIMITERS
1 #SRC-PRN  (A20)
1 #DEST-PRN (A20)

/*******************************
/* DYNAMIC VARIABLE DEFINITIONS
/*******************************
1 #DYN-SRC (A)DYNAMIC INIT <'  ab  CD  '>
1 #DYN-DEST (A)DYNAMIC

/* FOR PRINT OUT WITH DELIMITERS
1 #DYN-SRC-PRN  (A)DYNAMIC
1 #DYN-DEST-PRN (A)DYNAMIC

END-DEFINE

PRINT 'static variable definition:'
PRINT '---------------------------'
COMPRESS FULL ':' #SRC ':' TO #SRC-PRN LEAVING NO SPACE
PRINT ' '
PRINT ' 123456789012345      123456789012345'

MOVE *TRIM(#SRC, LEADING) TO #DEST
COMPRESS FULL ':' #DEST ':' TO #DEST-PRN LEAVING NO SPACE
DISPLAY #SRC-PRN #DEST-PRN '*TRIM(#SRC, LEADING)'

MOVE *TRIM(#SRC, TRAILING) TO #DEST
COMPRESS FULL ':' #DEST ':' TO #DEST-PRN LEAVING NO SPACE
DISPLAY #SRC-PRN #DEST-PRN '*TRIM(#SRC, TRAILING)'

MOVE *TRIM(#SRC) TO #DEST
COMPRESS FULL ':' #DEST ':' TO #DEST-PRN LEAVING NO SPACE
DISPLAY #SRC-PRN #DEST-PRN '*TRIM(#SRC)'

PRINT ' '
PRINT 'dynamic variable definition:'
PRINT '----------------------------'
COMPRESS FULL ':' #DYN-SRC ':' TO #DYN-SRC-PRN LEAVING NO SPACE
PRINT ' '
PRINT ' 1234567890           12345678'

MOVE *TRIM(#DYN-SRC, LEADING) TO #DYN-DEST
COMPRESS FULL ':' #DYN-DEST ':' TO #DYN-DEST-PRN LEAVING NO SPACE
DISPLAY (AL=20) #DYN-SRC-PRN #DYN-DEST-PRN '*TRIM(#SRC, LEADING)'

MOVE *TRIM(#DYN-SRC, TRAILING) TO #DYN-DEST
COMPRESS FULL ':' #DYN-DEST ':' TO #DYN-DEST-PRN LEAVING NO SPACE
DISPLAY (AL=20) #DYN-SRC-PRN #DYN-DEST-PRN '*TRIM(#SRC, TRAILING)'

MOVE *TRIM(#DYN-SRC) TO #DYN-DEST
COMPRESS FULL ':' #DYN-DEST ':' TO #DYN-DEST-PRN LEAVING NO SPACE
DISPLAY (AL=20) #DYN-SRC-PRN #DYN-DEST-PRN '*TRIM(#SRC)'

PRINT ' '
PRINT '":" := delimiter character to show the start and ending of a string!'
END

Output of Example 1:

#SRC-PRN             #DEST-PRN
-------------------- -----------------------

static variable definition:
----------------------------

 123456789012345         123456789012345
:  ab  CD       :       :ab  CD         :     *TRIM(#SRC, LEADING)
:  ab  CD       :       :  ab  CD       :     *TRIM(#SRC, TRAILING)
:  ab  CD       :       :ab  CD         :     *TRIM(#SRC)

dynamic variable definition:
----------------------------

 1234567890              12345678
:  ab  CD  :            :ab  CD  :            *TRIM(#SRC, LEADING)
:  ab  CD  :            :  ab  CD:            *TRIM(#SRC, TRAILING)
:  ab  CD  :            :ab  CD:              *TRIM(#SRC)

':' := delimiter character to show the start and ending of a string!

Top of page