Can someone explain the purpose of using SYNC in COBOL?
SYNC is used for faster computations...
it creates slack bytes(unused space).....
01 ws-var s9(04) comp
it starts from 3rd byte.
01 ws-var s9(04) comp sync
it starts from 4th byte...
SYNC sets storage boundary alignment for the variable you are defining. Firstly 01 and 77 level variables are always aligned on a double-word boundary (0, 8, 16, 24...) and level variable after the 01 begins on the next byte position, except if SYNC is specified. A 9(4) COMP variable is aligned to the next half-word, a 9(8) COMP is aligned to the next full-word, and COMP-1/COMP-2 variables are aligned to the next double-word boundary.
As previously explained, sets a storage boundary - re-read the earlier explanaton.
Slack is the bytes "left over" from some field to the next boundary aligned (SYNCed) field.
To see this, suggest you create some code with various short field that are 01 levels as well as some lower levels. Look at the compiled output to see how the compiler aligns things. Then add a few more lower level field (01s are automatically aligned)) and specify SYNC and see the results.