Usages with implicit type
USAGEs in COBOL carry implicit data types:
index→ binary-int signed, a.k.a.
pic S9(9) comp
float→ float32, a.k.a.
double→ float64, a.k.a.
Additionally, floating point types do not display with leading zeros:
program-id.X. data division. local-storage section. 1 i index value 1. 1 j float value 2. 1 k double value 99. procedure division. display i display j display k.
+000000001 2 99
Using array indices to declare variables
If you have an array defined, integer values can be declared as an index to that array.
For example, this (43 chars):
1 a pic 99 occurs 20. 1 i index. 1 j index.
becomes this (33 chars):
1 a pic 99 occurs 20 indexed i j.
All indices declared in this way will additionally be pre-initialized to 1. A single array can have up to 12 indices, according to the documentation.
Declaring multiple arrays at once
If you have two arrays which are or could be the same length, you can declare them both as members of a recurring struct.
For example, this (44 chars):
1 a pic 99 occurs 20. 1 b pic 999 occurs 20.
becomes this (37 chars):
1 occurs 20. 2 a pic 99. 2 b pic 999.
a(8) would then be accessing the
a of the eighth item, rather than the eighth item of
If you have multiple variables with the same usage, these can all be declared as part of a single structure.
For example, this (32 chars):
1 a float. 1 b float. 1 c float.
becomes this (23 chars):
1 float. 2 a. 2 b. 2 c.
This will work for
double usages, but will not work for something like
pic 9(9), because the implied usage (
display) requires a
Omitting whitespace around numbers
Sometimes, whitespace that surrounds a numeric literal can be omitted.
If to add or subtract a variable,
add -1 to n. add 1 to n.
add -1to n. add+1to n.
This trick can also work to remove the whitespace between two consecutive statements.
For example, this (20 chars):
set i to 1 add+1to n
becomes this (19 chars):
set i to+1add+1to n