Skip to content
systemcoding.dev
Mainframe

Declare a packed field with DECLARE FIXED DECIMAL

Declare a packed decimal field in PL/I with DECLARE FIXED DECIMAL, which stores digits two per byte, and print it with an edit format.

1 min read
Summarize in AI

PL/I stores FIXED DECIMAL as packed decimal, the same format COBOL calls COMP-3, so a record shared with a COBOL program needs no conversion. The two numbers in the attribute are the total digits and the digits after the decimal point.

packed.plipli
 PACKED: PROC OPTIONS(MAIN);
   DCL AMOUNT FIXED DECIMAL(7,2);
   AMOUNT = 123.45;
   PUT SKIP EDIT(AMOUNT)(F(8,2));
 END PACKED;
Text
  123.45

With seven digits plus a sign nibble, the field takes four bytes, and 123.45 is stored as 00 12 34 5C. The decimal point is never stored: it is a property of the declaration, so reading the same bytes with FIXED DECIMAL(7,0) gives 12345.

This is Enterprise PL/I for z/OS 6.1 syntax. Arithmetic on decimal fields is done in decimal and keeps its precision, but a result that needs more digits than the target holds raises the FIXEDOVERFLOW condition only if that is enabled, otherwise it is truncated.

Taggedz ospl i
Share

More snippets

Get new posts by email

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

Unsubscribe in one click. No spam, ever.