$TRIM is an alphanumeric function that returns the string resulting from the removal of leading or trailing characters from an alphanumeric expression.
This function has the following format:
[, RIGHT= {'a' }]
$TRIM(alpha‑expression [, LEFT= {a‑field }].)
Defines an alphanumeric expression.
The RIGHT= clause trims from the right any trailing characters with the specified value. The LEFT= clause trims from the left any leading characters with the specified value. You can specify either clause or both. If neither clause is specified, the default is RIGHT=' ' (trim trailing blanks).
Specifies an alphanumeric literal indicating the character to trim.
Specifies an one‑byte alphanumeric field containing the character to trim.
Examples
The following example trims leading and trailing blanks from a dataview field and processes the resulting field if it is less than or equal to eight characters long.
SET VAR‑FLD = $TRIM(DVW.FIELD,LEFT=' ',RIGHT=' ')
IF $LENGTH(VAR‑FLD) LE 8
DO MOVE‑ROUTINE
ENDIF
Moving the expression $TRIM returns to a field can produce different results for fixed length fields and variable length fields. For example, the fields used are defined as follows:
Field FIX‑FLD: Type X, length 10, initial value 'ABC Field VAR‑FLD: Type V, length 10, initial value 'ABC'
The following statement sets FIX‑FLD to 'ABCbbbbbbb', where b is a blank.
SET FIX‑FLD = $TRIM(FIX‑FLD, RIGHT=' ')
The function trims the trailing blanks from the original expression, but because the target field is fixed length, ten characters long, the trailing blanks are added back when the string is moved.
On the other hand, the following statement sets VAR‑FLD to ABC because you can trim the variable‑length target field to three characters.
SET VAR‑FLD = $TRIM(FIX‑FLD,RIGHT=' ')
See the $PAD function.
|
Copyright © 2015 CA Technologies.
All rights reserved.
|
|