[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
The COBOL Standard Alignment Rules specify how characters are positioned in an elementary data item. Positioning depends on the item's category:
If the JUSTIFIED clause applies to the receiving item, the rules for the
JUSTIFIED clause override rule 3. See the Section 5.3.28 clause for more
information.
5.2.3 Additional Alignment Rules for Record Allocation
As stated in Section 5.2.2, the COBOL Standard Alignment Rules specify data positioning only within elementary data items. Hewlett-Packard defines additional alignment rules that affect the positioning of:
On Alpha and I64 systems, HP COBOL offers the option of allocating subordinate record items along performance-optimal boundaries through the use of the alignment compiler option or directives (or the SYNCHRONIZED clause). If you select one of these options, subordinate data items will be aligned automatically along optimal boundaries for their data type. The compiler may have to skip one or more bytes before assigning a location to the next data item. These skipped bytes, called fill bytes, are spaces between one data item and the next. Refer to the HP COBOL User Manual for information on using alignment compiler options and directives.
If you do not select one of these Alpha- and I64-only alignment options, the HP COBOL compiler will locate the data item at the next unassigned byte location.
The presence of fill bytes can make a record's structure different from what you might expect. In particular, if a record contains many items requiring alignment, its size can increase significantly. If, unaware of the fill bytes, you tried to move a group item containing fill bytes to a single data item, right-end truncation would occur. You would not have this problem, however, if you moved the record into another identically defined group item. The method the compiler uses to allocate storage ensures that identically described group items have the same structure, even when their subordinate items are aligned on their required boundaries. <>
Figure 5-3 shows alignment boundaries for a record. The boundary is the leftmost location of the 1-, 2-, 4-, or 8-byte area. All boundaries are relative to the beginning of the record as byte number 0.
Figure 5-3 Record Alignment Boundaries
The HP COBOL compiler allocates storage for data items within records according to the rules of the major-minor equivalence technique. The major-minor equivalence technique ensures that identically defined group items have the same structure, even when their subordinate items are aligned. Therefore, group moves always produce predictable results. This technique is based on the following two rules:
Location equivalence forces a group (major) item to the same storage location as its first subordinate (minor) item. This forced positioning occurs regardless of the boundary alignment of either the group or subordinate item.
Refer to the HP COBOL User Manual chapter on aligning binary data for information on how location equivalence allocates storage.
The following example results in the major-minor location format:
01 ITEM-A. 03 ITEM-B. 05 ITEM-C PIC 9(4) COMP SYNCHRONIZED. 03 FILLER PIC X. 03 ITEM-D. 05 ITEM-E PIC 9(4) COMP SYNCHRONIZED. 03 ITEM-F PIC X. |
The following example (omitting SYNCHRONIZED) results in the left-right location format:
01 ITEM-A. 03 ITEM-B. 05 ITEM-C PIC 9(4) COMP. 03 FILLER PIC X. 03 ITEM-D. 05 ITEM-E PIC 9(4) COMP. 03 ITEM-F PIC X. |
Table 5-3 compares the major-minor technique of storage allocation with the left-to-right technique that assigns locations to a group item before its subsidiary items. Note that major-minor storage allocation adds a fill byte before ITEM-D. This forces location equivalence with ITEM-E, which is explicitly aligned by the SYNCHRONIZED clause.
Data Item | Major-Minor Location |
Left-Right Location |
---|---|---|
ITEM-A | 00 | 00 |
ITEM-B | 00 | 00 |
ITEM-C | 00 | 00 |
FILLER | 02 | 02 |
ITEM-D | 04 | 03 |
ITEM-E | 04 | 03 |
ITEM-F | 06 | 05 |
The following diagram also shows the storage allocation for the record ITEM-A in Table 5-3 using both techniques. A hyphen (-) represents fill bytes caused by explicit alignment; an asterisk (*) represents the FILLER data item.
Regardless of the record allocation technique, an elementary move always produces the expected result. For example:
MOVE ITEM-C TO ITEM-E |
A group move may produce an unexpected result, as in the following two situations:
Boundary equivalence forces a group item to a boundary determined by the alignment of its subordinate items.
Within a record, a group item aligns on a boundary as large as the forced alignment boundary of any data item that:
Refer to the HP COBOL User Manual chapter on alignment for more information about boundary equivalence.
Figure 5-4 shows how the compiler determines the boundary where each item begins when you specify the no-alignment compiler option.
Figure 5-4 Effect of Boundary and Location Equivalence Rules on Sample Record
Figure 5-5 graphically represents Figure 5-4. It shows the result of location and boundary equivalence applied to the description of record ITEM-A. A hyphen (-) indicates fill bytes.
Figure 5-5 Storage Allocation for Sample Record
Note the location of ITEM-D. Location equivalence requires only that it have the same location as ITEM-E, its first subordinate item. ITEM-E requires only 2-byte boundary alignment. However, another of ITEM-D's subordinate items, ITEM-F, contains ITEM-I, which must be aligned on a 4-byte boundary. Therefore, boundary equivalence forces ITEM-D to a 4-byte boundary as well, causing two fill bytes between ITEM-E and ITEM-F.
This example shows how boundary equivalence helps make group moves predictable:
01 ITEM-A. 03 ITEM-B. 05 ITEM-C PIC X. 05 ITEM-D PIC 9(8) COMP SYNC. 03 ITEM-E PIC X. 03 ITEM-F. 05 ITEM-G PIC X. 05 ITEM-H PIC 9(8) COMP SYNC. 03 ITEM-I PIC XX. |
Previous | Next | Contents | Index |