The Calculate Large Variable command allows CL to work with character
variables that exceed 15 bytes in length and contain up to 30 digits.
Simple operations of Add, Sub, Multiply, and Divide are supported.
Any values placed in the Factors are right aligned. The return
result must be specified as *CHAR LEN(30) and will be right aligned
by default with leading blanks. A return value exists for a minus
sign.
See also the EDTLRGVAR tool command.
Some system functions now return large size variables containing
decimal values that exceed the largest size that CL supports as a
*DEC type which is 15 digits. CLCLRGVAR allows operations on these
large variables.
Either or both factors may contain a leading or trailing minus sign
(but both may not be in the same factor). CLCLRGVAR right aligns
both factors. Leading blanks are treated as zeros (including an all
blank value). No embedded characters of blank or minus may exist.
No decimal point may exist. The result field can hold up to 30
digits.
A typical series of commands would be:
DCL &FACTOR1 *CHAR LEN(31)
DCL &FACTOR2 *CHAR LEN(31)
DCL &RESULT *CHAR LEN(30)
.
CHGVAR &FACTOR1 nnn
CHGVAR &FACTOR2 nnn
CLCLRGVAR OPER(*ADD) FACTOR1(&FACTOR1) FACTOR2(&FACTOR2)
RESULT(&RESULT)
The factor values would be right adjusted and ensured to contain only
valid digits. A leading or trailing minus would indicate a negative
value.
If a negative result exists, the SIGN return variable will be '-'.
If OPER(*DIV) is used, the optional return variable REMNDR will
contain the remainder.
Factor examples (b = blank)
---------------------------
Valid Invalid Invalid reason
----- ------- --------------
3bbbbb 2b1 Embedded blank
23-bbbb 2A3 Non digit
-2323bbb -2- Multiple minus signs
4 -bb23 Embedded blanks
4- 1.23 Decimal point
bbbbb 000-4 Embedded minus
- Only a minus sign
Decimal overflow
----------------
No check is made for a decimal overflow. If it occurs, the overflow
is truncated. You must ensure that your values will not cause an
overflow.
CLCLRGVAR escape messages you can monitor for
---------------------------------------------
TAA9891 An attempt to divide by 0
Escape messages from based on functions will be re-sent.
CLCLRGVAR Command parameters *CMD
----------------------------
OPER The operation to be performed.
*ADD Adds Factor 1 to Factor 2
*SUB Subtracts Factor 2 from Factor 1
*MULT Multiplies Factor 1 by Factor 2
*DIV Divides Factor 1 by Factor 2
See optional REMNDR parameter also
FACTOR1 The Factor 1 value. It must be declared as *CHAR
LEN(31), but cannot contain more than 30 digits. It
may contain leading or trailing blanks or a leading
or trailing minus sign. The value is right aligned
before performing any calculations. Embedded blanks
are not valid nor is a decimal notation.
FACTOR2 The Factor 2 value. It must be declared as *CHAR
LEN(31), but cannot contain more than 30 digits. It
may contain leading or trailing blanks or a leading
or trailing minus sign. The value is right aligned
before performing any calculations. Embedded blanks
are not valid nor is a decimal notation.
RESULT The Result of the calculation. This is a required
return variable that must be declared as *CHAR
LEN(30). The value will be right aligned by
default, preceded by leading blanks, and will always
be positive. Negative values are indicated in the
SIGN return parameter. If the result is zero, one
zero will be returned.
ALIGNRES Whether to align the result to the left or right in
the RESULT return variable. *RIGHT is the default
to align to the right. *LEFT may be specified to
align to the left.
SIGN An optional return variable that will contain the
sign of the result (and the remainder if any).
Either blank (plus) or '-' for minus will be
returned. If specified, the variable must be
declared as *CHAR LEN(1).
REMNDR An optional return variable that will contain the
remainder if OPER(*DIV) is used. If the OPER is
other than *DIV, blanks will be returned. If
specified, the variable must be declared as *CHAR
LEN(30).
The value is right aligned with leading blanks. If
a divide produces a 0 remainder, a single 0 will be
returned right adjusted.
Note that the value will always be plus. Use the
SIGN return variable to determine the true sign.
Restrictions
------------
Because CLCLRGVAR returns values, the command may only be used in a
CL like program.
No check is made for a decimal overflow. If it occurs, the overflow
is truncated. You must ensure that your values will not cause an
overflow.
Prerequisites
-------------
The following TAA Tools must be on your system:
ADJVAR Adjust variable
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
------ ---- --------- ---------- ----------
CLCLRGVAR *CMD TAACLUB QATTCMD
TAACLUBC *PGM CLP TAACLUBC QATTCL
TAACLUBR *PGM RPG TAACLUBR QATTCL
|