OCCURS DEPENDING TO LOAD A FILE IN TABLE



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

OCCURS DEPENDING TO LOAD A FILE IN TABLE

Postby kpargao » Thu Mar 10, 2011 4:54 pm

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?
kpargao
 
Posts: 2
Joined: Tue Mar 08, 2011 1:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: OCCURS DEPENDING TO LOAD A FILE IN TABLE

Postby BillyBoyo » Thu Mar 10, 2011 5:50 pm

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 :-)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: OCCURS DEPENDING TO LOAD A FILE IN TABLE

Postby Robert Sample » Thu Mar 10, 2011 5:55 pm

Section 1.4.5.1 of the COBOL Programming Guide manual has an example of loading a table that has OCCURS DEPENDING ON.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post