Description and Discussion
|The SimoTime Home Page|
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 System and is supported by Micro Focus COBOL running on a Linux, UNIX or Windows System.
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 (a byte is eight bits and a nibble is four bits). 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 bit representation would be 0010 0011). The sign indication is dependent on your operating environment. On an IBM mainframe, the sign is indicated by the last nibble of the last byte (or high memory address). For explicitly signed fields the "C" indicates a positive value and "D" indicates a negative value. For unsigned (or implied positive) fields the "F" indicates a positive 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 programmer 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.
We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.
Copyright © 1987-2015
All Rights Reserved
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)|
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.
|Guidelines for Converting Packed Fields to Display Fields|
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-numeric values 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 expressed 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 section includes links to documents with additional information that are beyond the scope and purpose of this document. The first sub-section requires an internet connection, the second sub-section references locally available documents.
Note: A SimoTime License is required for the items to be made available on a local server.
Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the icon.
Explore The Binary or COMP format for numeric data strings. This numeric structure is supported by COBOL and may be explicitly defined with the "USAGE IS COMP" or "USAGE IS BINARY" clause.
Explore The Edited for Display format for numeric data strings. This numeric structure is supported by COBOL and may be used with an edit-mask to prepare the presentation for readability by human beings.
Explore The Packed-Decimal or COMP-3 format for numeric data strings. This numeric structure is supported by COBOL and may be explicitly defined with the "USAGE IS COMP-3" clause.
Explore The Zoned-Decimal format for numeric data strings. This numeric structure is the default numeric for COBOL and may be explicitly defined with the "USAGE IS DISPLAY" clause.
Explore commonly used formats and processing techniques for managing various numeric formats available on the mainframe.
Explore the Numbers Connection for additional information about the structure and processing of numeric data items (or numeric fields).
Explore How to Generate a Data File Convert Program using simple specification statements in a Process Control File. This link to the User Guide includes the information necessary to create a Process Control File and generate the COBOL programs that will do the actual data file conversion.
Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.
Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and/or QSAM files.
The following links will require an internet connect.
A good place to start is The SimoTime Home Page via Internet Connect for access to white papers, program examples and product information.
Explore The Micro Focus Web Site via Internet Connect for more information about products and services available from Micro Focus.
Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.
This document was created and is copyrighted and maintained by SimoTime Technologies.
If you have any questions, suggestions, comments or feedback please call or send an e-mail to: email@example.com
We appreciate hearing from you.
Founded in 1987, SimoTime Technologies is a privately owned company. 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
|Packed-Decimal Format, Description and Discussion|
|Copyright © 1987-2015
All Rights Reserved
|When technology complements business|