ALIGNED and UNALIGNED attributes

ALIGNED specifies that the data element is aligned on the storage boundary corresponding to its data type requirement. UNALIGNED specifies that each data element is mapped on the next byte boundary, except for fixed-length bit strings, which are mapped on the next bit.

Read syntax diagramSkip visual syntax diagramALIGNEDUNALIGNED

Defaults are applied at element level. UNALIGNED is the default for bit data, character data, graphic data, uchar data, widechar data, and numeric character data. ALIGNED is the default for all other types of data.

Table 1 lists the requirements for the ALIGNED attribute.

Notes:
  • Alignment and storage requirements for program control data can vary across supported systems.
  • Complex data requires twice as much storage as its real counterpart, but the alignment requirements are the same.
Table 1. Alignment requirements
Variable type Stored internally as: Storage requirements (Bytes) Alignment requirements
ALIGNED data UNALIGNED data
BIT (n) ALIGNED: One byte for each group of 8 bits (or part thereof)

UNALIGNED: As many bits as are required, regardless of byte boundaries

ALIGNED: CEIL(n/8)

UNALIGNED: n bits

Byte (Data can begin on any byte, 0 through 7) Bit (Data can begin on any bit in any byte, 0 through 7)
CHARACTER (n) One byte per character n Byte (Data can begin on any byte, 0 through 7) Byte (Data can begin on any byte, 0 through 7)
CHARACTER (n)VARYINGZ One byte per character plus one byte for the nullterminator n+1
GRAPHIC (n) Two bytes per graphic 2n
GRAPHIC (n) VARYINGZ Two bytes per graphic plus two bytes for the nullterminator 2n+2
UCHAR (n) Four bytes per uchar 4n
UCHAR (n) VARYINGZ Four bytes per uchar plus one byte for the nullterminator 4n+1
WIDECHAR (n) Two bytes per widechar 2n
WIDECHAR (n) VARYINGZ Two bytes per widechar plus two bytes for the nullterminator 2n+2
PICTURE One byte for each PICTURE character (except V, K, and the F scaling factor specification) Number of PICTURE characters other than V, K, and F specification
DECIMAL FIXED (p,q) Packed decimal format (1/2 byte per digit, plus 1/2 byte for sign) CEIL((p+1)/2
BINARY FIXED (p,q)
SIGNED
1 <= p <= 7
UNSIGNED
1 <= p <= 8
One byte 1
ORDINAL
SIGNED
1 <= p <= 7
UNSIGNED
1 <= p <= 8
BIT (n) VARYING Two-byte prefix plus 1 byte for each group of 8 bits (or part thereof) of the declared maximum length ALIGNED: 2+CEIL(n/8)

UNALIGNED: 2 bytes+n bits

Halfword (Data can begin on byte 0, 2, 4, or 6) Byte (Data can begin on any byte, 0 through 7)
CHARACTER (n) VARYING Two-byte prefix plus 1 byte per character of the declared maximum length n+2
GRAPHIC(n) VARYING Two-byte prefix plus 2 bytes per graphic of the declared maximum length 2n+2
UCHAR (n) VARYING Two-byte prefix plus 4 bytes per uchar of the declared maximum length 4n+2
WIDECHAR (n) VARYING Two-byte prefix plus 2 bytes per widechar of the declared maximum length 2n+2
BINARY FIXED (p,q)
SIGNED
8 <= p <= 15
UNSIGNED
9 <= p <= 16
Halfword 2
ORDINAL
SIGNED
8 <= p <= 15
UNSIGNED
9 <= p <= 16
BINARY FIXED (p,q)
SIGNED
16 <= p <= 31
UNSIGNED
17 <= p <= 32
Fullword 4 Fullword (Data can begin on byte 0 or 4) Byte (Data can begin on any byte, 0 through 7)
ORDINAL
SIGNED
16 <= p <= 31
UNSIGNED
17 <= p <= 32
BINARY FLOAT (p) 1<=p<=21 Short floating-point
DECIMAL FLOAT (p) 1<=p<=6 if not DFP
DECIMAL FLOAT (p) 1<=p<=7 if DFP
BIT (n) VARYING4 Four-byte prefix plus 1 byte for each group of 8 bits (or part thereof) of the declared maximum length ALIGNED: 4+CEIL(n/8) UNALIGNED: 4 bytes+n bits Fullword (Data can begin on byte 0 or 4) Byte (Data can begin on any byte, 0 through 7)
CHARACTER (n) VARYING4 Four-byte prefix plus 1 byte per character of the declared maximum length n+4
GRAPHIC (n) VARYING4 Four-byte prefix plus 2 bytes per graphic of the declared maximum length 2n+4
UCHAR (n) VARYING4 Four-byte prefix plus 4 bytes per uchar of the declared maximum length 4n+4
WIDECHAR (n) VARYING4 Four-byte prefix plus 2 bytes per widechar of the declared maximum length 2n+4
POINTER(32) 4
HANDLE(32)
OFFSET under OFFSETSIZE(4)
FILE under LP(32)
ENTRY LIMITED under LP(32)
ENTRY 8
LABEL or FORMAT
TASK 16
AREA under OFFSETSIZE(4) 16+size Doubleword (Data can begin on byte 0) AREA data cannot be unaligned
AREA under OFFSETSIZE(8) 32+size
ENTRY LIMITED under LP(64) 8 Byte (Data can begin on any byte, 0 through 7)
POINTER(64)
HANDLE(64)
OFFSET under OFFSETSIZE(8)
FILE under LP(64)
BINARY FIXED(p,q)
SIGNED
32 <= p <= 63
UNSIGNED
33 <= p <= 64
BINARY FLOAT (p)
22 <= p <= 53
Long floating-point
DECIMAL FLOAT (p) 7<=p<=16 if not DFP
DECIMAL FLOAT (p) 8<=p<=16 if DFP
BINARY FLOAT (p)
54 <= p
Extended floating-point 16
DECIMAL FLOAT (p) 17<=p

ALIGNED or UNALIGNED can be specified for element, array, structure, or union variables. The application of either attribute to a structure or union is equivalent to applying the attribute to all contained elements that are not explicitly declared ALIGNED or UNALIGNED.

The following example illustrates the effect of ALIGNED and UNALIGNED declarations for a structure and its elements:


  declare 1 S,
            2 X bit(2),      /* unaligned by default  */
            2 A aligned,     /* aligned explicitly    */
              3 B,           /* aligned from A        */
              3 C unaligned, /* unaligned explicitly  */
                4 D,         /* unaligned from C      */
                4 E aligned, /* aligned explicitly    */
                4 F,         /* unaligned from C      */
              3 G,           /* aligned from A        */
            2 H;             /* aligned by default    */