ITOPACK: Converting a Large Binary Integer to Packed-Decimal Format

How to:

Available Languages: reporting, Maintain

The ITOPACK function converts a large binary integer in a non-FOCUS data source to packed-decimal format.

Some programming languages and some non-FOCUS data storage systems use double-word binary integer formats. These are similar to the single-word binary integers used by FOCUS, but they allow larger numbers. However, large binary integers (more than 4 bytes in length) are not supported in the Master File so they require conversion to packed-decimal format.

You must specify how many of the right-most bytes in the input field are significant. The result is an 8-byte packed-decimal field of up to 15 significant numeric positions (for example, P15 or P16.2).

Limit: For a field defined as 'PIC 9(15) COMP' or the equivalent (15 significant digits), the maximum number that can be converted is 167,744,242,712,576.

Syntax: How to Convert a Large Binary Integer to Packed-Decimal Format

ITOPACK(maxbytes, infield, output)

where:

maxbytes

Numeric

Is the maximum number of bytes in the 8-byte binary input field that have significant numeric data, including the binary sign.

Valid values are:

  • 5 ignores the left-most 3 bytes (up to 11 significant positions).
  • 6 ignores the left-most 2 bytes (up to 14 significant positions).
  • 7 ignores the left-most byte (up to 15 significant positions).
infield

A8

Is the field that contains the binary number. Both the USAGE and ACTUAL formats of the field must be A8.

output

Numeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be Pn or Pn.d.

Example: Converting a Large Binary Integer to Packed-Decimal Format

Suppose a binary number in an external file has the following COBOL format:

PIC 9(8)V9(4) COMP

It is defined in the EUROCAR Master File as a field named BINARYFLD. Its field formats are USAGE=A8 and ACTUAL=A8, since its length is greater than 4 bytes.

The following request converts the field to packed-decimal format:

DEFINE FILE EUROCAR
PACKFLD/P14.4 = ITOPACK(6, BINARYFLD, PACKFLD);
END
TABLE FILE EUROCAR
PRINT PACKFLD BY CAR
END