|
We know how to handle them! |
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, DEXCRIPTION, and UNIT-PRICE, for a total of 75 fields.
The COBOL OCCURS DEPENDING ON:
The invoice record fragment from
above could be modified as follows:
05 LINE-ITEM-COUNT
PIC 99.
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.
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.
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.
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.
For more articles on data conversion, see our TechTalk Index.
Our COBOL Conversion ServicesWith over 24 years of experience with thousands of files,
we have the knowledge to do your job right the first time.
|
|||||
|
Disc Interchange Service
Company, Inc.
Media Conversion Specialists
15 Stony Brook Road
Westford, MA 01886
(978) 692-0050