Data types
Standard COBOL provides the following data types:
Data type | Sample declaration | Notes |
---|---|---|
Character | PIC X(20) | Alphanumeric and alphabetic-only Single-byte character set (SBCS) |
Edited character | PIC X99BAXX | Formatted and inserted characters |
Numeric fixed-point binary | PIC S999V99 or BINARY | Binary 16, 32, or 64 bits (2, 4, or 8 bytes) Signed or unsigned. Conforming compilers limit the maximum value of variables based on the picture clause and not the number of bits reserved for storage. |
Numeric fixed-point packed decimal | PIC S999V99 | 1 to 18 decimal digits (1 to 10 bytes) Signed or unsigned |
Numeric fixed-point zoned decimal | PIC S999V99 | 1 to 18 decimal digits (1 to 18 bytes) Signed or unsigned Leading or trailing sign, overpunch or separate |
Numeric floating-point | PIC S9V999ES99 | Binary floating-point |
Edited numeric | PIC +Z,ZZ9.99 | Formatted characters and digits |
Group (record) | 01 CUST-NAME. | Aggregated elements |
Table (array) | OCCURS 12 TIMES | Fixed-size array, row-major order Up to 7 dimensions |
Variable-length table | OCCURS 0 to 12 TIMES | Variable-sized array, row-major order Up to 7 dimensions |
Renames (variant or union data) | 66 RAW-RECORD | Character data overlaying other variables |
Condition name | 88 IS-RETIRED-AGE | Boolean value dependent upon another variable |
Array index | [USAGE] INDEX | Array subscript |
Most vendors provide additional types, such as:
Data type | Sample declaration | Notes |
---|---|---|
Numeric floating-point single precision | PIC S9V9999999ES99 [USAGE] COMPUTATIONAL-1 | Binary floating-point (32 bits, 7+ digits) (IBM extension) |
Numeric floating-point double precision | PIC S9V999ES99 [USAGE] COMPUTATIONAL-2 | Binary floating-point (64 bits, 16+ digits) (IBM extension) |
Numeric fixed-point packed decimal | PIC S9V999 [USAGE] COMPUTATIONAL-3 | same as PACKED DECIMAL (IBM extension) |
Numeric fixed-point binary | PIC S999V99 | same as COMPUTATIONAL or BINARY (IBM extension) |
Numeric fixed-point binary (native binary) | PIC S999V99 | Binary 16, 32, or 64 bits (2, 4, or 8 bytes) Signed or unsigned. The maximum value of variables based on the number of bits reserved for storage and not on the picture clause. (IBM extension) |
Numeric fixed-point binary in native byte order | PIC S999V99 | Binary 16, 32, or 64 bits (2, 4, or 8 bytes) Signed or unsigned |
Numeric fixed-point binary in big-endian byte order | PIC S999V99 | Binary 16, 32, or 64 bits (2, 4, or 8 bytes) Signed or unsigned |
Wide character | PIC G(20) | Alphanumeric Double-byte character set (DBCS) |
Edited wide character | PIC G99BGGG | Formatted and inserted wide characters |
Edited floating-point | PIC +9.9(6)E+99 | Formatted characters, decimal digits, and exponent |
Data pointer | [USAGE] POINTER | Data memory address |
Code pointer | [USAGE] PROCEDURE-POINTER | Code memory address |
Bit field | PIC 1(n) [USAGE] COMPUTATIONAL-5 | n can be from 1 to 64, defining an n-bit integer Signed or unsigned |
Index | [USAGE] INDEX | Binary value corresponding to an occurrence of a table element May be linked to a specific table using INDEXED BY |