Page 1 of 1

OCCURS DEPENDING TO LOAD A FILE IN TABLE

PostPosted: Thu Mar 10, 2011 4:54 pm
by kpargao
Hi,

I have a requirement where I do not know the number of records in the input file. The first thing I want to do is to read the input file and store the records in array. Since the number of records may between 2000 - 2500 I can define an array with minimum size being 1 and maximum size being 3000 with occurs depending on clause. The counter variable on which the array will depend will be populated at the end when I will read the input file completely and will be the number of records in input file.

If I define a occurs depending on clause and then start reading each record of the input file and moving the element to the table when should the value of number of records shud be moved to the counter variable.

Can someone explain how to use occurs depending on such scenario?

Re: OCCURS DEPENDING TO LOAD A FILE IN TABLE

PostPosted: Thu Mar 10, 2011 5:50 pm
by BillyBoyo
Two answers.

Firstly, until you "use" the DEPENDING ON bit, it doesn't matter whether it is set or not. So, before you SEARCH ALL, or move a higher-level group item it does not matter if set or not. So, you can set when all the data is loaded in the table.

Secondly, I would increment the value each time I store a new item in the table, so that the data is always consistent, because later someone not looking closely enough might attempt to "use" it before it has been set.

If you are not using the DEPENDING ON, then you don't need it at all. Just define the table as OCCCURS 3000.

Also, of course, check that you haven't over-filled the table, and allow the program to either die gracefully with appropriate messages to whatever your site standards are if it attempts to do this (more than 3000 input records), or chuck out the extra records. If you don't check for this you will overwrite first, your working storage, then Cobol's storage area, then your program code itself, none of which is good :-)

Re: OCCURS DEPENDING TO LOAD A FILE IN TABLE

PostPosted: Thu Mar 10, 2011 5:55 pm
by Robert Sample
Section 1.4.5.1 of the COBOL Programming Guide manual has an example of loading a table that has OCCURS DEPENDING ON.