The Convert Character to Decimal command converts a character field
to a decimal value and allows for editing and validity checking
options. The command is similar to CHGVAR, but provides for options
to simplify CL program coding. CPF9898 is sent as an escape message
on any invalid data.
CVTCHRDEC may be used when the data is input as a parameter to your
program or from a display file.
A typical command would be:
DCL &OUTDEC *DEC LEN(15 0)
.
CVTCHRDEC INPCHAR(&xxx) OUTDEC(&OUTDEC)
Options
-------
Options exist to allow for:
- Leading minus sign
- Trailing minus sign
- Leading plus sign
- Decimal character
- Separator characters
If a decimal notation exists in the INPCHAR value and is allowed by
ALWDECPOS(*YES), the value is returned as a whole number. For
example, if the INPCHAR value is 12.3, the value 123 is returned.
Optional return variables
-------------------------
Optional return variables exist for the integer count (whole numbers
in the input value) and the number of decimal positions in the input
value. For example:
DCL &OUTDEC *DEC LEN(15 0)
DCL &RTNINTCNT *DEC LEN(3 0)
DCL &RTNDECCNT *DEC LEN(3 0)
.
CVTCHRDEC INPCHAR(&xxx) OUTDEC(&OUTDEC) +
RTNINTCNT(&RTNINTCNT) +
RTNDECCNT(&RTNDECCNT)
If the INPCHAR value is 12.3, the following would exist:
OUTDEC 123
RTNINTCNT 2
RTNDECCNT 1
Validity checking values exist for the number of decimal positions
and a range of values. The range of values test must be specified in
integers. For example, if a range of .01 to 9.01 is valid,
LOWRANGE(1) and HIGHRANGE(901) should be specified.
If the INPCHAR value is not in a range of .01 to 9.01, the error
message would state 'Not in range of 1 to 901. To provide for a
better error message when a range value including decimal positions
is specified, you should specify the RANGEDEC parameter. If
RANGEDEC(2) had been specified, the error message would be 'Not in
range of .01 to 9.01'.
Error conditions
----------------
The CPF9898 escape message is sent if errors occur such as non-valid
characters, two minus signs, or a decimal character exists when the
option does not allow it. Embedded blanks are not valid such as:
1 23
1.2 3
The text of the CPF9898 escape message varies depending on the error
condition.
If you are using a display file, typical coding would be as follows
where the &MSG field is defined in the display file as *CHAR LEN(80)
and would appear on an error line.
DISPLAY: SNDRCVF
CHGVAR &MSG ' '
.
CVTCHRDEC ...
MONMSG MSGID(CPF9898) EXEC(DO) /* Some error */
RCVMSG MSGTYPE(*EXCP) MSG(&MSG)
GOTO DISPLAY
ENDDO /* Some error */
Command parameters *CMD
------------------
INPCHAR The input value to be converted. It must be a
character field and cannot exceed 22 bytes in
length.
OUTDEC The converted decimal value that is returned. It
must be declared as *DEC LEN(15 0). The value
returned is always in whole numbers. For example,
if INPCHAR is 12.3, OUTDEC would be 123. To
determine the number of decimal positions entered by
the user, use the RTNDECCNT parameter.
RTNINTCNT The return count of the number of integers entered.
This is an optional return variable. If used, it
must be specified as *DEC LEN(3 0). If the INPCHAR
value is 12.3, the integer count returned would be
2.
RTNDECCNT The return count of the number of decimal positions
entered. This is an optional return variable. If
used, it must be specified as *DEC LEN(3 0). If the
INPCHAR value is 12.3, the decimal count returned
would be 1.
RQDDECPOS An optional parameter that defaults to *NONE that
determines if the input value should be checked to
see if a decimal position exists. *NONE causes no
check to occur.
If a value is entered, the number of digits to the
right of the decimal position is checked to see if
it is the same count. For example, if the user must
always enter two digits to the right of the decimal
value (eg. 1.00), then an entry of 2 will force
this check. If all blanks are entered, this value
is not checked. To require an entry, use the
LOWRANGE and HIGHRANGE parameters.
ALWLDGMIN A *YES/*NO parameter for whether to allow a leading
minus sign. The default is *NO. *YES may be
specified to allow a leading minus sign.
Specifying both ALWLDGMIN(*YES) and ALWTRLMIN(*YES)
is valid, but the INPCHAR value may only have a
single minus sign.
ALWTRLMIN A *YES/*NO parameter for whether to allow a trailing
minus sign. The default is *NO. *YES may be
specified to allow a trailing minus sign.
Specifying both ALWLDGMIN(*YES) and ALWTRLMIN(*YES)
is valid, but the INPCHAR value may only have a
single minus sign.
ALWLDGPLS A *YES/*NO parameter for whether to allow a leading
plus sign. The default is *NO. *YES may be
specified to allow a leading plus sign.
Specifying both ALWLDGMIN(*YES) and ALWLDGPLS(*YES)
is valid, but the INPCHAR value may only have one of
the signs.
ALWDECPOS A *YES/*NO parameter for whether to allow a decimal
position character. The default is *NO. *YES may
be specified to allow a decimal position character.
The character used is determined based on the
QDECFMT system value.
ALWSEPCHR A *YES/*NO parameter for whether to allow separator
characters such as the comma in 123,456. The
default is *NO. *YES may be specified to allow a
separator character.
The character used is determined based on the
QDECFMT system value.
LOWRANGE The Low Range value to test for. The default is
*NONE. If a value is entered, the value must be
greater than or equal to the LOWRANGE value.
The Low Range value should be specified ignoring
decimal positions. For example, if the low range is
.01, specify LOWRANGE(1).
If decimal positions are allowed to exist in the
input value, you should improve the Range Check
validity error message by specifying the RANGEDEC
parameter.
HIGHRANGE The High Range value to test for. The default is
*NONE. If a value is entered, the value must be
less than or equal to the HIGHRANGE value.
The High Range value should be specified ignoring
decimal positions. For example, if the high range
is 99.01, specify HIGHRANGE(9901).
If decimal positions are allowed to exist in the
input value, you should improve the Range Check
validity error message by specifying the RANGEDEC
parameter.
RANGEDEC The number of decimal positions in the range check
error message. The default is *NONE.
If you want a low range of .01 to 9.01, LOWRANGE(1)
and HIGHRANGE(901) should be specified. If the
input value is not within the range, the error
message would state 'Not in range of 1 to 901. To
provide for a better error message when a range
value is specified including decimal positions, you
should specify a RANGEDEC value. If RANGEDEC(2) had
been specified, the error message would be 'Not in
range of .01 to 9.01'.
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:
EDTVAR Edit variable
SNDESCMSG Send escape message
Implementation
--------------
None, the tool is ready to use.
Objects used by the tool
------------------------
Object Type Attribute Src member Src file
------ ---- --------- ---------- ----------
CVTCHRDEC *CMD TAACLQT QATTCMD
TAACLQTC *PGM CLP TAACLQTC QATTCL
|