The TRIM command is similar to the RPG IV %TRIMx functions. Leading
blanks may be trimmed off the left hand side of a value along with
specified characters. Trailing characters may also be trimmed off
the right side of a value. Because the command returns a 1000 byte
variable, there is no concept of trimming off trailing blanks as with
the RPG function. The length of the returned value may also be
returned.
A typical series of commands would be:
DCL &INP *CHAR LEN(25)
DCL &RTNVAL *CHAR LEN(1000)
DCL &RTNLEN *DEC LEN(5 0)
.
TRIM INPVAL(&INP) TRIMCHAR('') RTNVAL(&RTNVAL) +
RTNLEN(&RTNLEN)
The default is to trim leading blanks and any leading or trailing
characters specified in the TRIMCHAR parameter. Trimming at either
end of the value ends when a character is found that does not match
one of the TRIMCHAR characters.
If the &INP value was ' ABC& ', the RTNVAL would be 'ABC' (in 1000
bytes) with a RTNLEN of 3.
If the &INP value was ' AB&C& ', the RTNVAL would be 'AB&C' (in
1000 bytes) with a RTNLEN of 4.
If the &INP value was ' &&& ', the RTNVAL would be all blanks with a
RTNLEN of 0.
Difference with RPG %TRIMx built-in function
--------------------------------------------
The RPG IV %TRIMx function definition optionally trims off any
trailing blanks. Because the TRIM command returns a large variable,
there will be blanks (in most cases) on the right side of the return
variable.
The TRIMTYPE parameter describes the type of trimming to be
performed. With the exception of the trailing blanks function:
** TRIMTYPE(*BOTH) = %TRIM.
** TRIMTYPE(*LEFT) = %TRIML.
** TRIMTYPE(*RIGHT) = %TRIMR.
Difference with RMVCHAR TAA command
-----------------------------------
The RMVCHAR TAA command removes specified characters anywhere in a
value (removing leading blanks is the default). Using RMVCHAR
instead of TRIM as previously shown:
RMVCHAR INPVAL(&INP) RMVCHAR('') RTNVAL(&RTNVAL) +
RTNLEN(&RTNLEN)
If the &INP value was ' ABC& ', the RTNVAL would be 'ABC' (in 1000
bytes) with a RTNLEN of 3 (same result as with TRIM).
If the &INP value was ' AB&C& ', the RTNVAL would be 'ABC' (in 1000
bytes) with a RTNLEN of 3 (the '&' would be removed from the middle
of the value as well).
TRIM escape messages you can monitor for
----------------------------------------
TAA9891 The INPVAL value may not be all blanks.
TAA9892 The TRIMCHAR value may not be all blanks.
Escape messages from based on functions will be re-sent.
Command parameters *CMD
------------------
INPVAL The value to be trimmed. It may be up to 1000 bytes
and may not be all blanks.
TRIMCHAR Up to 50 characters to be trimmed out of the INPVAL
value. The value may not be all blanks.
All characters entered (designated by the rightmost
non-blank) are compared against the leading and
trailing characters in the INPVAL value (assuming
TRIMTYPE = *BOTH). Trimming ends when a
non-matching value is found for either end of the
INPVAL value. It is not an error to enter a
character that does not exist in the INPVAL value.
It is not an error to enter the same character
multiple times such as '-%-', but additional
overhead is required.
Because trimming ends at either end when a
non-matching character is found in the INPVAL value,
trimming of embedded characters does not occur. For
example, if INPVAL = '&&AB&C&, and TRIMCHAR = '&',
the returned value will be 'AB&C'. To remove
embedded characters, see the RMVCHAR TAA command.
The value may be entered in hex. For example, to
trim out upper case 'A', enter TRIMCHAR(X'C1').
TRIMTYPE The type of trimming to be performed. Trimming ends
when any non-matching character in the INPVAL value
is found.
*BOTH is the default to trim leading blanks and any
TRIMCHAR specified at both the leading and trailing
positions of the INPVAL value.
*LEFT may be specified to trim leading blanks and
any TRIMCHAR specified at the leading positions of
the INPVAL value.
*RIGHT may be specified to trim any TRIMCHAR
specified at the trailing positions of the INPVAL
value. Because the RTNVAL must be declared as
LEN(1000) there will be trailing blanks in most
cases.
RTNVAL The return (trimmed) value. A variable must be
specified and it must be declared as *CHAR
LEN(1000).
RTNLEN The return length (the length of the trimmed value).
This is an optional return variable that if used
must be declared as *DEC LEN(5 0).
Restrictions
------------
Because the command returns variables, it may only be used in a CL
program.
Prerequisites
-------------
The following TAA Tools must be on your system:
SNDESCINF Send escape information
SNDESCMSG Send escape message
Implementation
--------------
None, the tool is ready to use.
Objects used by the tool
------------------------
Object Type Attribute Src member Src file
------ ---- --------- ---------- ----------
TRIM *CMD TAACLRN QATTCMD
TAACLRNC *PGM CLP TAACLRNC QATTCL
|