SYNCHRONIZED Clause Example
Slack bytes (unused character positions) are added before each synchronized item in the records. For Example -
01 STUDENT.
05 STUDENT-NO PIC 9(02).
05 STUDENT-NAME PIC X(12).
05 STUDENT-GRADE PIC 9(02).
05 STUDENT-CLASS PIC X(03).
After the compiler inserts the slack bytes, the declaration is modified. For instance, after STUDENT-NO, the next item STUDENT-NAME starts from the boundary. Similarly, for STUDENT-GRADER, the STUDENT-CLASS starts from the boundary after the insertion of slack bytes. The declaration after slack bytes is -
01 STUDENT.
05 STUDENT-NO PIC 9(02).
[05 SLACK-BYTES PIC XX. INSERTED BY COMPILER]
05 STUDENT-NAME PIC X(12).
05 STUDENT-GRADE PIC 9(02).
[05 SLACK-BYTES PIC XX. INSERTED BY COMPILER]
05 STUDENT-CLASS PIC X(03).
The below diagram represents the memory allocation along with slack bytes -
Four slack bytes are inserted if we do not use the SYNC clause. The variables (followed by slack bytes) should declare with SYNC clause to avoid the slack bytes as shown below -
01 STUDENT.
05 STUDENT-NO PIC 9(02).
05 STUDENT-NAME PIC X(12) SYNC.
05 STUDENT-GRADE PIC 9(02).
05 STUDENT-CLASS PIC X(03) SYNC.
The diagram below represents the same allocation after introducing the SYNC clause. There will be no slack bytes anymore -