Skip to content
systemcoding.dev
Mainframe

Inspect Packed Decimal Fields in a Dataset With ISPF HEX ON

Use ISPF HEX ON in edit or browse to read COMP-3 packed decimal fields in a dataset, decode sign nibbles by hand, and find the record that causes an S0C7.

7 min read
Summarize in AI
Flat illustration of a magnifier over lines of a log, with the Linux, Rust and C++ logos.

A COBOL program abends with an S0C7 on a record, and you open the input file in ISPF to find the bad one. The screen shows rows of characters, and where the packed decimal fields should be there are odd symbols or blanks. A COMP-3 field is not text: its bytes hold two decimal digits each, and most of them are not printable characters. To read it you need to see the bytes themselves, and ISPF has a command for that. This post shows how to turn on hexadecimal display in ISPF browse and edit on z/OS 3.1, how to read a packed decimal field from the two lines of hex digits, how to decode the sign, and how to search a file for records whose packed fields are invalid. It supports the diagnosis in fix an S0C7 data exception in a COBOL batch job.

How packed decimal is stored

A packed decimal, COMP-3 in COBOL, stores two decimal digits per byte, one in each half-byte (nibble), with the last nibble holding the sign. A field of PIC S9(7)V99 COMP-3 has nine digits and a sign, which is ten nibbles, so it takes five bytes. The value 12345.67 is stored as:

Text
digits:  0 0 1 2 3 4 5 6 7  +sign
nibbles: 0 0 | 1 2 | 3 4 | 5 6 | 7 C
bytes:   00     12    34    56    7C

The implied decimal point, from the V in the picture, is not stored: the nine digits 001234567 are read as 0012345.67. The sign nibble is C for positive, D for negative and F for unsigned, which is also treated as positive. A packed field is valid when every digit nibble is 0 to 9 and the last nibble is a sign. Anything else causes an S0C7 when the program uses the field in arithmetic.

Turning HEX on

In an ISPF edit or browse session, type HEX ON on the command line and press Enter. Each line of data is then shown with two extra lines beneath it, the hex zone and hex digit lines, which together give the hexadecimal value of every byte. HEX OFF turns it off. By default the two lines are stacked under the character line, which is the vertical format, and HEX ON DATA or HEX ON VERT choose the layout (the exact options differ slightly between edit and browse, and HEX DATA shows the hex in a single dump-style layout).

Take a file of FB records of 80 bytes, where each record begins with a five-character customer code followed by a packed balance of five bytes. For the balance 12345.67 the five bytes are 00 12 34 56 7C, and the customer code C0001 is the bytes C3 F0 F0 F0 F1. With HEX ON the first record looks like this, with the packed field showing as unprintable characters, shown here as periods:

Text
Command ===> HEX ON
****** ***************************** Top of Data ******************************
000001 C0001.....
       CFFFF01357
       300010246C

The first line is the data as characters. The second line gives the zone of each byte, its upper nibble, and the third gives the digit, its lower nibble. Read them one column at a time. The first column is C over 3, the byte C3, which is the letter C. The next four columns are F0, F0, F0 and F1, the digits 0, 0, 0 and 1. The last five columns are the packed field: zone line 0 1 3 5 7, digit line 0 2 4 6 C.

Read the packed field by taking the zone nibble then the digit nibble of each byte, left to right: 0 0, 1 2, 3 4, 5 6, 7 C. Together the digits are 0 0 1 2 3 4 5 6 7 and the final C is the sign, so the value is positive 12345.67 when the picture's decimal point is applied. The skill is reading the two lines as a pair of nibbles per byte.

Finding the bad record

An S0C7 from a packed field means some record holds a byte pair that breaks the rules. With HEX ON, scan for the usual signs.

  • Spaces in a packed position. The zone and digit lines show 4 and 0 for each byte, 40 40 40 40 40, the EBCDIC blank. Every nibble is 4 or 0, and the last nibble 0 is not a sign. This is the most common bad value, from a blank field.

  • Low-values. Zone and digit lines show 0 and 0: 00 00 00 00 00. The digits are valid and the last nibble 0 is not a sign, so arithmetic abends. Some programs initialize with low-values and test for them.

  • A sign nibble that is not a sign. A last nibble between 0 and 9, as in 12 34 56 78 91, is a digit and not a sign. The valid signs are A to F.

  • A digit nibble above 9. A nibble A to F in a digit position, as in 1A 34 5C, is invalid.

  • Text in the field. A few bytes that decode as EBCDIC letters, the sign of a layout that is off by some bytes, so a name sits where a number should be.

To find them in a large file without scanning, use the FIND command with a hexadecimal string. In ISPF, a hexadecimal search string is written X'...':

Text
Command ===> FIND X'4040404040' ALL

This finds every occurrence of five EBCDIC blanks, and the number of matches shows in the short message. ISPF also has picture strings for character classes: P'#' matches any numeric character, P'-' any non-numeric character, and P'.' any character that cannot be displayed, which is a quick way to land on packed and binary bytes. A column range narrows the search, as in FIND X'4040' 21 25 ALL, which looks only in columns 21 through 25. The strings are documented in the ISPF Edit and Edit Macros manual.

For binary-heavy records a column-range find on packed data is the practical approach. If the record layout is known, a REXX edit macro or a short COBOL program that checks IS NUMERIC on each packed field and prints the record number is more reliable. The ISPF method is for a first look.

Zoned decimal and binary

HEX ON also reads zoned decimal, PIC 9(5), which is stored as one digit per byte with the zone F. The value 125 is F1 F2 F5, and a signed zoned number has the sign in the zone of the last byte: F1 F2 C5 for +125 and F1 F2 D5 for -125. In the hex lines, a zoned field shows F on the zone line for each digit except possibly the last, and the digit line shows the number: FFC over 125, which reads +125.

Binary fields, COMP, show as the bytes of a two's-complement integer in big-endian order: the value 1,000 in a PIC S9(9) COMP is 00 00 03 E8. A negative number has the high bit set, so -1 is FF FF FF FF. With HEX ON you can read these as a hexadecimal number, which is easy for small values and tedious for large ones.

Editing with care

In edit mode, the hex lines are editable: you can change a nibble by typing over the digit in the hex line. That is a way to repair a bad record, setting the sign nibble of a packed field to C, and it is one to use carefully. Make a copy of the dataset first, and change only the nibbles you mean to. In a production dataset, the repair is a change that should go through your site's procedures, since a hand-edited record leaves no record of what changed. In browse mode, nothing can be altered.

Records with variable length, RECFM=VB, show the four-byte record descriptor word in front of the data in hex, and the columns of the fields are offset by four. Check the record length in the COLS ruler and the dataset information before counting positions, as covered in check a dataset's extents, used space and volumes with ISPF data set information.

Using the layout

Knowing the positions makes the scan precise. If the copybook says the packed balance starts at byte 6 of the record and is five bytes long, display with COLS to find columns 6 to 10, and read the zone and digit lines under those columns only. A column ruler helps: type COLS on the command line to show it. For the first record, the field is under columns 6 to 10, and the pair of hex lines under them is the field. Compare to the layout in the program's data map, which gives the displacement of every field.

When ISPF is not the tool

ISPF suits a look at a record or a few. For thousands of records, write a small program or use DFSORT's INCLUDE with a numeric class test, for example INCLUDE COND=(6,5,PD,EQ,6,5,PD) as a trick that fails to select records whose packed field is invalid, and ICETOOL to count them. For a repeated need, a validation job that reads the file with a COBOL program and IS NUMERIC tests, and writes a report of the rejects, is the lasting answer.

The HEX, FIND and COLS commands are documented in the ISPF Edit and Edit Macros manual on the IBM Documentation site.

Also inDebugging
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.