For any data description that has binary items that are not on their natural boundaries, the compiler inserts slack bytes within a record to ensure that all SYNCHRONIZED items are on their proper boundaries.
Because it is important that you know the length of the records in a file, you need to determine whether slack bytes are required and, if necessary, how many the compiler will add. The algorithm the compiler uses to calculate this is as follows:
For example:
01 FIELD-A. 05 FIELD-B PICTURE X(5). 05 FIELD-C. 10 FIELD-D PICTURE XX. [10 SLACK-BYTES PICTURE X. INSERTED BY COMPILER] 10 FIELD-E COMPUTATIONAL PICTURE S9(6) SYNC.Slack bytes can also be added by the compiler when a group item is defined with an OCCURS clause and contains within it a SYNCHRONIZED binary data item. To determine whether slack bytes are to be added, the following action is taken:01 FIELD-L. 05 FIELD-M PICTURE X(5). 05 FIELD-N PICTURE XX. [05 SLACK-BYTES PICTURE X. INSERTED BY COMPILER] 05 FIELD-O. 10 FIELD-P COMPUTATIONAL PICTURE S9(6) SYNC.
01 WORK-RECORD. 05 WORK-CODE PICTURE X. 05 COMP-TABLE OCCURS 10 TIMES. 10 COMP-TYPE PICTURE X. [10 SLACK-BYTES PIC XX. INSERTED BY COMPILER] 10 COMP-PAY PICTURE S9(4)V99 COMP SYNC. 10 COMP-HRS PICTURE S9(3) COMP SYNC. 10 COMP-NAME PICTURE X(5).
Figure 8. Insertion of Slack Bytes within a Record
In order to align COMP-PAY and COMP-HRS upon their proper boundaries, the compiler has added two slack bytes within the record.
In the example previous, without further adjustment, the second occurrence of COMP-TABLE would begin one byte before a doubleword boundary, and the alignment of COMP-PAY and COMP-HRS would not be valid for any occurrence of the table after the first. Therefore, the compiler must add slack bytes at the end of the group, as though the record had been written as follows:
01 WORK-RECORD. 05 WORK-CODE PICTURE X. 05 COMP-TABLE OCCURS 10 TIMES. 10 COMP-TYPE PICTURE X. [10 SLACK-BYTES PIC XX. INSERTED BY COMPILER ] 10 COMP-PAY PICTURE S9(4)V99 COMP SYNC. 10 COMP-HRS PICTURE S9(3) COMP SYNC. 10 COMP-NAME PICTURE X(5). [10 SLACK-BYTES PIC XX. INSERTED BY COMPILER]In this example, the second (and each succeeding) occurrence of COMP-TABLE begins one byte beyond a doubleword boundary. The storage layout for the first occurrence of COMP-TABLE will now appear as shown in Figure 9.
Figure 9. Insertion of Slack Bytes between Records
Each succeeding occurrence within the table will now begin at the same relative position as the first.
Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.