Representation of numerics on a mainframe

I now work with a mainframe. I realised once more that numeric variables have different formats on a mainframe. As we do not always have a clear description, we should somehow recognise how the data are stored. Let us first show how numeric data can be stored.
As an example, I take the number 123.

mainframe repres

In the upper row, we see the number 123. This is how we see externally this number. In the two rows below, we see the internal format: F1F2F3. This is the most common format: PIC(n) display in Cobol terminology. When we use SAS, we must use the s370fzdu6.2 format, the so-called unsigned zoned decimal.

This brought me the idea to show 6 different internal formats of 123, along with the Cobol format and the SAS format.

Let me give you the results:

How does 123 look           Likely Cobol representation	                        SAS format
internally?     externally
F0F0F0F1F2F3	000123      PIC 9(n) DISPLAY	                                s370fzdu6.2
C0F0F0F1F2F3	{00123      PIC S9(n) DISPLAY SIGN LEADING	                S370FZDL6.2
4EF0F0F1F2F3	+00123      PIC S9(n) DISPLAY SIGN LEADING SEPARATE	        S370FZDS6.2
F0F0F1F2F34E	00123+      PIC S9(n) DISPLAY SIGN TRAILING SEPARATE	        S370FZDT6.2
00000000123C	            pic S(9)  comp-3	                                s370fpd6.2
00000000123F	            PIC 9(n) PACKED-DECIMAL	                        s370fpdu6.2

In fact, two different formats are used:

  • Zoned decimals where digits can be internally seen as a combination of F and a digit. Hence 7 is stored as F7. Externally, we see the 7. The only difference between the different zoned decimal representation is to whether a sign is available(the +) and where it is placed: at a trailing position or at a leading position.
  • Packed decimals where digit are stored efficiently as one byte is used to internally store two digits. The result is we can recognise 123 in the internal format quite easily (in 00000000123C). However the external representation doesn’t make much sense.