COBOL -> English

JCW2 used Ask the Experts™
Note: I'm taking a class.

Would you translate this COBOL code into English? (I.E., explain what's going on)

01  AREA-REC-IN.                                                
          05  AREA-IN             PIC X(49).                                
          05  AREA-STATE     PIC X(2).                                
          05  FILLER                PIC X(1).                                
          05  AREA-TYPE       PIC X(1).                                
          05  AREA-Q1           PIC S9(8) COMP-3.                        
          05  AREA-Q2           PIC S9(8) COMP-3.                        
          05  AREA-Q3           PIC S9(8) COMP-3.                        
          05  AREA-Q4           PIC S9(8) COMP-3.                    
          05  FILLER                PIC X(7).
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
My COBOL is rusty but I'll try.

FD is File Descriptor - it matches up with the select clause (in another part of the program)  to tell which file you are describing  

01 is level for the entire record (it includes all the 05 levels iside it. The name of the 01 level is AREA-REC-IN so you can manipulate the entire record at one time using this name.

05 AREA-IN is a field inside the 01 level.  It is 49 characters long.  This is kind of like a string but unlike a string it has a specific length (49) which never changes. The other fields "X" fields are similar, the next one is always 2 characters long, the next one is always one character long.  The COMP-3 fields are packed numeric.  The field can accomodate 8 digits but it is physically less than 8 because it is packed.  

All together these fields descibe a single record in a file.  When you read the record, you can access the AREA-TYPE (and the other fields) directly since you have defined the separate fields in the layout of the record.  
BTW, that record adds up to 80 bytes which is a very common record size on a Mainframe system because in the olden days we had these punch cards (Hollerith cards) that were normally 80 characters wide.  

Since each of the COMP-3 fields is 5 bytes the total size of the record is 49+2+1+1+5+5+5+5+7 = 80.   I believe the last 7 characters were often reserved for sequence numbers (so you could put the cards back in order if you dropped them).  The special keyword FILLER is a way to specify a field in the record that you are not going to reference in your program.  So this program is not going to reference the last 7 characters the 1 character after the AREA-STATE field as separate fields (although) it can still reference the entire record as AREA-REC-IN and of course that also includes any data inside those FILLER fields.

Also, this is probably more that you want to know but here is the reason an 8 digit packed field is 5 bytes long.  Take the number 12345678 for example, If you look at this COMP-3 number in hex it looks like this:

01 23 45 67 8C

That last nibble (C in this example) is the sign.  C means that the number is signed positive.  D would be signed negative and F would be unsigned.   So -6543 would be: 00 00 06 54 3D.  

I did not know they were still giving classes in COBOL.

MajorBigDeal's explanation is right on.  One more thing about BCD (binary coded decimal):  You can calculate the actual length of the field with this formula:

(number of digits + 1) / 2 (rounded up if necessary).  

This works because each 2 digits in the picture clause requires only one byte to store.  The sign requires a nibble (half byte).  So if you have a PIC clause of S9(8), you would require 5 bytes to store the number( 8 plus 1 divided by 2, round up).  If you have a PIC clause of S9(5) you would require 3 bytes (5 plus 1 divided by 2).

Since COBOL records are based on 80 characters, the difference between what you need and 80 is generally FILLER, however FILLER may be used to mask areas of the data that actually contain data that is not designed to be accessed by this particular record.


Thank you for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial