The NumToNum procedure dynamically converts numeric data stored in a character field to a numeric value. This allows you extract a packed, zoned or integer value from a buffer and store it in a numeric field.
numeric-value NumtoNum( szSrcValue 256A Const Varying DataType 1A Const nSrcLen 5I 0 Const nSrcDecPos 5I 0 Const Options(*NOPASS) ) |
|
See also: NumToZoned, NumToChar, CharToNum |
| Symbolic Named Constant | Value |
| T_Signed or T_Integer | X'00' |
| T_Zoned | X'02' |
| T_Packed | X'03' |
If the function succeeds, the return value is the value from the szSrcValue parameter in numeric form. A packed decimal value is returned, and may be assigned to any numeric variable using the EVAL operation.
If the function fails, the return value is zero.
This procedure is provided for dynamic conversion. It provides an easy method for extracting a packed value from within an unformatted character buffer.
In the example that follows, the NumtoNum procedure is used to extract a packed decimal value from a flat-file record. That numeric value, referred to as amount due is converted to numeric and copied to the nAmtDue field.
H DftActGrp(*NO) BNDDIR('XTOOLS/XTOOLS')
FCustMast IF F 50 DISK
/INCLUDE QCPYSRC,NumtoNum
.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++
D nAmtDue S 7P 2
ICUSTMAST NS
I 1 50 DATA
** The CUSTMAST file has the amount due value
** stored as a packed (7,2) value starting in
** position 15 of the file's record.
.....C..n01..............OpCode(ex)Extended-factor2+++++++++++++++++++++++++++++
C Eval nAmtDue = NumtoNum(%Subst(data: 15: 4) :
C T_Packed : 7 : 2)
C nAmtDue dsply
Positions 15 to 18 of the DATA field are illustrated below:
|
The packed decimal value 2431.50 is stored in positions 15 to 18 of the DATA field. The substring operation extracts the information from those positions and passes it to NumtoNum. NumtoNum unpacks the data and returns it as a numeric value. That return value is copied to the nAmtDue field.