Tooluck logoTooluck
SKILL.md

comp3-packed-decimal

Agent skill frombenchflow-ai/skillsbench

Reference for COBOL COMP-3 (packed decimal / BCD) numeric storage -- layout on disk, declaring it in the FD, and pitfalls when carrying the decoded value through working storage and into later arithmetic. Useful when an input record holds a balance, rate, or carry-forward as packed decimal rather than a printable digit string.

How to install comp3-packed-decimal

install comp3-packed-decimal
# install the skillsbench pack with the skills CLI
npx skills add benchflow-ai/skillsbench

# or add only this skill to Claude Code: copy the folder

tasks-extra/cobol-gl-batch-reconcile/environment/skills/comp3-packed-decimal/

# into

~/.claude/skills/comp3-packed-decimal/ (all projects)

.claude/skills/comp3-packed-decimal/ (one project)

tasks-extra/cobol-gl-batch-reconcile/environment/skills/comp3-packed-decimal/SKILL.md

Apache-2.0Full file
1# COMP-3 / packed decimal storage
2
3`USAGE COMP-3` (a.k.a. PACKED-DECIMAL) stores a signed numeric field as
4binary-coded-decimal nibbles: each byte holds two decimal digits, except the
5last byte whose low nibble is the sign:
6
7```
8PIC S9(11)V99 USAGE COMP-3
9+--+--+--+--+--+--+--+
10|D1|D2|D3|D4|D5|D6|D7| 7 bytes total for 13 digits
11+--+--+--+--+--+--+--+
12 ^^-- sign nibble in the LOW half of the last byte
13```
14
15Bytes-on-disk = `ceil((digit_count + 1) / 2)`. For `PIC S9(11)V99` that is
16`ceil(14 / 2) = 7` bytes. The high nibble of the first byte holds the first
17decimal digit; the implied decimal point is not stored.
18
19Sign nibbles:
20
21| Nibble | Meaning |
22|--------|---------|
23| `C` | positive (some shops emit `F` for unsigned, but `C` is standard for SIGNED) |
24| `D` | negative |
25| `F` | unsigned / non-`S` PIC |
26
27## Declaring COMP-3 in an FD
28
29The record layout must match the byte budget. If the data in the file is
30packed but you declare the field as `PIC X(n)` or as an unpacked decimal,
31the COBOL runtime will not decode it and the value will look like binary
32garbage when displayed.
33
34```cobol
35FD MAST-FILE
36 RECORD CONTAINS 80 CHARACTERS.
3701 MAST-REC.
38 05 M-ACCT PIC X(6).
39 05 M-TYPE PIC X.
40 05 M-STATUS PIC X.
41 05 M-CCY PIC X(3).
42 05 M-CARRY PIC S9(11)V99 USAGE COMP-3. *> 7 bytes
43 05 FILLER PIC X(62). *> remainder of 80
44```
45…

Excerpt shown under the repository's Apache-2.0 license.

More skills in skillsbench

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates