Your Ad Here

September 09 2010 06:11:30
Navigation
· Home
· Articles
· Downloads
· Discussion Forum
· Useful Links
· News Categories
· Contact Us
· Search
Advertisement
COBOL OCCURS...DEPENDING ON

The COBOL OCCURS

COBOL files can have "tables".  A table is a field or group that occurs multiple times.  The number of times it repeats is specified by the OCCURS clause, like this:

   05  MONTHLY-SALES OCCURS 12 TIMES     PIC S9(5)V99.

This creates 12 fields in the record, each with a PIC S9(5)V99.

OCCURS can also be applied to a group, such as this example:

   05  LINE-ITEMS OCCURS 25 TIMES.
10 QUANTITY PIC 9999.
10 DESCRIPTION PIC X(30).
10 UNIT-PRICE PIC S9(5)V99.

This creates 25 groups, each of which contains the three fields QUANTITY, DESCRIPTION, and UNIT-PRICE, for a total of 75 fields.

The COBOL OCCURS... DEPENDING ON

COBOL also permits tables that occur a variable number of times, depending on the value in some other field.  This is similar to the COBOL OCCURS clause, except the number of times it occurs varies from record to record.  This causes the records to vary in size depending on the number of occurrences in any given record. Consequently, data within the table, and any data following the table will appear in varying locations in different records.

The invoice record fragment from above could be modified as follows:

   05  LINE-ITEM-COUNT                  PIC 99.
05 LINE-ITEMS OCCURS 0 TO 25 TIMES
DEPENDING ON LINE-ITEM-COUNT.
10 QUANTITY PIC 9999.
10 DESCRIPTION PIC X(30).
10 UNIT-PRICE PIC S9(5)V99.

The table LINE-ITEMS contains three fields (QUANTITY,  DESCRIPTION,  UNIT-PRICE) which make up one line on an invoice.  Each invoice can have from 0 to 25 line items.  The actual number of line items on a particular invoice, and therefore in the record, is given by the field LINE-ITEM-COUNT.

One instance of the table occupies 41 bytes, and the table may occur from 0 to 25 times, so the total space occupied by the table LINE-ITEMS in the record varies from 0 bytes to 1025 bytes.  If there are any fields after this table, their position in the record will shift, depending on the number of occurrences of the table.

There is a more complete description of OCCURS and OCCURS DEPENDING ON in the "Tables and Occurs" section of our Reading COBOL Layouts tutorial.

The PC File

Most PC databases cannot handle this concept. There are three potential solutions. In order of complexity, and using this example, they are:

1. If the OCCURS...DEPENDING ON is at the end of the record, as it commonly is, and DISC appends a CR-LF to the records,  some databases can deal with this and will import as many occurrences as contained in the record, then advance to the next record when they encounter the CR-LF delimiter. You should define all 25 occurrences (75 fields) in your database.

2. If the size of the table is not too large, in both bytes and number of fields, DISC can convert ALL records so they have 25 occurrences of the table. When we expand the number of occurrences in a particular record, say from 3 to 25, we fill the added character fields with spaces, and the added numeric fields with zeros.  Be careful to calculate the final size before choosing this method. A table with, say, ten fields of ten bytes each that occurs from 1 to 100 times would contain 1,000 fields and 10,000 bytes when expanded to the maximum size.  Expanding every record to the maximum possible size can make the file very large, which is why the occurs...depending on was used in the first place.

3. The last solution is to extract the table from the COBOL record and write each occurrence as a separate record in a new file, then add a key to relate those records to the main file, thus creating a relational database.

Comments
#1 | katharine on August 11 2010 19:41:04
Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... keyword,
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Latest Articles
· Best Way To Maximize...
· How to Maximize Adse...
· COBOL OCCURS...DEPEN...
· In-Stream and Catalo...
· JCL Statements
Advertisement
Render time: 0.03 seconds 260,329 unique visits