Rational Developer for System z
COBOL for Windows, Version 7.5, Language Reference


Slack bytes within records

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 so, how many bytes the compiler will add. The algorithm the compiler uses is as follows:

These slack bytes are added to each record immediately following the elementary data item that precedes the binary item. They are defined as if they constitute an item with a level-number equal to that of the elementary item that immediately precedes the SYNCHRONIZED binary item, and are included in the size of the group that contains them.

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.
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.

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:

The slack bytes are inserted at the end of each occurrence of the group item that contains the OCCURS clause. For example, a record defined as follows will appear in storage, as shown, in the figure after the record:

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-HOURS            PICTURE S9(3) COMP SYNC.
        10  COMP-NAME             PICTURE X(5).

Begin figure description. This figure shows the insertion of slack bytes within a record, based on how record fields align with doubleword, fullword, and halfword boundaries. End figure description.

In order to align COMP-PAY and COMP-HOURS on their proper boundaries, the compiler added 2 slack bytes within the record.

In the previous example, without further adjustment, the second occurrence of COMP-TABLE would begin 1 byte before a doubleword boundary, and the alignment of COMP-PAY and COMP-HOURS 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-HOURS             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 1 byte beyond a doubleword boundary. The storage layout for the first occurrence of COMP-TABLE will now appear as shown in the following figure:

Begin description. This figure shows the insertion of slack bytes between records, based on how record fields align with doubleword, fullword, and halfword boundaries. End description.

Each succeeding occurrence within the table will now begin at the same relative position as the first.


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)