IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

vary occurs clause based on the number of Records


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Mon Jul 07, 2008 7:15 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Jul 07, 2008 7:20 pm
Reply with quote

What is the problem?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jul 07, 2008 7:43 pm
Reply with quote

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
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Mon Jul 07, 2008 8:01 pm
Reply with quote

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
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Jul 07, 2008 8:08 pm
Reply with quote

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
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Mon Jul 07, 2008 8:39 pm
Reply with quote

Hi Ashimer,

Thanks a lot for the reply.

Sree
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jul 07, 2008 9:06 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Jul 08, 2008 2:30 pm
Reply with quote

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
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Tue Jul 08, 2008 4:33 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top