|
|||||
|
This document will focus on a discussion of a numeric field (or data string) known as "PACKED-DECIMAL" format (also referred to as packed data or a packed numeric field). This format is used on an IBM Mainframe and is supported by Micro Focus COBOL running on Windows or UNIX.
Note: The items in this document are appropriate for applications that are written in COBOL, Mainframe Assembler (HLASM) or PL/I. The IBM Mainframe architecture drove many of the numeric formats that existed in the early ANSI specifications for COBOL.and have been carried forward to the current COBOL ANSI specifications.
A packed decimal representation stores two decimal digits in one byte. A packed decimal representation stores decimal digits in each "nibble" of a byte. Each byte has two nibbles, and each nibble is indicated by a hexadecimal digit. For example, the value 23 would be stored in two nibbles, using the hexadecimal digits 2 and 3. The sign indication is dependent on your operating environment. On an IBM mainframe, the sign is indicated by the last nibble. The C indicates a positive value, and D indicates a negative value.
The mainframe can perform arithmetic functions on packed-decimal fields without having to convert the format. Storing numeric values in a packed-decimal format may save a significant amount of storage space. For example, on the mainframe the value 12,345 would be five (5) bytes in length (i.e. x'F1F2F3F4F5'). If the same information is stored in a packed-decimal (i.e. USAGE IS COMP-3) the field would be three (3) bytes in length (i.e. x'12345C').
When converting this type of field from EBCDIC to ASCII the programmer is presented with a number of confusing options and challenges. This document will try to explain the options and help the program avoid the common mistakes that are made during a conversion process.
The following table shows the structure of a five digit numeric field using the Packed-Decimal format (i.e. the COBOL syntax would be USAGE IS COMP-3). The field contains a value of one-hundred-twenty-three (or 00123). Since the packed-decimal format stores a digit in each nibble (2 digits per byte) the actual field size is only three (3) bytes.
| The Packed Decimal Format for a Numeric Field | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Note-1: A field that is defined as "Unsigned"
(i.e. PIC 99999 COMP-3) is an implied positive value.
Note-2: The "Hex" is an abbreviation for
Hexadecimal notation.
Note-3: A field that is defined as "Signed"
(i.e. PIC S99999 COMP-3) will have the sign in the rightmost nibble of the
units positions (or Byte-2 in the preceding example). A X'nC' is used as an
explicit positive sign and a X'nD' is used as an explicit negative
sign.
Note-4:
The Packed-decimal format
is the same for the Mainframe and for Micro Focus running on a Windows or UNIX
system.
The following is a table that shows the actual field sizes (for a COMP-3 or packed-decimal) based on the number of digits specified in the picture clause.
| # of Digits | Picture Clause | Field Size | Value | Positive (Hex) | Negative (Hex) |
| 1 | PIC S9 | 1 | 1 | x'1C' | x'1D' |
| 2 | PIC S99 | 2 | 12 | x'012C' | x'012D' |
| 3 | PIC S999 | 2 | 123 | x'123C' | x'123D' |
| 4 | PIC S9(4) | 3 | 1234 | x'01234C' | x'01234D' |
| 5 | PIC S9(5) | 3 | 12345 | x'12345C' | x'12345D' |
| 6 | PIC S9(6) | 4 | 123456 | x'0123456C' | x'0123456D' |
| 7 | PIC S9(7) | 4 | 1234567 | x'1234567C' | x'1234567D' |
| 8 | PIC S9(8) | 5 | 12345678 | x'012345678C' | x'012345678D' |
| 9 | PIC S9(9) | 5 | 123456789 | x'123456789C' | x'123456789D' |
| 10 | PIC S9(10) | 6 | 1234567890 | x'01234567890C' | x'01234567890D' |
| 11 | PIC S9(11) | 6 | 12345678901 | x'12345678901C' | x'12345678901D' |
| 12 | PIC S9(12) | 7 | 123456789012 | x'0123456789012C' | x'0123456789012D' |
| 13 | PIC S9(13) | 7 | 1234567890123 | x'1234567890123C' | x'1234567890123D' |
| 14 | PIC S9(14) | 8 | 12345678901234 | x'012345678901234C' | x'012345678901234D' |
| 15 | PIC S9(15) | 8 | 123456789012345 | x'123456789012345C' | x'123456789012345D' |
| 16 | PIC S9(16) | 9 | 1234567890123456 | x'01234567890123456C' | x'01234567890123456D' |
| 17 | PIC S9(17) | 9 | 12345678901234567 | x'12345678901234567C' | x'12345678901234567D' |
| 18 | PIC S9(18) | 10 | 123456789012345678 | x'0123456789012345678C' | x'0123456789012345678D' |
This section describes how to convert the previously discussed packed-decimal formats into text strings to print or display the information in a human readable form. Before converting the packed-decimal fields it should be determined if a conversion is necessary. The following list provides some basic guidelines.
| 1. | When migrating an application (both data and COBOL programs for processing the data) from an IBM Mainframe to a Micro Focus and Windows environment a conversion is not necessary. Micro Focus COBOL supports the packed-decimal format. |
| 2. | When migrating an application (both data and COBOL programs for processing the data) from an IBM Mainframe to a Micro Focus and UNIX environment a conversion is not necessary. Micro Focus COBOL supports the packed-decimal format. |
| 3. | When migrating or transferring data from a COBOL oriented, IBM Mainframe or AS/400 environment to a non-COBOL oriented (Windows or UNIX) environment (i.e. ASCII/Text or excel spreadsheet) then a conversion will be required. This may require two conversion tasks. The packed-decimal fields (or data strings) will need to be converted to a zoned-decimal format (sign leading separate with an explicit decimal point should be considered depending on the target environment). The zoned-decimal format may then require a conversion from EBCDIC to ASCII. |
| 4. | When using the File Transfer Protocol (FTP) to transfer a data file between a mainframe and a Windows or UNIX environment it will be necessary to use the BINARY mode if the records contain packed-decimal fields. If a conversion between EBCDIC and ASCII is required it will need to be done after the transfer. |
This section describes how to convert a packed-decimal field (i.e. PIC S9(5) USAGE IS COMPUTATIONAL-3) to a zoned-decimal field (i.e. PIC S9(5) USAGE IS DISPLAY SIGN LEADING SEPARATE). The resulting field will have a separate leading sign but will still have an implied decimal based on the field definition from the COBOL picture clause.
* The following defines a signed, packed-decimal field.
* The length of this field is 3 bytes & contains 5 digits.
01 PACK-DECIMAL-S3V2-TEXT.
05 PACK-DECIMAL-S3V2 pic S9(3)V99 COMP-3 value 0.
* The following defines a signed, zone-decimal field.
* The sign is not part of the units position because of
* the SIGN LEADING SEPARATE syntax. This is standard
* COBOL coding and is ANSI/85 compliant.
* The length of this field is 6 bytes.
01 SLS-S3V2-TEXT.
05 SLS-S3V2-NUMB pic S9(3)V99 value 0
SIGN LEADING SEPARATE.
...
...
PROCEDURE DIVISION.
* The following statement will place a value into the
* packed-decimal field. The actual value will be x'00123C'.
add 1.23 to ZERO giving PACK-DECIMAL-S3V2
* The following statement will place the arithmetic value of
* the packed-decimal field into the zone-decimal field. The actual
* value will be x'4EF0F0F1F2F3'. This results in converting the
* packed-decimal field. Both fields have an implied decimal point.
add PACK-DECIMAL-S3V2 to ZERO giving SLS-S3V2-NUMB
* The preceding statement is the only statement required to do
* the conversion from packed-decimal to zone-decimal.
* The additional code in this section is used to display the
* input and result field values in hexadecimal dump format.
This section describes how to convert a packed-decimal field (i.e. PIC S9(5) USAGE IS COMPUTATIONAL-3) to a zoned-decimal field (i.e. PIC X ). The resulting field will have a separate leading sign and an explicit decimal point embedded in the text string. This field (or data string) may easily be exported to a non-COBOL environment.
* The following defines a signed, packed-decimal field.
* The length of this field is 3 bytes & contains 5 digits.
01 PACK-DECIMAL-S3V2-TEXT.
05 PACK-DECIMAL-S3V2 pic S9(3)V99 COMP-3 value 0.
* The following defines an edited field for numeric
* values and will contain an explicit decimal point. This
* is standard COBOL coding and is ANSI/85 compliant.
* The length of this field is 7 bytes.
01 PRINT-LINE.
05 FILLER pic X(8) value 'Edited: '.
05 PRINT-NUMBER pic +ZZZ.99.
...
...
PROCEDURE DIVISION.
* The following statement will place a value into the
* packed-decimal field. The actual value will be x'00123C'.
add 1.23 to ZERO giving PACK-DECIMAL-S3V2
* The following statement will place the arithmetic value of
* the packed-decimal field into the edited print field. The
* actual value will be x'4E4040F14BF2F3'. This results in
* converting the packed-decimal field but has leading spaces.
move PACK-DECIMAL-S3V2 to PRINT-NUMBER
* The following statement will replace the leading spaces
* with zeroes. The resulting value will be x'4EF0F0F14BF2F3'.
inspect PRINT-NUMBER replacing all SPACE by ZERO
* The preceding 2 statements are the only statements required
* to do the conversion from packed-decimal to zone-decimal.
* The additional code in this section is used to display the
* input and result field values in hexadecimal dump format.
We have seen a few instances where a packed field may contain SPACES. This should be considered a bad programming practice. Having non-numeric values in a numeric field should be avoided. The process that caused non-numerics to be placed in a numeric field should be corrected. When converting data between EBCDIC and ASCII this presents an additional effort to deal with the situation.
A SPACE character (hex 40 for EBCDIC or a hex 20 for ASCII) could be a valid numeric entry in a packed field in all the positions of the field except the units positions. It would be reasonable to assume that if the units position of a packed field is a SPACE character and all other positions are SPACE characters then the packed field SPACE values should be converted between EBCDIC and ASCII.
For numeric fields with USAGE IS COMP-3 (i.e. PACKED FIELDS) the conversion code generated by SimoTime does not do any conversion. This is the default behavior. However, since the situation does exist the SimoTime technology has a configuration option to generate conversion code that will analyze a packed field and convert SPACE values between EBCDIC and ASCII or to initialize the packed field with a ZERO value.
The following is sample code that will test a packed field for SPACE values and then convert the EBCDIC SPACE values to ASCII SPACE values.
* Packed CUST-CREDIT-LIMIT
* The /PACKEDFLD option is set to SPACECONVERT
if CUST-RECORD(300:4) = all x'40'
inspect CUST-RECORD(300:4) replacing all x'40' by x'20'
end-if
The following is sample code that will test a packed field for SPACE values and then initialize the packed field to ZERO values.
* Packed CUST-CREDIT-LIMIT
* The /PACKEDFLD option is set to SPACEZERO
if CUST-RECORD(300:4) = all x'40'
inspect CUST-RECORD(300:4) replacing all x'40' by x'00'
move x'0F' to CUST-RECORD(303:1)
end-if
The purpose of this document is to provide an overview of numeric data strings or fields that are packed-decimal format.
Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
The following table provides a list of white papers describing the numeric formats used on an IBM Mainframe system. A couple of sample COBOL programs are also included.
| Numeric Type | Description |
| Zoned Decimal | This document describes the zoned-decimal format. This is coded in COBOL as USAGE IS DISPLAY and is the default format if the USAGE clause is missing. |
| Packed Decimal | This document describes the packed-decimal format. This is coded in COBOL as USAGE IS COMPUTATIONAL-3 and is usually coded in its abbreviated form of COMP-3. |
| Binary | This document describes the binary format. This is coded in COBOL as USAGE IS COMPUTATIONAL and is usually coded in its abbreviated form of COMP. This may also be coded with the keyword BINARY. |
| Edited Numeric | This document describes the edited numeric format. This is coded in COBOL using an edit mask in the picture clause. An example would be PIC ZZZ.99+. |
| number01 | This example describes some commonly used techniques for managing various numeric formats available on the mainframe. |
| spsnum01 | This is an introductory, self-study course about the commonly used numeric formats available on the mainframe. The course material may be purchased from SimoTime. The documentation may be viewed online. |
The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
To review all the information available on this site start at The SimoTime Home Page .
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned, Limited Liability Corporation located in Novato, California. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2008 SimoTime Enterprises, LLC All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |
| Version 06.03.24 |