ALIGN

Specifies the memory boundaries on which data items of level-01 or level-77 are aligned.

Syntax:

>>-.---.--ALIGN--"integer-.-------.-"-----------------><
   +-/-+                  +-FIXED-+
                          +--OPT--+

Parameters:

integer The distance from the start of one level-01 to the start of the next is a multiple of this. Can take any value from 1 to 255.
OPT | FIXED
OPT aligns the 01 level item on a multiple of integer best suited for its size (see table below). This allows more optimal instructions to be used at machine code level for such data items.
Note: For JVM COBOL code, OPT behaves as if FIXED is set.

FIXED aligns the 01 level item on the next multiple of integer.

If neither OPT nor FIXED is specified, the previous value that was specified is used. If no previous value exist, it defaults to OPT, unless the RM or DIALECT"RM" directives are in effect, in which case it defaults to FIXED.

Properties:

Default: ALIGN"8 OPT"
Phase: Syntax check
$SET: Initial

Dependencies:

IBMCOMP or NORM sets ALIGN"8 OPT" immediately.

DIALECT"RM" sets ALIGN"4 FIXED" immediately.

RM"ANSI" or RM sets ALIGN"2 FIXED" immediately.

Comments:

Data items of level-01 are aligned on byte boundaries that are multiples of the value given.

This can help produce more efficient execution results but does mean more memory might be used.

The following table show the boundary on which an item will be aligned depending on their size and the directive setting

01 level item size ALIGN"1 OPT" ALIGN"2 OPT" ALIGN"4 OPT" ALIGN"8 OPT" ALIGN"16 OPT"
1 1 2 4 8 16
2-3 2 2 4 8 16
4-7 4 4 4 8 16
8-15 8 8 8 8 16
>=16 16 16 16 16 16

Setting integer to a number that is not a multiple of four could impair the efficiency of the generated code. Under ALIGN(integer OPT), integer should be a power of 2, and will be increased to the next power of 2 if not (to a max value of 16).

If your program accesses data beyond the size of the 01-level item into the next or previous 01-level group, then you will need to use ALIGN(integer FIXED) to preserve the fixed alignment between 01-level items. However, such code is not ANSI Standard compliant, is not guaranteed to work in all circumstances, may interfere with some optimizations, and won't work in JVM COBOL.

Limitations:

If the 01-level group contains the following level-78 syntax, then the 01-level item will only be aligned according to the value of the ALIGN directive and not its size:

01 grp1.
78 constant-01 value next.
78 constant-01 value start grp1.

This is because the next/start record the data address before items are aligned according to their size.