cobolpacked-decimal

Physical storage of COBOL PACKED-DECIMAL field on Little Endian machines


I understand the shape of the bytes behind a PACKED-DECIMAL number when on a Big-Endian machine. What I have not been able to discover is what shape would those bytes take on a Little-Endian machine.

Note: The reason I believe there does exist a separate format for such is because the IBM MQ Encoding field has the following values:-

Of MQENC_DECIMAL_REVERSED it simply says:-

Packed-decimal integers are represented in the same way as MQENC_DECIMAL_NORMAL, but with the bytes arranged in reverse order. The bits within each byte are arranged in the same way as MQENC_DECIMAL_NORMAL.

Can anyone corroborate or refute this description?

For example, the number +123.45 stored in a PIC 9(3)V99 COMP-3 would have the following bytes:-

12 34 5C

The above quote suggests to me that if in reversed, the same packed decimal number would be represented on a Little-Endian machine as:-

5C 34 12

N.B. I have not tagged this question with ibm-mq, as I don't really think the crux of my question has anything to do with IBM MQ. It is simply the reason I am asking.


Solution

  • It looks like packed data is stored in "normal" byte order.

    The following program was compiled with OpenCOBOL 1.1.0 on Ubuntu 16.04 on a Lenovo ThinkPad...

       ID Division.
       Program-ID. testcmp3.
       Environment Division.
       Input-Output Section.
       File-Control.
           Select OUTPUT01 Assign To './output01'
               Status OUTPUT01-STATUS.
       Data Division.
       File Section.
       FD  OUTPUT01
           Record 16
           Block 0
           Recording F.
       01  OUTPUT01-REC PIC X(016).
    
       Working-Storage Section.
       01  CONSTANTS.
           05  MYNAME             PIC X(008) VALUE 'testcmp3'.
    
       01  WS-OUTPUT01-REC.
           05  WS-OUT-S94COMP     PIC S9(004) COMP   VALUE +0.
           05  FILLER             PIC X(001)         VALUE HIGH-VALUES.
           05  WS-OUT-S95COMP3    PIC S9(005) COMP-3 VALUE +0.
           05  FILLER             PIC X(008)         VALUE SPACES.
    
       01  WORK-AREAS.
           05  OUTPUT01-STATUS    PIC X(002)         VALUE ZEROES.
    
       Procedure Division.
       OPEN OUTPUT OUTPUT01
       IF OUTPUT01-STATUS NOT = '00'
           DISPLAY 
             MYNAME 
             ' open of OUTPUT01 status = ' 
             OUTPUT01-STATUS
       END-IF
    
       PERFORM 100-WRITE 100 TIMES
    
       CLOSE OUTPUT01
       STOP RUN.
    
       100-WRITE.
           WRITE OUTPUT01-REC FROM WS-OUTPUT01-REC
           ADD 1 TO WS-OUT-S94COMP
           ADD 1 TO WS-OUT-S95COMP3
           .
    

    ...with the option binary-byteorder set to native.

    The resulting file, displayed with the hexdump program, follows.

    00000000  00 00 ff 00 00 0c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000010  01 00 ff 00 00 1c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000020  02 00 ff 00 00 2c 20 20  20 20 20 20 20 20 20 20  |.....,          |
    00000030  03 00 ff 00 00 3c 20 20  20 20 20 20 20 20 20 20  |.....<          |
    00000040  04 00 ff 00 00 4c 20 20  20 20 20 20 20 20 20 20  |.....L          |
    00000050  05 00 ff 00 00 5c 20 20  20 20 20 20 20 20 20 20  |.....\          |
    00000060  06 00 ff 00 00 6c 20 20  20 20 20 20 20 20 20 20  |.....l          |
    00000070  07 00 ff 00 00 7c 20 20  20 20 20 20 20 20 20 20  |.....|          |
    00000080  08 00 ff 00 00 8c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000090  09 00 ff 00 00 9c 20 20  20 20 20 20 20 20 20 20  |......          |
    000000a0  0a 00 ff 00 01 0c 20 20  20 20 20 20 20 20 20 20  |......          |
    000000b0  0b 00 ff 00 01 1c 20 20  20 20 20 20 20 20 20 20  |......          |
    000000c0  0c 00 ff 00 01 2c 20 20  20 20 20 20 20 20 20 20  |.....,          |
    000000d0  0d 00 ff 00 01 3c 20 20  20 20 20 20 20 20 20 20  |.....<          |
    000000e0  0e 00 ff 00 01 4c 20 20  20 20 20 20 20 20 20 20  |.....L          |
    000000f0  0f 00 ff 00 01 5c 20 20  20 20 20 20 20 20 20 20  |.....\          |
    00000100  10 00 ff 00 01 6c 20 20  20 20 20 20 20 20 20 20  |.....l          |
    00000110  11 00 ff 00 01 7c 20 20  20 20 20 20 20 20 20 20  |.....|          |
    00000120  12 00 ff 00 01 8c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000130  13 00 ff 00 01 9c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000140  14 00 ff 00 02 0c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000150  15 00 ff 00 02 1c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000160  16 00 ff 00 02 2c 20 20  20 20 20 20 20 20 20 20  |.....,          |
    00000170  17 00 ff 00 02 3c 20 20  20 20 20 20 20 20 20 20  |.....<          |
    00000180  18 00 ff 00 02 4c 20 20  20 20 20 20 20 20 20 20  |.....L          |
    00000190  19 00 ff 00 02 5c 20 20  20 20 20 20 20 20 20 20  |.....\          |
    000001a0  1a 00 ff 00 02 6c 20 20  20 20 20 20 20 20 20 20  |.....l          |
    000001b0  1b 00 ff 00 02 7c 20 20  20 20 20 20 20 20 20 20  |.....|          |
    000001c0  1c 00 ff 00 02 8c 20 20  20 20 20 20 20 20 20 20  |......          |
    000001d0  1d 00 ff 00 02 9c 20 20  20 20 20 20 20 20 20 20  |......          |
    000001e0  1e 00 ff 00 03 0c 20 20  20 20 20 20 20 20 20 20  |......          |
    000001f0  1f 00 ff 00 03 1c 20 20  20 20 20 20 20 20 20 20  |......          |
    00000200  20 00 ff 00 03 2c 20 20  20 20 20 20 20 20 20 20  | ....,          |
    00000210  21 00 ff 00 03 3c 20 20  20 20 20 20 20 20 20 20  |!....<          |
    00000220  22 00 ff 00 03 4c 20 20  20 20 20 20 20 20 20 20  |"....L          |
    00000230  23 00 ff 00 03 5c 20 20  20 20 20 20 20 20 20 20  |#....\          |
    00000240  24 00 ff 00 03 6c 20 20  20 20 20 20 20 20 20 20  |$....l          |
    00000250  25 00 ff 00 03 7c 20 20  20 20 20 20 20 20 20 20  |%....|          |
    00000260  26 00 ff 00 03 8c 20 20  20 20 20 20 20 20 20 20  |&.....          |
    00000270  27 00 ff 00 03 9c 20 20  20 20 20 20 20 20 20 20  |'.....          |
    00000280  28 00 ff 00 04 0c 20 20  20 20 20 20 20 20 20 20  |(.....          |
    00000290  29 00 ff 00 04 1c 20 20  20 20 20 20 20 20 20 20  |).....          |
    000002a0  2a 00 ff 00 04 2c 20 20  20 20 20 20 20 20 20 20  |*....,          |
    000002b0  2b 00 ff 00 04 3c 20 20  20 20 20 20 20 20 20 20  |+....<          |
    000002c0  2c 00 ff 00 04 4c 20 20  20 20 20 20 20 20 20 20  |,....L          |
    000002d0  2d 00 ff 00 04 5c 20 20  20 20 20 20 20 20 20 20  |-....\          |
    000002e0  2e 00 ff 00 04 6c 20 20  20 20 20 20 20 20 20 20  |.....l          |
    000002f0  2f 00 ff 00 04 7c 20 20  20 20 20 20 20 20 20 20  |/....|          |
    00000300  30 00 ff 00 04 8c 20 20  20 20 20 20 20 20 20 20  |0.....          |
    00000310  31 00 ff 00 04 9c 20 20  20 20 20 20 20 20 20 20  |1.....          |
    00000320  32 00 ff 00 05 0c 20 20  20 20 20 20 20 20 20 20  |2.....          |
    00000330  33 00 ff 00 05 1c 20 20  20 20 20 20 20 20 20 20  |3.....          |
    00000340  34 00 ff 00 05 2c 20 20  20 20 20 20 20 20 20 20  |4....,          |
    00000350  35 00 ff 00 05 3c 20 20  20 20 20 20 20 20 20 20  |5....<          |
    00000360  36 00 ff 00 05 4c 20 20  20 20 20 20 20 20 20 20  |6....L          |
    00000370  37 00 ff 00 05 5c 20 20  20 20 20 20 20 20 20 20  |7....\          |
    00000380  38 00 ff 00 05 6c 20 20  20 20 20 20 20 20 20 20  |8....l          |
    00000390  39 00 ff 00 05 7c 20 20  20 20 20 20 20 20 20 20  |9....|          |
    000003a0  3a 00 ff 00 05 8c 20 20  20 20 20 20 20 20 20 20  |:.....          |
    000003b0  3b 00 ff 00 05 9c 20 20  20 20 20 20 20 20 20 20  |;.....          |
    000003c0  3c 00 ff 00 06 0c 20 20  20 20 20 20 20 20 20 20  |<.....          |
    000003d0  3d 00 ff 00 06 1c 20 20  20 20 20 20 20 20 20 20  |=.....          |
    000003e0  3e 00 ff 00 06 2c 20 20  20 20 20 20 20 20 20 20  |>....,          |
    000003f0  3f 00 ff 00 06 3c 20 20  20 20 20 20 20 20 20 20  |?....<          |
    00000400  40 00 ff 00 06 4c 20 20  20 20 20 20 20 20 20 20  |@....L          |
    00000410  41 00 ff 00 06 5c 20 20  20 20 20 20 20 20 20 20  |A....\          |
    00000420  42 00 ff 00 06 6c 20 20  20 20 20 20 20 20 20 20  |B....l          |
    00000430  43 00 ff 00 06 7c 20 20  20 20 20 20 20 20 20 20  |C....|          |
    00000440  44 00 ff 00 06 8c 20 20  20 20 20 20 20 20 20 20  |D.....          |
    00000450  45 00 ff 00 06 9c 20 20  20 20 20 20 20 20 20 20  |E.....          |
    00000460  46 00 ff 00 07 0c 20 20  20 20 20 20 20 20 20 20  |F.....          |
    00000470  47 00 ff 00 07 1c 20 20  20 20 20 20 20 20 20 20  |G.....          |
    00000480  48 00 ff 00 07 2c 20 20  20 20 20 20 20 20 20 20  |H....,          |
    00000490  49 00 ff 00 07 3c 20 20  20 20 20 20 20 20 20 20  |I....<          |
    000004a0  4a 00 ff 00 07 4c 20 20  20 20 20 20 20 20 20 20  |J....L          |
    000004b0  4b 00 ff 00 07 5c 20 20  20 20 20 20 20 20 20 20  |K....\          |
    000004c0  4c 00 ff 00 07 6c 20 20  20 20 20 20 20 20 20 20  |L....l          |
    000004d0  4d 00 ff 00 07 7c 20 20  20 20 20 20 20 20 20 20  |M....|          |
    000004e0  4e 00 ff 00 07 8c 20 20  20 20 20 20 20 20 20 20  |N.....          |
    000004f0  4f 00 ff 00 07 9c 20 20  20 20 20 20 20 20 20 20  |O.....          |
    00000500  50 00 ff 00 08 0c 20 20  20 20 20 20 20 20 20 20  |P.....          |
    00000510  51 00 ff 00 08 1c 20 20  20 20 20 20 20 20 20 20  |Q.....          |
    00000520  52 00 ff 00 08 2c 20 20  20 20 20 20 20 20 20 20  |R....,          |
    00000530  53 00 ff 00 08 3c 20 20  20 20 20 20 20 20 20 20  |S....<          |
    00000540  54 00 ff 00 08 4c 20 20  20 20 20 20 20 20 20 20  |T....L          |
    00000550  55 00 ff 00 08 5c 20 20  20 20 20 20 20 20 20 20  |U....\          |
    00000560  56 00 ff 00 08 6c 20 20  20 20 20 20 20 20 20 20  |V....l          |
    00000570  57 00 ff 00 08 7c 20 20  20 20 20 20 20 20 20 20  |W....|          |
    00000580  58 00 ff 00 08 8c 20 20  20 20 20 20 20 20 20 20  |X.....          |
    00000590  59 00 ff 00 08 9c 20 20  20 20 20 20 20 20 20 20  |Y.....          |
    000005a0  5a 00 ff 00 09 0c 20 20  20 20 20 20 20 20 20 20  |Z.....          |
    000005b0  5b 00 ff 00 09 1c 20 20  20 20 20 20 20 20 20 20  |[.....          |
    000005c0  5c 00 ff 00 09 2c 20 20  20 20 20 20 20 20 20 20  |\....,          |
    000005d0  5d 00 ff 00 09 3c 20 20  20 20 20 20 20 20 20 20  |]....<          |
    000005e0  5e 00 ff 00 09 4c 20 20  20 20 20 20 20 20 20 20  |^....L          |
    000005f0  5f 00 ff 00 09 5c 20 20  20 20 20 20 20 20 20 20  |_....\          |
    00000600  60 00 ff 00 09 6c 20 20  20 20 20 20 20 20 20 20  |`....l          |
    00000610  61 00 ff 00 09 7c 20 20  20 20 20 20 20 20 20 20  |a....|          |
    00000620  62 00 ff 00 09 8c 20 20  20 20 20 20 20 20 20 20  |b.....          |
    00000630  63 00 ff 00 09 9c 20 20  20 20 20 20 20 20 20 20  |c.....          |
    00000640
    

    The draft standard document ISO/IEC CD2.1 1989:202x says of the USAGE PACKED-DECIMAL phrase...

    The USAGE PACKED-DECIMAL clause specifies that a radix of 10 is used to represent a numeric item in the storage of the computer. Furthermore, this clause specifies that each digit position shall occupy the minimum possible configuration in computer storage. Each implementor specifies the precise effect of the USAGE PACKED-DECIMAL clause upon the alignment and representation of the data item in the storage of the computer, including the representation of any algebraic sign. Sufficient computer storage shall be allocated by the implementor to contain the maximum range of values implied by the associated decimal picture character-string. If the WITH NO SIGN phrase is specified the representation of the data item in the storage of the computer reserves no storage for representing any sign value. The PICTURE character string of the data item shall not contain the symbol ā€˜Sā€™; the data item is always considered to have a zero, or positive value.