View previous topic :: View next topic
|
Author |
Message |
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
I have a File which contains 10 records. And i need to declare an Array whose occurs clause should be based on the Number of records, In my case it is 10.
Sree |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
What is the problem? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
As long as the number of records in the file is fixed, no problem. If the number of records in the file is not fixed, you'll have to devise a method to find the record count, update the array in your COBOL source, and recompile the program before you can use it. Not really a good use of COBOL -- there's other, better ways to do this. |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi Robert/Craig,
Thanks a Lot for the Response.
Robert ,can you please let me know on the other solutions.
Thanks,
Sree |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Y u want to recompile and all ??? if you have an idea of the maximum records that can be there in the file (atleast somewhere near the max count) declare an array with the max count using depending on clause which will be based on the rec count .... |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi Ashimer,
Thanks a lot for the reply.
Sree |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you know the maximum possible number of records you might use an "occurs depending on" and populate that value with the record count.
The code would need to make sure the total number of records did not exceed the maximum and abend accordingly. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi,
You might like to use something like..(just the code-extension of above replies)
Code: |
01 TABLE.
05 COUNT PIC S9(03) COMP-3.
05 TBL OCCURS 100 TIMES
DEPENDING ON COUNT
INDEXED BY IDX.
10 VAR-1 PIC X(03).
10 VAR-2 PIC X(02). |
And the valuse of
Code: |
05 COUNT PIC S9(03) COMP-3. |
can come from input-files (right-away) or you might get it from the 'current' program itself. |
|
Back to top |
|
|
Antonio Barata Warnings : 1 New User
Joined: 04 Apr 2007 Posts: 37 Location: Lisbon, Portugal
|
|
|
|
Hi
I don't know whether this applies or not but, alternatively you can increment the count as you read the file. Anyway, you won't have access to the data until you read it right?
Something like this:
READ infile
IF valid record
ADD 1 to count
END-IF
END-READ |
|
Back to top |
|
|
|