Numbers and Formats
 Internal Numeric Structures
http://www.simotime.com
 Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 09.05.17 
  Introduction
  Objective of Session
 
  Requirements
  Materials Provided
  Criteria for Success
  Analyze the Number Formats
 
  Numeric Fields, Zoned Decimal Format
 
  Numeric Fields, Zoned Decimal, Unsigned
  Numeric Fields, Zoned Decimal, Signed, Positive
  Numeric Fields, Zoned Decimal, Signed, Negative
  Numeric Fields, Zoned Decimal, Advantages and Disadvantages
  Numeric Fields, Packed-Decimal or COMP-3 Format
 
  Numeric Fields, Packed Decimal, Unsigned
  Numeric Fields, Packed Decimal, Signed, Positive
  Numeric Fields, Packed Decimal, Signed, Negative
  Numeric Fields, Packed Decimal, Advantages and Disadvantages
  Numeric Fields, BINARY or COMP Format
 
  Numeric Fields, Binary or COMP, Unsigned
  Numeric Fields, Binary or COMP, Signed, Positive
  Numeric Fields, Binary or COMP, Signed, Negative
  Numeric Fields, Binary or COMP, Advantages and Disadvantages
  Convert Packed-Decimal Format
 
  Convert, Packed-Decimal to Display
  Convert, Packed-Decimal to Display with Explicit Decimal Point
  Convert, Packed-Decimal Considerations for EBCDIC and ASCII Encoding
  A Sample JCL Member
  A Sample Command (.CMD) File
  A Sample COBOL Program
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Glossary of Terms
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

This document is an introduction to the various numeric formats used by COBOL and the IBM mainframe systems The session will describe three of the popular numeric formats used with COBOL and IBM Mainframe systems. The discussions include further detail about the issues and concerns of unsigned (or implied positive) numbers, signed (positive or negative) numbers and decimal or whole numbers. A sample of how to convert non-print formats to display or print formats is included along with a sample COBOL program.

The sample COBOL source code that is used in this session may be compiled and executed using Micro Focus COBOL (this includes Mainframe Express or Net Express). Since the sample COBOL source code is COBOL/2 compliant it may be compiled and executed on a mainframe (either z/OS or VSE). For this exercise only the Windows operating system with Micro Focus COBOL will be used. A JCL member is included for ease of execution for the Mainframe or with Micro Focus Mainframe Express. A Windows command file (.CMD) is included for ease of execution for the Micro Focus Net Express sub-system running under Windows.

To perform this exercise requires a basic knowledge of the Windows environment and Micro Focus Net Express (the COBOL sample program will also work with Mainframe Express and may be compiled and executed on an IBM Mainframe). Additional help is provided for individuals that may not be proficient in the use of Micro Focus or have forgotten how to perform a particular function.

Note: This module is part of The SimoPATH Series of training and reference materials. For more information refer to The Home Page for The SimoPATH Series.

Objective of Session
(Next) (Previous) (Table-of-Contents)

The objective of this session is to assist the user in developing a basic understanding of the most common numeric encoding formats used on an IBM Mainframe and how to migrate or export this information to a Windows platform.

1. Discuss the three most common numeric encoding formats.
2. Show the memory dump of the underlying binary or hexadecimal values of the numeric formats.
3. Discuss numeric format conversion options.
4. Document the Hardware and Software that is required to perform this exercise.

Requirements
(Next) (Previous) (Table-of-Contents)

If this session is being performed through self-study then it will be necessary to install the following software on a Windows system. Windows/XP or Windows Server is preferred.

1. Either Micro Focus Net Express or Micro Focus Mainframe Express must be installed. Refer to the Micro Focus documentation for more information about these technologies. Net Express is used for the classroom environment and the self-study course.
2. The SimoTime library of utility programs and callable routines must be installed. These technologies are usually pre-installed for the classroom environment and must be obtained from SimoTime and installed for the self-study course.
3. The DataMig1 directory that is available from SimoTime must be configured. This directory is usually pre-configured for the classroom environment and must be obtained from SimoTime and installed for the self-study course.

Note: This example uses two of the shared modules that are included in the SimoMODS package of programs. The SimoDUMP and SIMOLOGS programs may be compiled with a Micro Focus dialect and the SYSLOG references in the JCL member will be ignored. The mapping of the SYSLOG will be dependent on a SYSLOG environment variable setting.

Materials Provided
(Next) (Previous) (Table-of-Contents)

For the classroom environment two directories (c:\DataMig1 and c:\SimoLIBR) are provided that contain the following information.

1. The c:\DataMig1\ directory contains the sample source members for this exercise.
2. The c:\SimoLIBR directory contains the SimoTime utility programs used in this exercise.

Criteria for Success
(Next) (Previous) (Table-of-Contents)

The following items must be completed to meet the minimum requirements for successfully completing this session.

1. Read a Micro Focus sequential file that contains the various numeric formats and export the data to an excel spreadsheet.
2. Highlight the Hexadecimal numeric fields in the memory dump.
3. Display or print the numeric files with a separate sign and suppress leading zeroes using COBOL.

Analyze the Number Formats
(Next) (Previous) (Table-of-Contents)

This session will describe three popular numeric formats used with COBOL and/or the IBM Mainframe. Included is a sample COBOL program describing how to convert non-print formats to display or print formats.

Numeric Field Type Coding Syntax Normally Coded (Minimum)
Binary
(alternate coding technique)
USAGE IS COMPUTATIONAL
USAGE IS BINARY
COMP
BINARY
Packed Decimal USAGE IS COMPUTATIONAL-3 COMP-3
Zoned Decimal USAGE IS DISPLAY Left blank, this is the default

The following is an example of actual COBOL source code.

      *    The following two lines show the syntax for a binary field,
      *    1st line is full syntax, 2nd line is normally coded syntax.
       01  NUMERIC-BINARY-FULL  PIC S9(5)V99 USAGE IS COMPUTATIONAL.
       01  NUMERIC-BINARY-NORM  PIC S9(5)V99 COMP.
      *    The following two lines show the syntax for a packed field,
      *    1st line is full syntax, 2nd line is normally coded syntax.
       01  NUMERIC-PACKED-FULL  PIC S9(5)V99 USAGE IS COMPUTATIONAL-3.
       01  NUMERIC-PACKED-NORM  PIC S9(5)V99 COMP-3.
      *    The following two lines show the syntax for a zoned field,
      *    1st line is full syntax, 2nd line is normally coded syntax.
       01  NUMERIC-ZONED-FULL   PIC S9(5)V99 USAGE IS DISPLAY.
       01  NUMERIC-ZONED-NORM   PIC S9(5)V99.

Numeric Fields, Zoned Decimal Format
(Next) (Previous) (Table-of-Contents)

The unsigned, zone decimal fields are text fields and are assumed to be a simple, no risk conversion. However, during an EBCDIC to ASCII conversion it is a good practice to treat unsigned fields as signed since it is possible for a signed, zone-decimal value to end up in an unsigned field. As long as it is a positive value the mainframe will process the field.

Numeric Fields, Zoned Decimal, Unsigned
(Next) (Previous) (Table-of-Contents)

If we take a five digit number (00123) and look at how it is stored in memory as an UNSIGNED, ZONED-DECIMAL number. It will be different for EBCDIC-encoding and ASCII-encoding.

For EBCDIC-encoding the five digit number (00123) is represented as x'F0F0F1F2F3'. If this number is printed or displayed it will appear as "00123". The following is the memory dump of the EBCDIC-encoded number.

 * ZONED... ********************************************************************
 * ZONED... Zoned-Decimal, Unsign, USAGE IS DISPLAY
 * ZONED... Starting... Length = 0005
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 F0F0F1F2 F3xxxxxx xxxxxxxx xxxxxxxx 00123........... ................
 * ZONED... Complete... Length = 0005

For ASCII-encoding the five digit number (00123) is represented as x'3030313233'. If this number is printed or displayed it will appear as "00123". The following is the memory dump of the ASCII-encoded number.

 * ZONED... ********************************************************************
 * ZONED... Zoned-Decimal, Unsign, USAGE IS DISPLAY
 * ZONED... Starting... Length = 0005
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 30303132 33xxxxxx xxxxxxxx xxxxxxxx ................ 00123...........
 * ZONED... Complete... Length = 0005

Numeric Fields, Zoned Decimal, Signed, Positive
(Next) (Previous) (Table-of-Contents)

If we take a five digit positive number (+00123) and look at how it is stored in memory as a SIGNED, ZONED-DECIMAL number. It will be different for EBCDIC-encoding and ASCII-encoding.

For EBCDIC-encoding the five digit positive number (+00123) is represented as x'F0F0F1F2C3'. If the number is printed or displayed it will appear as "0012C" and the editing effort to properly display or print has caused headaches for programmers for years. The following is the memory dump of the EBCDIC-encoded positive number.

 * ZONED... Zoned-Decimal, Signed, Positive, USAGE IS DISPLAY
 * ZONED... Starting... Length = 0005
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 F0F0F1F2 C3xxxxxx xxxxxxxx xxxxxxxx 0012C........... ................
 * ZONED... Complete... Length = 0005

For ASCII-encoding the five digit positive number (+00123) is represented as x'3030313233'. If this number is printed or displayed it will appear as "00123". The following is the memory dump of the ASCII-encoded positive number.

 * ZONED... Zoned-Decimal, Signed, Positive, USAGE IS DISPLAY
 * ZONED... Starting... Length = 0005
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 30303132 33xxxxxx xxxxxxxx xxxxxxxx ................ 00123...........
 * ZONED... Complete... Length = 0005

Numeric Fields, Zoned Decimal, Signed, Negative
(Next) (Previous) (Table-of-Contents)

If we take a five digit negative number (-00123) and look at how it is stored in memory as a SIGNED, ZONED-DECIMAL number.

For EBCDIC-encoding the five digit negative number (-00123) is represented as x'F0F0F1F2D3'. If the number is printed or displayed it will appear as "0012L" and this has caused headaches for programmer to correct. The following is the memory dump of the EBCDIC-encoded negative number.

 * ZONED... Zoned-Decimal, Signed, Negative, USAGE IS DISPLAY
 * ZONED... Starting... Length = 0005
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 F0F0F1F2 D3xxxxxx xxxxxxxx xxxxxxxx 0012L........... ................
 * ZONED... Complete... Length = 0005

For ASCII-encoding(using Micro Focus) the five digit negative number (-00123) is represented as x'3030313273'. If this number is printed or displayed it will appear as "0012s". The following is the memory dump of the ASCII-encoded negative number.

 * ZONED... Zoned-Decimal, Signed, Negative, USAGE IS DISPLAY
 * ZONED... Starting... Length = 0005
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 30303132 73xxxxxx xxxxxxxx xxxxxxxx ................ 0012s...........
 * ZONED... Complete... Length = 0005

Numeric Fields, Zoned Decimal, Advantages and Disadvantages
(Next) (Previous) (Table-of-Contents)

The advantages for Zoned Decimal fields are as follows.

1. The unsigned, positive numbers are easy to display or print.
2. The signed numbers require minimum effort to edit for printing or displaying.
3. Easy for programmers to read when testing or debugging programs.

The disadvantages for Zoned Decimal fields are as follows.

1. Not an efficient use of memory or disk, a five digit number will take five bytes of storage or disk space.
2. Not the most efficient way for processors to perform arithmetic. Some systems will actually convert the number to binary, do the arithmetic and convert the result back to zoned-decimal format.
3. Requires some editing before printing or displaying. This is especially true for signed fields.

The Zoned-Decimal format is supported on the mainframe and with Micro Focus COBOL.

The Zoned Decimal Format, Description and Discussion document provides additional, detailed information for this type of field or data string.

Numeric Fields, Packed-Decimal or COMP-3 Format
(Next) (Previous) (Table-of-Contents)

Packed-decimal fields provided a way to store numeric fields or data strings using less memory or machine readable storage. For Example, a five digit value can be stored in three bytes.

Numeric Fields, Packed Decimal, Unsigned
(Next) (Previous) (Table-of-Contents)

If we take a five digit implied, positive number (00123) and look at how it is stored in memory as an UNSIGNED, PACKED-DECIMAL number. It will be the same for EBCDIC-encoding and ASCII-encoding (using Micro Focus). The three bytes in memory will be x'00123F'. A numeric value stored in this format will need to be converted (or edited) prior to printing or displaying.

 * PACKED.. ********************************************************************
 * PACKED.. Packed-Decimal, Unsign, USAGE IS COMP-3
 * PACKED.. Starting... Length = 0003
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 00123Fxx xxxxxxxx xxxxxxxx xxxxxxxx ................ ..?.............
 * PACKED.. Complete... Length = 0003

Numeric Fields, Packed Decimal, Signed, Positive
(Next) (Previous) (Table-of-Contents)

If we take a five digit positive number (00123) and look at how it is stored in memory as an SIGNED, PACKED-DECIMAL number. It will be the same for EBCDIC-encoding and ASCII-encoding. The three bytes in memory will be x'00123C'. A numeric value stored in this format will need to be converted (or edited) prior to printing or displaying.

 * PACKED.. Packed-Decimal, Signed, Positive, USAGE IS COMP-3
 * PACKED.. Starting... Length = 0003
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 00123Cxx xxxxxxxx xxxxxxxx xxxxxxxx ................ ..<.............
 * PACKED.. Complete... Length = 0003

Numeric Fields, Packed Decimal, Signed, Negative
(Next) (Previous) (Table-of-Contents)

If we take a five digit negative number (00123) and look at how it is stored in memory as an SIGNED, PACKED-DECIMAL number. It will be the same for EBCDIC-encoding and ASCII-encoding. The three bytes in memory will be x'00123D'. A numeric value stored in this format will need to be converted (or edited) prior to printing or displaying.

 * PACKED.. Packed-Decimal, Signed, Negative, USAGE IS COMP-3
 * PACKED.. Starting... Length = 0003
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 00123Dxx xxxxxxxx xxxxxxxx xxxxxxxx ................ ..=.............
 * PACKED.. Complete... Length = 0003

Numeric Fields, Packed Decimal, Advantages and Disadvantages
(Next) (Previous) (Table-of-Contents)

The advantages for Packed Decimal fields are as follows.

1. Smaller footprint (each byte contains two digits except for the position containing the sign) in memory or when written to machine readable storage.
2. Relatively easy for programmers to read when testing or debugging programs.
3. The packed-decimal format is the same for the IBM Mainframe (both z/OS and VSE), the AS/400 and Micro Focus COBOL (both Windows and UNIX, both EBCDIC and ASCII).

The disadvantages for Packed Decimal fields are as follows.

1. Requires some editing before printing or displaying.
2. Non-mainframe environments usually do not support this format at the hardware level for arithmetic processing. This format is usually emulated with software for the non-mainframe environments.

The Packed-Decimal format is supported on the mainframe and with Micro Focus COBOL.

The Packed-Decimal or COMP-3 Format, Description and Discussion document provides additional information about this type of field or data string.

Numeric Fields, BINARY or COMP Format
(Next) (Previous) (Table-of-Contents)

Binary fields provide a very efficient way to store numeric fields or data strings in memory or on machine readable storage. On a mainframe this is one of the most efficient ways to do arithmetic calculations and are maintained as 2, 4 or 8 byte fields or data strings (2 bytes is a half-word, 4 bytes is a word or full-word and 8 bytes is a double-word).

It is important to note that many non-mainframe systems allow a binary field to have any length. This will cause a problem when the information is stored in files. Micro Focus provides directives to support the mainframe format for binary fields. Refer to the Micro Focus documentation for more information about the IBMCOMP and NOTRUNC directives.

For Binary fields (or numeric data strings) the byte-order of the high and low order digits must be considered. The terms used to refer to the byte order are "Big Endian" and "Little Endian". The term "Big Endian" is used when the high-order byte of the number is stored in memory at the lowest address, and the low-order byte at the highest address. The term "Little Endian" is used when the low-order byte of the number is stored in memory at the lowest address, and the high-order byte at the highest address. The Mainframe and Micro Focus COBOL uses "Big Endian" for COMP fields. The byte order may become a concern when exporting files with binary fields to a non-mainframe and non-COBOL environment.

Numeric Fields, Binary or COMP, Unsigned
(Next) (Previous) (Table-of-Contents)

If we take a five digit implied, positive number (00123) and look at how it is stored in memory as an UNSIGNED, BINARY number. It will be the same for EBCDIC-encoding and ASCII-encoding if the IBMCOMP and NOTRUNC directives are used with the Micro Focus COBOL compiler. The four bytes in memory will be x'0000007B'. A numeric value stored in this format will need to be converted (or edited) prior to printing or displaying.

 * BINARY.. ********************************************************************
 * BINARY.. Binary Format, No Sign, USAGE IS COMP
 * BINARY.. Starting... Length = 0004
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 0000007B xxxxxxxx xxxxxxxx xxxxxxxx ...#............ ...{............
 * BINARY.. Complete... Length = 0004

Numeric Fields, Binary or COMP, Signed, Positive
(Next) (Previous) (Table-of-Contents)

If we take a five digit positive number (+00123) and look at how it is stored in memory as a SIGNED, BINARY number. It will be the same for EBCDIC-encoding and ASCII-encoding. The four bytes in memory will be x'0000007B'. A numeric value stored in this format will need to be converted (or edited) prior to printing or displaying.

 * BINARY.. Binary Format, Positive, USAGE IS COMP
 * BINARY.. Starting... Length = 0004
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 0000007B xxxxxxxx xxxxxxxx xxxxxxxx ...#............ ...{............
 * BINARY.. Complete... Length = 0004

Numeric Fields, Binary or COMP, Signed, Negative
(Next) (Previous) (Table-of-Contents)

If we take a five digit negative number (-00123) and look at how it is stored in memory as a SIGNED, BINARY number. It will be the same for EBCDIC-encoding and ASCII-encoding. The four bytes in memory will be x'FFFFFF85'. A numeric value stored in this format will need to be converted (or edited) prior to printing or displaying.

 * BINARY.. Binary Format, Negative, USAGE IS COMP
 * BINARY.. Starting... Length = 0004
 *  Offset Hex..... ........ ........ ........ ebcdic.......... ascii...........
 *   1-016 FFFFFF85 xxxxxxxx xxxxxxxx xxxxxxxx ...e............ ................
 * BINARY.. Complete... Length = 0004

Numeric Fields, Binary or COMP, Advantages and Disadvantages
(Next) (Previous) (Table-of-Contents)

The advantages for Binary or COMP fields are as follows.

1. Usually the most efficient format for arithmetic processing..
2. Storage use is more efficient than Zoned-Decimal.

The disadvantages for Binary or COMP fields are as follows.

1. Requires some editing before printing or displaying.
2. Need to be careful with the size of binary fields when moving between the Mainframe and a Windows or UNIX environment.
3. Need to be careful with the Big Endian and Little Endian formats for binary data strings.

The binary format is supported on the mainframe and with Micro Focus COBOL using the IBMCOMP and NOTRUNC compiler directives. It is important to note that an unsigned (or implied positive) field may contain a larger positive number than a signed field. For example, a 2-byte, unsigned binary field could contain values from 0 to 65535. If a 2-byte field were defined as a signed binary field it could contain values from -32767 to +32767 since the high-order bit is used as the sign.

The Binary or COMP Format, Description and Discussion document provides additional information about this type of field or data string.

Convert Packed-Decimal Format
(Next) (Previous) (Table-of-Contents)

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.

Convert, Packed-Decimal to Display
(Next) (Previous) (Table-of-Contents)

This section describes how to convert a packed-decimal field (i.e. PIC S9(5) USAGE IS COMPUTATIONAL) 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.

       WORKING-STORAGE SECTION.
       01  TEXT-PACKED-DECIMAL-SIGN.
           05  SIGN-PACKED-DECIMAL pic S9(5) COMP-3 value 123.
...
       01  TEXT-SIGN-LEAD-SEPARATE.
           05  SIGN-LEAD-SEPARATE  pic S9(5) SIGN LEADING SEPARATE
                                   value 0.
...
...
       PROCEDURE DIVISION.
           add SIGN-PACKED-DECIMAL to ZERO giving SIGN-LEAD-SEPARATE
...

With the preceding example the contents of all the fields will contain the arithmetic value of +00123 after the conversion. The SIGN-PACKED-DECIMAL contains x'00123F'. After the conversion the contents of SIGN-LEAD-SEPARATE will contain x'4EF0F0F1F2F3' for EBCDIC or x'2B3030313233' for ASCII.

Convert, Packed-Decimal to Display with Explicit Decimal Point
(Next) (Previous) (Table-of-Contents)

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 Z ). The resulting field will have a separate leading sign and an explicit decimal point embedded in text string. This field (or data string) may easily be exported to a non-COBOL environment.

       WORKING-STORAGE SECTION.
      *    The following defines a signed, packed-decimal field.
      *    The length of this field is 5 bytes.
       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 6 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

Convert, Packed-Decimal Considerations for EBCDIC and ASCII Encoding
(Next) (Previous) (Table-of-Contents)

The packed-decimal format is supported by Micro Focus COBOL for the Windows and UNIX environments. Micro Focus supports both the EBCDIC-encoding and ASCII-encoding (referred to as CHARSET"EBCDIC" and CHARSET"ASCII" compiler directives). The packed decimal format in the Micro Focus environment is the same for both EBCDIC and ASCII.

A Sample JCL Member
(Next) (Previous) (Table-of-Contents)

The following is the source listing for the sample JCL member used in this exercise. The JCL member may be used to execute the sample program on an IBM Mainframe or a Windows Systems using Micro Focus Mainframe Express or Enterprise Server with the Mainframe Transaction Option (ES/MTO). and the Batch Facility.

//NUMBERJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*                   This program is provided by:                    *
//*                    SimoTime Enterprises, LLC                      *
//*           (C) Copyright 1987-2010 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text    - COBOL and Commonly User Numeric Formats
//* Author  - SimoTime Enterprises
//* Date    - November 11, 2003
//* Version - 06.03.22
//*
//* This set of programs illustrates the use of some of the commonly
//* used numeric formats. It will show actual hex-dump content of
//* the fields along with the field length for the display format
//* (actual digits), the packed format (COMP-3) and the binary (COMP)
//* formats.
//*
//* When running with Net Express the IBMCOMP an NOTRUNC directives
//* will be required to maintain compatability with the mainframe
//* format and field sizes for binary fields.
//*
//* This technique provides for the use of a single set of COBOL
//* source programs that will run on OS/390, Windows or UNIX.
//*
//* This set of programs will run on a Personal Computer with Windows
//* and Micro Focus Mainframe Express or a Mainframe with OS/390.
//*
//* Note: if all three COBOL programs are compiled with a mainframe
//* dialect then the following JCL will work as expected.
//*
//* In some non-mainframe environments it may be a requirement to
//* call the SIMODUMP and SIMOLOGS programs from programs that may
//* be compiled in a mainframe or non-mainframe dialect.
//*
//* The SimoDUMP and SIMOLOGS programs may be compiled with a
//* Micro Focus dialect and the SYSLOG references in this JCL member
//* will be ignored. The mapping of the SYSLOG will be dependent on
//* a SYSLOG environment variable setting.
//*
//*   ************
//*   * NUMBERJ1 *
//*   ********jcl*
//*        *
//*   ************
//*   * SIMOEXEC *
//*   ********exe*
//*        *
//*        *
//*        *
//*   ************     ************
//*   * NUMBERC1 ******* SIMODUMP *
//*   ********cbl*     ********cbl*
//*        *                *
//*        *           ************     ************
//*        *           * SIMOLOGS ******* CONSOLE  *
//*        *           ********cbl*  *  ************
//*        *                         *
//*   ************                   *  ************
//*   *   EOJ    *                   ****  SYSLOG  *
//*   ************                      *******data*
//*
//* *******************************************************************
//* Step-1 This job step will delete a previously created
//*        hex-dump file.
//*
//SYSLOGDT EXEC PGM=IEFBR14
//SYSLOG   DD  DSN=SIMOTIME.DATA.SYSLOG,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=V,LRECL=1055,DSORG=PS)
//*
//* *******************************************************************
//* STEP-2 Allocate a new SYSLOG file.
//* Note:  The LRECL is four (4) bytes bigger than the logical record
//*        that is defined in the program that writes to SYSLOG. This
//*        allows for the four (4) byte Record Descriptor Word (RDW)
//*        that is appended to the front of each record. The program
//*        defines the records as varying in size from 64 to 1,051.
//* Note:  It is necessary to pre-allocate the SYSLOG file. The program
//*        that does the actual file compare will do an "OPEN EXTEND".
//*        If the file is not pre-allocated, an open error will be
//*        posted and the program will execute but will only display
//*        truncated information to SYSOUT.
//SYSLOGCT EXEC PGM=IEFBR14
//SYSLOG   DD  DSN=SIMOTIME.DATA.SYSLOG,DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=V,LRECL=1055,DSORG=PS)
//*
//* *******************************************************************
//* Step-3 Execute the program.
//*
//NUMBERX1 EXEC PGM=NUMBERC1,PARM='SYSOUT(BOTH)'
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//*            The following DD statement is for the logging file.
//SYSLOG   DD  DSN=SIMOTIME.DATA.SYSLOG,DISP=SHR
//SYSOUT   DD  SYSOUT=*
//*

A Sample Command (.CMD) File
(Next) (Previous) (Table-of-Contents)

The following is the source listing for the sample command file (NUMBERE1.CMD) used in this exercise. The command file may be used to execute the sample program on a Windows system using Micro Focus Net Express.

@echo OFF
rem  * *******************************************************************
rem  *                   This program is provided by:                    *
rem  *                    SimoTime Enterprises, LLC                      *
rem  *           (C) Copyright 1987-2010 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  * Text    - Driver for COBOL and Commonly User Numeric Formats
rem  * Author  - SimoTime Enterprises
rem  * Date    - November 11, 2003
rem  * Version - 03.12.15
rem  *
rem  * *******************************************************************
rem  * Step   1 of 2  Set the environment variables...
rem  *
     call Env1PROD
     set syslog=c:\SimoNXE4\AN01\ProdLib1\LOGS\ProdLOG1.LOG
     set CmdName=NUMBERE1
     call SimoNOTE "*******************************************************%CmdName%"
     call SimoNOTE "Starting JobName %CmdName%"
rem  * *******************************************************************
rem  * Step   2 of 2  Execute the Number Format Analysis Program...
rem  *
     run NUMBERC1
rem  *
     call SimoNOTE "Finished JobName %CmdName%"
:End
     call SimoNOTE "Conclude SysLog is %SYSLOG%"
     if not "%1" == "nopause" pause

A Sample COBOL Program
(Next) (Previous) (Table-of-Contents)

The following is the source listing for the sample COBOL program used in this exercise

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    NUMBERC1.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * 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 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 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                                  *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: NUMBERC1.CBL
      *****************************************************************
      *
      * NUMBERC1 - Numeric formats for COBOL.
      *
      *
      * DESCRIPTION
      * -----------
      * This set of programs is used to show the various numeric
      * format used by the COBOL Program Language.
      *
      * This program illustrates the use of some of the commonly
      * used numeric formats. It will show actual hex-dump content of
      * the fields along with the field length for the display format
      * (actual digits), the packed format (COMP-3) and the binary
      * (COMP)
      * formats.
      *
      * The COBOL programs are compiled with the ASSIGN(EXTERNAL)
      * directive. This provides for external file mapping of file
      * names.
      *
      * When running with Net Express the IBMCOMP an NOTRUNC directives
      * will be required to maintain compatability with the mainframe
      * format and field sizes for binary fields.
      *
      * This technique provides for the use of a single COBOL source
      * program that will run on OS/390, Windows or Unix.
      *
      * This program will run on a Personal Computer with Windows
      * and Micro Focus Net Express or Mainframe Express.
      *
      * This program will also run on an IBM Mainframe.
      *
      *****************************************************************
      *
      * MAINTENANCE
      * -----------
      * 1996/03/15 Simmons, Created program.
      * 1996/03/15 Simmons, No changes to date.
      *
      *****************************************************************
      *
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *    ------------------------------------------------------------
       01  SIM-TITLE.
           05  T1 pic X(11) value '* NUMBERC1 '.
           05  T2 pic X(34) value 'Self Study, Numeric Formats COBOL '.
           05  T3 pic X(10) value ' v06.03.22'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* NUMBERC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2010 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* NUMBERC1 '.
           05  C2 pic X(32) value 'Thank you for using this sample '.
           05  C3 pic X(32) value 'by SimoTime Enterprises, LLC    '.
           05  C4 pic X(04) value '    '.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* NUMBERC1 '.
           05  C2 pic X(32) value 'Please send comments or suggesti'.
           05  C3 pic X(32) value 'ons to helpdesk@simotime.com    '.
           05  C4 pic X(04) value '    '.

      *****************************************************************
      *    Buffer used for posting messages to the console.
      *    ------------------------------------------------------------
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* NUMBERC1 '.
           05  MESSAGE-TEXT        pic X(68).

      *****************************************************************
      *    Coding techniques for various numeric formats...
      *    ------------------------------------------------------------
      *    The following shows the full syntax for ZONED-DECIMAL
      *
       01  ZONE-DECIMAL-UNSIGN     pic 9(5)  USAGE IS DISPLAY.
      *
      *    The preceding is normally coded as follows. Since there is
      *    no USAGE clause the default is DISPLAY or ZONED-DECIMAL.
      *
       01  ZONE-DECIMAL-UNSIGN-N   PIC 9(5).
      *
      *    For Working Storage fields a value clause may be added to
      *    minimize or avoid the occurence of a "S0C7" or an error
      *    message of "Invalid value in numeric field" followed
      *    by a program ABEND. The value clause will cause the field
      *    to contain all ZEROES when the program is loaded. If the
      *    value clause is not used as follows the numeric field may
      *    contain spaces.
      *
       01  ZONE-DECIMAL-UNSIGN-NV  PIC 9(5) VALUE 0.

      *    ------------------------------------------------------------
      *    The following is the full syntax for PACKED-DECIMAL.
      *
       01  PACK-DECIMAL-UNSIGN     pic 9(5)  USAGE IS COMPUTATIONAL-3.
      *
      *    The preceding is normally coded as follows.
      *    For the USAGE clause the syntax may be abbreviated. The
      *    "USAGE IS" part of the clause is not neccessary and the
      *    COMPUTATIONAL-3 may be abbreviated as COMP-3.
      *    The VALUE clause is optional and will initialize the
      *    field to ZEROES when the program is started.
      *
       01  PACK-DECIMAL-UNSIGN-N   pic 9(5)  COMP-3 VALUE 0.

      *    ------------------------------------------------------------
      *    The following is the full syntax for BINARY or COMP field.
       01  BINARY-UNSIGN           pic 9(5)  USAGE IS COMPUTATIONAL.
      *
      *    The preceding is normally coded as follows.
      *    The VALUE clause is optional and will initialize the
      *    field to ZEROES when the program is started.
      *
       01  BINARY-UNSIGN-2         pic 9(5)  COMP VALUE 0.

      *****************************************************************
      *    Various numeric formats used by COBOL...
      *    ------------------------------------------------------------
       01  TEXT-ZONED-DECIMAL.
           05  NUMB-ZONED-DECIMAL pic 9(5)  value 123.
       01  TEXT-ZONED-DECIMAL-SIGN.
           05  SIGN-ZONED-DECIMAL pic S9(5) value 123.

       01  TEXT-PACKED-DECIMAL.
           05  NUMB-PACKED-DECIMAL pic 9(5)  COMP-3 value 123.
       01  TEXT-PACKED-DECIMAL-SIGN.
           05  SIGN-PACKED-DECIMAL pic S9(5) COMP-3 value 123.

       01  TEXT-BINARY.
           05  NUMB-BINARY         pic 9(5)  COMP   value 123.
       01  TEXT-BINARY-SIGN.
           05  SIGN-BINARY         pic S9(5) COMP   value 123.

       01  PACK-DECIMAL-S3V2-TEXT.
           05  PACK-DECIMAL-S3V2   pic S9(3)V99 COMP-3 value 6.15.
       01  SLS-S3V2-TEXT.
           05  SLS-S3V2-NUMB       pic S9(3)V99 value 0
                                   SIGN LEADING SEPARATE.

       01  TEXT-SIGN-LEAD-SEPARATE.
           05  SIGN-LEAD-SEPARATE  pic S9(5) value 0
                                   SIGN LEADING SEPARATE.

       01  PRINT-LINE.
           05  FILLER              pic X(8) value 'Edited: '.
           05  PRINT-NUMBER        pic +ZZZ.99.

       01  W-SIGN-06.
           05  W-SIGN              pic X       value SPACE.
           05  W-SIGN-VALUE        pic X(3)    value SPACES.
           05  W-SIGN-POINT        pic X       value '.'.
           02  W-SIGN-DECIMAL      pic X(2)    value SPACES.

       01  FIELD-LENGTH            pic 9(3)    value 0.
       01  FIELD-LENGTH-X          REDEFINES   FIELD-LENGTH
                                   pic X(3).
       COPY PASSDUMP.

      *****************************************************************
       PROCEDURE DIVISION.
           perform FIRST-TIME-LOGIC

      *    ------------------------------------------------------------
      *    Example-01, Show the Hex format for an unsigned, positive
      *    and negative Zoned-Decimal field or USAGE IS DISPLAY...
           perform ZONED-FIELD

      *    ------------------------------------------------------------
      *    Example-02, Show the Hex format for an unsigned, positive
      *    and negative Packed-Decimal field or USAGE IS COMP-3...
           perform PACKED-FIELD

      *    ------------------------------------------------------------
      *    Example-03, Show the Hex format for an unsigned, positive
      *    and negative Binary field or USAGE IS COMP...
           perform BINARY-FIELD

      *    ------------------------------------------------------------
      *    Example-04, Show how to convert a packed-decimal number to a
      *    display number with a separate leading sign character.
      *    Convert from... PIC S9(5) USAGE IS COMPUTATIONAL-3
      *    Convert to..... PIC S9(5) USAGE IS DISPLAY
      *    The resulting field will still be implied decimal. The field
      *    length will be 6-bytes, a single (1-byte) leading sign
      *    and five (5-bytes) digits.
      *
           perform CONVERT-TO-DISPLAY

      *    ------------------------------------------------------------
      *    Example-05, Show how to convert a packed number
      *    with two decimal position and an implied decimal point to a
      *    text string with a separate leading sign character and an
      *    explicit decimal point.
      *    Convert from... PIC S9(5) USAGE IS COMPUTATIONAL-3
      *    Convert to..... PIC X(7)
      *    The resulting field will have an explicit decimal point.
      *    The field length will be 7-bytes, a single (1-byte) leading
      *    sign, three (3-bytes) digits to the left of the decimal, a
      *    single (1-byte) decimal point and two (2-bytes) digits to
      *    the right of the decimal point.
      *
           perform CONVERT-TO-DISPLAY-PIC-X


      *    ------------------------------------------------------------
      *    Example-06, Show how to convert a packed number
      *    with two decimal position and an implied decimal point to a
      *    text string with a separate leading sign character and an
      *    explicit decimal point.
      *    Convert from... PIC S9(3)V99 USAGE IS COMPUTATIONAL-3
      *    Convert to..... PIC +ZZZ.99
      *    The resulting field will have an explicit decimal point.
      *    The field length will be 7-bytes, a single (1-byte) leading
      *    sign, three (3-bytes) digits to the left of the decimal, a
      *    single (1-byte) decimal point and two (2-bytes) digits to
      *    the right of the decimal point.
      *
           perform CONVERT-TO-DISPLAY-PIC-Z

           GOBACK.

      *****************************************************************
       DUMP-ASTERISK-ROW.
           move 'NOTE' to SIMODUMP-REQUEST
           move all '*' to SIMODUMP-BUFFER
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           exit.

      *****************************************************************
       DUMP-ASTERISK-ROW-2X.
           perform DUMP-ASTERISK-SINGLE
           perform DUMP-ASTERISK-ROW
           exit.

      *****************************************************************
       DUMP-ASTERISK-SINGLE.
           move 'NOTE' to SIMODUMP-REQUEST
           move SPACES to SIMODUMP-BUFFER
           move '*'    to SIMODUMP-BUFFER(1:1)
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           exit.

      *****************************************************************
      * Descirbe the format for a zoned-decimal field...
      *****************************************************************
       ZONED-FIELD.
      *    Prepare to show the Number...
           move 'ZONED...' to SIMODUMP-DUMP-ID
           perform DUMP-ASTERISK-ROW-2X
           move 'Zoned-Decimal, Unsign, USAGE IS DISPLAY'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the field...
           add length of TEXT-ZONED-DECIMAL
               to ZERO giving SIMODUMP-LENGTH
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-ZONED-DECIMAL to SIMODUMP-BUFFER
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Zoned-Decimal, Signed, Positive, USAGE IS DISPLAY'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the positive value...
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-ZONED-DECIMAL-SIGN to SIMODUMP-BUFFER
           add length of TEXT-ZONED-DECIMAL-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Zoned-Decimal, Signed, Negative, USAGE IS DISPLAY'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           move SPACES         to SIMODUMP-BUFFER
           subtract SIGN-ZONED-DECIMAL from ZERO
             giving SIGN-ZONED-DECIMAL
           move TEXT-ZONED-DECIMAL-SIGN to SIMODUMP-BUFFER
           add length of TEXT-ZONED-DECIMAL-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           exit.

      *****************************************************************
      * How to convert to a display field from packed or binary...
      *****************************************************************
       CONVERT-TO-DISPLAY.
           move 'CONVERT1' to SIMODUMP-DUMP-ID
           perform DUMP-ASTERISK-ROW-2X
           move 'Convert from Packed to Display'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA

           move 'The PACKED-DECIMAL field to be converted'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA

           add length of TEXT-PACKED-DECIMAL-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-PACKED-DECIMAL-SIGN to SIMODUMP-BUFFER
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'The DISPLAY field created by the conversion routine'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA

      *    Show the hexadecimal content of the unsigned value...
           add SIGN-PACKED-DECIMAL to ZERO giving SIGN-LEAD-SEPARATE
           add length of SIGN-LEAD-SEPARATE
               to ZERO giving SIMODUMP-LENGTH
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-SIGN-LEAD-SEPARATE to SIMODUMP-BUFFER
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           exit.

      *****************************************************************
      * How to convert to a display field from packed or binary...
      *****************************************************************
       CONVERT-TO-DISPLAY-PIC-X.
           move 'CONVERT2' to SIMODUMP-DUMP-ID
           perform DUMP-ASTERISK-ROW-2X
           move 'Convert from Packed to Text, Decimal Point Value'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the unsigned value...
           add PACK-DECIMAL-S3V2 to ZERO giving SLS-S3V2-NUMB

           move SLS-S3V2-TEXT(1:1) to W-SIGN
           move SLS-S3V2-TEXT(2:3) to W-SIGN-VALUE
           move SLS-S3V2-TEXT(5:2) to W-SIGN-DECIMAL

           add length of W-SIGN-06
               to ZERO giving SIMODUMP-LENGTH
           move SPACES         to SIMODUMP-BUFFER
           move W-SIGN-06      to SIMODUMP-BUFFER
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           exit.

      *****************************************************************
      * How to convert to a display field from packed or binary...
      *****************************************************************
       CONVERT-TO-DISPLAY-PIC-Z.
           move 'CONVERT3' to SIMODUMP-DUMP-ID
           perform DUMP-ASTERISK-ROW-2X
           move 'Positive Packed to Edited Text with Decimal Point'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA

      *    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

           add length of PRINT-LINE
               to ZERO giving SIMODUMP-LENGTH
           move SPACES      to SIMODUMP-BUFFER
           move PRINT-LINE  to SIMODUMP-BUFFER
           move 'DUMP'      to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Negative Packed to Edited Text with Decimal Point'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           add -4.56 to ZERO giving PACK-DECIMAL-S3V2
           move PACK-DECIMAL-S3V2 to PRINT-NUMBER
           inspect PRINT-NUMBER replacing all SPACE by ZERO
           move PRINT-LINE  to SIMODUMP-BUFFER
           move 'DUMP'      to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           exit.

      *****************************************************************
      * Descirbe the format for a packed-decimal field...
      *****************************************************************
       PACKED-FIELD.
      *    Prepare to show the Number...
           move 'PACKED..' to SIMODUMP-DUMP-ID
           perform DUMP-ASTERISK-ROW-2X
           move 'Packed-Decimal, Unsign, USAGE IS COMP-3'
             to SIMODUMP-BUFFER
           move 'NOTE'         to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the unsigned value...
           add length of TEXT-PACKED-DECIMAL
               to ZERO giving SIMODUMP-LENGTH
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-PACKED-DECIMAL to SIMODUMP-BUFFER
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Packed-Decimal, Signed, Positive, USAGE IS COMP-3'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the positive value...
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-PACKED-DECIMAL-SIGN to SIMODUMP-BUFFER
           add length of TEXT-PACKED-DECIMAL-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Packed-Decimal, Signed, Negative, USAGE IS COMP-3'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           move SPACES         to SIMODUMP-BUFFER
           subtract SIGN-PACKED-DECIMAL from ZERO
             giving SIGN-PACKED-DECIMAL
           move TEXT-PACKED-DECIMAL-SIGN to SIMODUMP-BUFFER
           add length of TEXT-PACKED-DECIMAL-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           exit.

      *****************************************************************
      * Descirbe the format for a binary field...
      *****************************************************************
       BINARY-FIELD.
      *    Prepare to show the Number...
           move 'BINARY..' to SIMODUMP-DUMP-ID
           perform DUMP-ASTERISK-ROW-2X
           move 'Binary Format, No Sign, USAGE IS COMP'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the field...
           add length of TEXT-BINARY
               to ZERO giving SIMODUMP-LENGTH
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-BINARY to SIMODUMP-BUFFER
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Binary Format, Positive, USAGE IS COMP'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
      *    Show the hexadecimal content of the positive value...
           move SPACES         to SIMODUMP-BUFFER
           move TEXT-BINARY-SIGN to SIMODUMP-BUFFER
           add length of TEXT-BINARY-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           move 'Binary Format, Negative, USAGE IS COMP'
             to SIMODUMP-BUFFER
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           move SPACES         to SIMODUMP-BUFFER
           subtract SIGN-BINARY from ZERO
             giving SIGN-BINARY
           move TEXT-BINARY-SIGN to SIMODUMP-BUFFER
           add length of TEXT-BINARY-SIGN
               to ZERO giving SIMODUMP-LENGTH
           move 'DUMP'         to SIMODUMP-REQUEST
           call 'SIMODUMP'  using SIMODUMP-PASS-AREA

           exit.

      *****************************************************************
       FIRST-TIME-LOGIC.
           perform Z-POST-COPYRIGHT.
           move 'BOTH' to SIMODUMP-SYSOUT
           move 'HIDE' to SIMODUMP-COPYRIGHT
           exit.

      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************
       Z-POST-CONSOLE-MESSAGE.
           display MESSAGE-BUFFER upon console
           move SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.

      *****************************************************************
       Z-POST-NOTE-AND-CLEAR.
           move 'NOTE' to SIMODUMP-REQUEST
           call 'SIMODUMP' using SIMODUMP-PASS-AREA
           move SPACES to SIMODUMP-BUFFER
           exit.

      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01 upon console
           display SIM-THANKS-02 upon console
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this session is to describe the techniques and effort involved to compare two data file on a Windows platform using Micro Focus COBOL and Micro Focus formatted files. This session is available as an on site class or an on line, self-study course.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

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.

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLNumericFieldIntoInternalStructureZip as a Z-Pack. The Z-Packs provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download. Please view the complete list of SimoTime Z-Pack Examples at http://www.simotime.com/sim4dzip.htm.

The Home Page for The SimoPATH Series  is the starting point to view information about training sessions and learning materials available from SimoTime Enterprises.

The SimoTime Home Page is the starting point to review all the information available from SimoTime Enterprises.

The following table is a list of other examples available from SimoTime that describe the various techniques for managing mainframe-oriented, numeric formats on an IBM Mainframe or with Micro Focus COBOL.

Link Name Description
number01 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.
Note: This page is currently active.
databn01 This is a White Paper that describes the usage and format of BINARY fields (or "USAGE IS COMPUTATIONAL" in COBOL terminology).
datapk01 This is a White Paper that describes the usage and format of PACKED-DECIMAL fields (or "USAGE IS COMPUTATIONAL-3" in COBOL terminology).
datazd01 This is a White Paper that describes the usage and format of ZONED-DECIMAL fields (or "USAGE IS DISPLAY" in COBOL terminology).

The following chart provides a list of the sample COBOL programs that focus on processing numeric fields.

HTML Tag Description
cblnum01 This is an example of how COBOL can test that a data field contains a valid numeric value. It also illustrates how to redefine a numeric field and then scan the field from left to right testing for a digit in each position.
cblraz01 This suite of programs provides an example of a routine that will Right Adjust (or Right Justify) a text string within a numeric field and fill the left-most or high-order bytes with zeroes.
cbltxn01 This suite of programs provides an example of how a COBOL program calls a COBOL routine to create a 150-character, English-oriented text data string from a 12-digit numeric field. For example, if the numeric field contains 000000001234 then a text string is created with the following information, One-Thousand-Two-Hundred-Thirty-Four
nbrtyp01 This suite of example programs will describe the use, format and size of some of the commonly used numeric fields of the COBOL programming language. This example also illustrates how to redefine a numeric field and how to display the actual hexadecimal content of a numeric field.
number01 This document is an introduction to the various numeric formats used by COBOL and the IBM mainframe systems The session will describe three of the popular numeric formats used with COBOL and IBM Mainframe systems. The discussions include further detail about the issues and concerns of unsigned (or implied positive) numbers, signed (positive or negative) numbers and decimal or whole numbers. A sample of how to convert non-print formats to display or print formats is included along with a sample COBOL program.
numbug01 The challenge with this program is that it is expected to process the various numeric items in the same manner as the mainframe. For example, a zoned-decimal field that contains leading spaces should not cause an ABEND (i.e. 163 error on Micro Focus) but should treat the leading spaces as zeroes and complete the arithmetic calculation. However, a packed-decimal field that contains non-numeric values would issue a S0C7 (referred to as a sock-seven) on the mainframe and should issue a 163 error in the Micro Focus environment.

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.

The SimoREC1 Utility Program has the capability of generating a callable COBOL program that will do the conversion of a data string between EBCDIC and ASCII. The generated COBOL source code or the conversion tables may be viewed or modified to meet unique requirements. The generated program may be called by an I/O program generated by SimoZAPS.

This item will provide a link to  an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.

This document provides a quick summary of the  File Status Key  for VSAM data sets and QSAM files.

Check out  The VSAM - QSAM Connection  for more examples of mainframe VSAM and QSAM accessing techniques and sample code.

The hexadecimal dump of the parameter-buffer uses the same technique as describe in another SimoTime example that describes the dumping of a data string using COBOL. The name of the member that does the actual hexadecimal dump is called SimoDUMP. A copy file (PASSDUMP.CPY) is provided for defining the pass area.

You may view the complete list of examples at http://www.simotime.com/sim4dzip.htm and many are available as a SimoTime Z-Pack (a zip file package with sample source code, data and documentation).

Note: You must be attached to the Internet to download a Z-Pack or view the list.

Glossary of Terms
(Next) (Previous) (Table-of-Contents)

Check out  The SimoTime Glossary  for a list of terms and definitions used in the documents provided by SimoTime.

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

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.

About SimoTime Enterprises
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises 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


Return-to-Top
Copyright © 1987-2010 SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com