COBOL Std 8 Data Definition Rules
Jump to navigation
Jump to search
8. Data Definition Rules[edit]
8.1 Numeric Usage[edit]
- Signed arithmetic fields must use the S prefix:
PIC S9(9). - Packed-decimal (COMP-3) is the preferred internal numeric type for arithmetic fields — smaller footprint and faster on most platforms.
- Binary (COMP-5) for SQL Communications Area fields (SQLCODE etc.) to match GixSQL generated C types.
- DISPLAY numeric only for print-output or host-variable character-format copybooks.
| Use Case | Recommended PIC | Notes |
|---|---|---|
| Integer counter | S9(9) COMP-3 |
Handles values to ±999,999,999. |
| Currency / amount | S9(9)V99 COMP-3 |
Odd digit count for packed efficiency. |
| Square root / remainder | 9(9)V9(9) DISPLAY |
18-digit decimal for precision comparisons. |
| DB identity / sequence | S9(9) COMP-3 |
Match PostgreSQL INTEGER type. |
| SQLCODE / SQLERRD | S9(9) COMP-5 |
Required by GixSQL SQLCA layout. |
8.2 88-Level Condition Names[edit]
- Define 88-level conditions for every significant state a field can hold; never test magic numbers directly in procedural code.
- 88-level names must be self-documenting:
SW-END-OF-FILErather thanSW-FLAG-1. - Comment the business meaning of each 88 at its definition.
<syntaxhighlight lang="cobol">
03 DAL-RESULT PIC 9(2) VALUE ZERO.
*-- 0 = operation succeeded
88 DAL-METHOD-OK VALUE 0.
*-- 1 = operation failed; caller should log and stop
88 DAL-METHOD-NOK VALUE 1.
*-- 2 = end of data / not found; not an error
88 DAL-METHOD-EOF VALUE 2.
</syntaxhighlight>
8.3 Host Variable Copybooks[edit]
- SQL host variables must be defined in a dedicated copybook (suffix
-TAB) included viaEXEC SQL INCLUDE. - Do not define host variables inline in WORKING-STORAGE outside a designated include.
- Character-format and packed-decimal versions are separate copybooks if both are needed; name them unambiguously (e.g.
PRIMES-TAB-PKD.cpyvsPRIMES-TAB.cpy).