Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
Posted: Tue Apr 17, 2018 7:27 am Post subject: Lengths of fields
I'm trying to get my head around the following problem and simply don't understand it. I'm guessing that maybe the usage of COMP-5 and SYNC might have something to do with it but would appreciate if anyone can explain.
Here's the source code for part of a copybook layout. The copybook looks like this:-
Code:
01 XWU92001-Addon.
03 Addon.
06 attr-nil-Addon-value PIC X DISPLAY.
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
Posted: Tue Apr 17, 2018 8:32 am Post subject:
I don't know assembler, but my guess is that the compiler inserted 2 "slack bytes" before 06 Name to force Name2-length to start on a half-word boundary (because of the SYNC clause). _________________ ....Terry
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Tue Apr 17, 2018 11:26 am Post subject:
misi01,
When using binary storage (binary and comp), COBOL compiler requires that a numeric field start on some boundary. If you specify a comp field in the middle of a record, and it doesn't happen to begin on a 32 bit (4 byte) boundary, the compiler will "align" it to a 32 bit boundary to "synchronize" it.
Check this link which explains in detail about the Slack bytes with a pictorial reprenstation
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
Posted: Wed Apr 18, 2018 2:08 am Post subject:
Thanks to both of you. As you pointed out, attr-nil-Addon-value is offset 1 and one byte. Normally, MonthlyPrice-num would then be at offset 2, but since it's a binary field, the offset is set to 4, and 4 - 1 is the same as 276 - 273.
BTW - useful link Kolusu. _________________ Michael
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum