Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

SYNCHRONIZED clause

Function

The SYNCHRONIZED clause specifies the alignment of an elementary item on a natural boundary of the computer memory to ensure efficiency during the performance of arithmetic operations on the item.

As an extension to standard COBOL, the compiler described in this publication allows the SYNCHRONIZED clause to be specified at group level; this has the effect of aligning the elementary items subordinate to the group.

Format


{SYNCHRONIZED | SYNC} [LEFT | RIGHT]


Syntax rules

  1. SYNC is the abbreviation of SYNCHRONIZED.

  2. LEFT and RIGHT are treated as comments.

  3. The SYNCHRONIZED clause may not be specified for data of the classes national, object and pointer.

General rules

  1. When items are boundary-aligned because of the presence of a SYNCHRONIZED clause, it is sometimes necessary for the compiler to insert slack bytes. Slack bytes are unused character positions inserted into a record immediately ahead of an item requiring boundary alignment. Such slack bytes are included in the length of the group item containing the aligned item.

  2. The actual boundary at which a synchronized item is placed depends on the USAGE clause for the item.

  3. If the SYNCHRONIZED clause is omitted for binary data items or internal floating-point items, no slack bytes are generated. However, if arithmetic operations are performed on these items, the compiler will generate the statements necessary to move these items to auxiliary items which are properly aligned for the arithmetic operation.

  4. If the SYNCHRONIZED clause is specified for a group item, then all elementary items with USAGE COMPUTATIONAL, COMPUTATIONAL-5, BINARY, COMPUTATIONAL-1 or COMPUTATIONAL-2 will be aligned as if the SYNCHRONIZED clause had been specified in the data description entries of these items.

  5. If the SYNCHRONIZED clause is specified then the following actions will be performed:

    • For a data item with USAGE COMPUTATIONAL, COMPUTATIONAL-5 or BINARY:

      1. For the area S9 through S9(4) in the PICTURE clause, the data item is aligned on a halfword boundary (2 bytes).

      2. For the area S9(5) through S9(31) in the PICTURE clause, the data item is aligned on a fullword boundary (multiple of 4).

    • For a data item with USAGE COMPUTATIONAL-1, the item is aligned on a fullword boundary.
      For a data item with USAGE COMPUTATIONAL-2, the item is aligned on a doubleword boundary (8 bytes).

      Notes:

      • For a data item with USAGE DISPLAY, or COMPUTATIONAL-3 or PACKED-DECIMAL, the SYNCHRONIZED clause is treated as a comment, as no alignment is necessary in these cases.

      • For a data item with USAGE INDEX, the SYNCHRONIZED clause is also treated as a comment, as alignment in these cases is always performed on word boundaries. 

    For a summary of the details that have to be observed on the alignment of data items, refer to table 16:

    USAGESYNC permittedAlignment without SYNCAlignment with SYNC
    BINARY, COMP,
    COMP-5
    yesBHW1

    W2

    COMP-1

    yes

    B

    W

    COMP-2

    yes

    B

    DW

    COMP-3,
    PACKED-DECIMAL

    yes3

    B

    B

    DISPLAY

    yes3

    B

    B

    INDEX

    yes3

    W

    W

    NATIONAL

    no

    B

    -

    OBJECT REFERENCE

    no

    DW

    -

    POINTER

    no

    W

    -

    PROGRAM-POINTER

    no

    W

    -

    Table 16: Data item alignment


    B

    Alignment on byte boundary

    W

    Alignment on word boundary

    HW

    Alignment on half-word boundary

    DW

    Alignment on double word boundary

    1) 1-4 digits 
    2) >= 5 digits
    3)Permitted but has no influence on alignment

  6. When the SYNCHRONIZED clause is specified within a table (described by the OCCURS clause), each table element will be aligned. (This process is described under "Alignment by insertion of slack bytes".)

  7. When specifying the SYNCHRONIZED clause in conjunction with a REDEFINES clause, the programmer must ensure that the element being redefined is aligned (see Example 7-28).

  8. The SYNCHRONIZED clause does not alter the length of an elementary data item. Each unused internal memory location (slack bytes) is included in the size of the group to which the elementary item is subordinate, and must be allowed for an internal memory allocation if the group item was the object of a REDEFINES clause (see Example 7-29).

  9. All record descriptions (01-level entries) in all sections of the Data Division begin at doubleword boundaries.

  10. When blocking records that contain elementary items with the SYNCHRONIZED clause specified, the user must add the necessary slack bytes to ensure proper alignment after the first record within the block. (This process is described under "Alignment by insertion of slack bytes").

  11. For the purpose of aligning elementary items with USAGE COMPUTATIONAL, COMPUTATIONAL-5, BINARY, COMPUTATIONAL-1, COMPUTATIONAL-2, specified in the LINKAGE section, all 01-level elementary items are assumed to be aligned on doubleword boundaries. Consequently, the user must ensure that these operands are appropriately aligned in the USING phrase when he writes a CALL statement.

Example 7-28

In the following example, A has to be aligned on a fullword boundary:

02  A  PICTURE X(4).
02  B  REDEFINES A PICTURE S9(9) USAGE BINARY SYNC.

Example 7-29

01 RECORD.
   02  A.
       03  G PICTURE X(5).
       03  H PICTURE S9(9) SYNC USAGE BINARY.
   02  B   REDEFINES A.
       03  I PICTURE X(12).

Here, elementary item G occupies 5 bytes, and elementary item H occupies 4 bytes.

The SYNCHRONIZED and USAGE clauses indicate that the elementary data item H is aligned on fullword boundary; elementary item H is therefore preceded by 3 slack bytes. As data item A as a whole occupies 12 bytes, the subject of the REDEFINES clause (data item B) must also occupy 12 bytes.