Lengths of fields
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: Lengths of fields Author: misi01Location: Stockholm, Sweden PostPosted: Tue Apr 17, 2018 7:27 am
    —
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 ?

#2:  Author: Terry_HeinzeLocation: Richfield, MN, USA PostPosted: Tue Apr 17, 2018 8:32 am
    —
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).

#3:  Author: kolusuLocation: San Jose PostPosted: Tue Apr 17, 2018 11:26 am
    —
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

#4:  Author: misi01Location: Stockholm, Sweden PostPosted: Wed Apr 18, 2018 2:08 am
    —
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.



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group