MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lengths of fields

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 620
Topics: 173
Location: Stockholm, Sweden

PostPosted: Tue Apr 17, 2018 7:27 am    Post subject: Lengths of fields Reply with quote

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.         
                                                             
    06 MonthlyPrice-num              PIC S9(9) COMP-5 SYNC. 
                                                             
    06 MonthlyPrice                  PIC S9(9) COMP-5 SYNC. 
                                                             
    06 Name-num                      PIC S9(9) COMP-5 SYNC. 
                                                             
    06 Name.                                                 
      09 Name2-length                  PIC S9999 COMP-5 SYNC.
      09 Name2                         PIC X(255).           
      09 attr-nil-Name-value           PIC X DISPLAY.       
    06 filler                        PIC X(2).   

   Nothing more in the copybook           



and the resulting compiler listing looks like this
Code:

01 XWU92001-Addon.                                       BLW=00001+3E0         0CL276
  03 Addon.                                              BLW=00001+3E0         0CL276
    06 attr-nil-Addon-value    PIC X DISPLAY.            BLW=00001+3E0,0000000 1C
    06 MonthlyPrice-num        PIC S9(9) COMP-5 SYNC.    BLW=00001+3E4,0000004 1F
    06 MonthlyPrice            PIC S9(9) COMP-5 SYNC.    BLW=00001+3E8,0000008 1F
    06 Name-num                PIC S9(9) COMP-5 SYNC.    BLW=00001+3EC,000000C 1F
    06 Name.                                             BLW=00001+3F0,0000010 0CL258
      09 Name2-length            PIC S9999 COMP-5 SYNC.  BLW=00001+3F0,0000010 1H   
      09 Name2                   PIC X(255).             BLW=00001+3F2,0000012 255C
      09 attr-nil-Name-value     PIC X DISPLAY.          BLW=00001+4F1,0000111 1C
    06 filler                  PIC X(2).                 BLW=00001+4F2,0000112 2C

My assumption is that the various fields have the following lengths:-

Code:

                                 Field
                                 length
06 attr-nil-Addon-value          1         (pic x display)
06 MonthlyPrice-num              4         PIC S9(9) COMP-5 SYNC.   
06 MonthlyPrice                  4          PIC S9(9) COMP-5 SYNC.   
06 Name-num                      4          PIC S9(9) COMP-5 SYNC.   
06 Name.                                     (group variable - ignore)
    09 Name2-length              2         PIC S9999 COMP-5 SYNC.
    09 Name2                   255      PIC X(255).           
    09 attr-nil-Name-value       1          PIC X DISPLAY.         
    06 filler                    2          PIC X(2).               


Now when I add up 1+4+4+4+2+255+1+2 I get 273, and not 276 as the compiler listing shows.
What am I missing ?
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Tue Apr 17, 2018 8:32 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12370
Topics: 75
Location: San Jose

PostPosted: Tue Apr 17, 2018 11:26 am    Post subject: Reply with quote

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

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/igy3lr50/5.3.16.2
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
misi01
Advanced


Joined: 02 Dec 2002
Posts: 620
Topics: 173
Location: Stockholm, Sweden

PostPosted: Wed Apr 18, 2018 2:08 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group