Convert Numeric to Zoned-Character

NumToZoned

The NumToZoned procedure dynamically converts numeric data stored in a character field to zoned (signed) decimal data, then converts that zoned decimal to character. Unlike a traditional assignment statement such as MOVE or EVAL, NumToZoned works with packed and integer (binary) data that is extracted from a flat file using %subst or similar functions. The data passed to NumToZoned must be in valid packed decimal or binary format that is stored in a character field.

The primary difference between this procedure and NumToChar is that you have a choice of edit codes and return formats with NumToChar, where as NumToZoned provides a quick method for returning a character form of a numeric value without applying edit characteristics. The return value includes all leading zeros.

varying-length-char-value NumToZoned(
  szSrcValue 256A   Const Varying :
  DataType     1A   Const :
  nSrcLen      5I 0 Const :
  nSrcDec      5I 0 Const OPTIONS(*NOPASS) 
)

See also: NumToChar, CharToNum

Parameters

szSrcValue
[input VChar(256) const]  A varying or fixed-length character value whose length is 1 to 64 and that contains packed, zoned or integer data. The data must be in true packed, zoned, or integer format but stored in a character buffer. A valid value for this parameter, would be a character field whose length is 4, containing X'7654321F'. The returned value would be '7654321'.
DataType
[input Char(1) const] Specifies the data-type format for the szSrcValue parameter. This identifies the format that the data is currently stored in. Valid choices for this parameter are as follows:
 
Symbolic Named Constant Value
T_Signed or T_Integer X'00'
T_Zoned X'02'
T_Packed X'03'
nSrcLen
[input int(2) const]  Specify the number of digits for the value specified on the szSrcValue parameter. This is the actual number of decimal digits (not the number of bytes) in the numeric value specified for the szSrcValue parameter. The valid range is 1 to 31.
nSrcDec [Optional]
[input int(2) const]  Specify the number of decimal positions for the value specified on the szSrcValue parameter. The valid range is 0 to 31. Strictly speaking, this value is not used by the conversion algorithm and therefore does not need to be specified.

Return Value

If the function succeeds, the return value is the character form of the numeric value specified on the szSrcValue parameter. The value is returned as zoned decimal stored in a varying length character field. This value may be assigned to a character field (with or without the varying attribute).

If the function fails, the return value is empty.

Remarks

This procedure is provided for dynamic conversion only. It provides a quick method to convert data stored in a buffer to zoned decimal with leading zeros included. It is used for by the CSV and XML routines.