Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 5: Data Division

SYNCHRONIZED/SYNC clause and slack bytes

  • To understand SYNC/SYNCHRONIZED clause, make sure you studied sections “Basics of Internal Representation of Data in Mainframe”<LINK> & “USAGE Clause”<LINK>
  • While storing variables in storage, COBOL compiler normally allocates contiguous storage spaces. But in order to take full advantage of the COMP items, storage of these items must start from respective boundaries. This helps in increasing computation efficiency of program.
  • First let’s understand example:-

    01 DEPT-DATA. 05 DATA-1 PIC X(5). 05 DATA-2 PIC 9(6) COMP SYNC. 05 DATA-3 PIC S9(4)V99 COMP-3.

  • Below diagram depicts the storage structure when SYNC is used and when SYNC is not used:-
  • In above example, DATA-1 will be stored at address 0-4 i.e. DATA-1 takes 5 bytes of storage. Now DATA-2 is defined as ‘9(6) COMP SYNC’, this will require 4 bytes of storage but since SYNC clause is specified for DATA-2, it will start at storing at next full word boundary which is at address 8 and thus DATA-2 will be stored at address 8-B taking 4 bytes of storage. DATA-3 will require 4 bytes and will occupy space form C-D. In this case space at address 5-7 remain unused (called as slack bytes) and this storage space will be wasted. Thus, DEPT-DATA requires total space of 16 bytes. The diagram above also shows that if we have not specified SYNC clause for DATA-2, there will not be any slack bytes and thus storage required for DEPT-DATA in that case will be 13 bytes.
  • In above example DATA-2 was in need of full word (4 bytes) storage, thus it must start storing at full word boundaries (full word boundaries are 0,4,8,C) but if DATA-2 was defined as ‘PIC 9(3) COMP SYNC’, in this case it needs storage of 2 bytes. Thus, storage for it should starts at half word boundaries (i.e. 0,2,4,6,8,A,C,E). For double word (8-bytes) COMP data items defined with SYNC clause will start storing at double word boundaries (i.e. 0, 8, G).
  • Storing data at proper alignment helps in increasing processing speed. SYNC clause explicitly aligns COMP data items, INDEX data items along with their natural word boundaries.
  • SYNC clause is used to optimize processing speed but it does so at the expense of storage(as it introduces slack bytes)

© copyright mainframebug.com
Privacy Policy