Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Storing data in cobol array
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Thu Aug 06, 2009 2:54 pm    Post subject: Storing data in cobol array
Reply with quote

Hi,

I have to read an inpu file and need to put some fields in an array. Later I have to read this array and write it to some other file.

I am not how many records will come on dialy basis.

Could some one tell me how to give code to store values in an array?
Back to top
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 06, 2009 3:35 pm    Post subject: Reply to: Storing data in cobol array
Reply with quote

What is the LRECL of each record and what would be your estimate of the absolute maximum number of records in the file, also known as a SWAG (Scientific Wild A$$ Guess)?

Bill
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Thu Aug 06, 2009 3:40 pm    Post subject: Re: Reply to: Storing data in cobol array
Reply with quote

Thanks for reply Bill

LRECL is 133 and record count not more than 1000
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 06, 2009 3:55 pm    Post subject: Reply to: Storing data in cobol array
Reply with quote

Then you would need an array which has an OCCURS 1000 with each OCCURS (Entry) defined as PIC X(133). You should also define two indices to the array, one for your normal use and one which will contain the maximum number of records.

First, you must set your normal index to zero. To accomplish this in COBOL, set it to one then set it down by one. Now, you're ready to go.

As you read the file and before moving the record to an array-entry occurence, you set the normal index up by one.

When you reach EOF, set the maximum-index to your normal counting-index.

Before reading a record from the array, you must first reset your normal index to one.

After reading the record from the array, when the normal index equals the maximum index, then you're done.

Keep in mind when you're storing each record in the array, if the counting index has exceeded 1000, then you can't continue, because you've run of of array space and you need to modify the program, increasing the OCCURS to a higher value of your choice.

Not too difficult.... icon_wink.gif

Bill
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Thu Aug 06, 2009 4:09 pm    Post subject: Re: Reply to: Storing data in cobol array
Reply with quote

Thank you for your nice explanation.

If want to read this array and write it to another out file, how can I proceed?
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Thu Aug 06, 2009 4:12 pm    Post subject:
Reply with quote

Bill,

Can you provide any sample code which functions like your explanation.

I am new to development.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 06, 2009 4:48 pm    Post subject: Reply to: Storing data in cobol array
Reply with quote

I understand the fact that you are new, but going forward, it would not be a good foundation for you if someone provides code.

This is something that you need to jump into, get your feet wet, learn by your mistakes and work your way through all what is programming.

We all had to do it this way.

Is there a more Senior colleague with whom you can consult with?

Bill
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Thu Aug 06, 2009 5:06 pm    Post subject:
Reply with quote

No. I was the only guy working on this item.

Thanks for your help. I like your energy.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1238
Location: Richfield, MN, USA

PostPosted: Thu Aug 06, 2009 9:34 pm    Post subject:
Reply with quote

As Bill suggests, jumping in and learning by mistakes is oftentimes the most effective way of learning. Since you are new, here's some pseudocode to get you started in transfering your COBOL table (array) to your output file:
Code:
set your table index to a value of 1,
MOVE an occurrence of your table (using your index) to the output record area,
write an output record,
increment the index by 1,
if the index has exceeded the maximum number of occurrences, you're done; if not, repeat the above steps starting with the MOVE step.
The correct COBOL syntax to use is up to you. Also, there are many ways to write this code that will all produce the desired result. Some are more easily understood and maintained by others.
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Fri Aug 07, 2009 8:39 am    Post subject:
Reply with quote

Hi
SET ix TO 1

PERFORM 0000-para until EOF-IP

0000-para
READ ip-file INTO ip-rec

MOVE ip-rec TO array[IX]


Do this in the loop

While writing just process them and then simply write the records.

Hope this help

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

Site Director


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

PostPosted: Fri Aug 07, 2009 8:45 am    Post subject:
Reply with quote

Hello,

If this suggestion is followed, only 1 entry in the array will receive data. . .
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Fri Aug 07, 2009 8:56 am    Post subject:
Reply with quote

Sorry I forgot to inccrement the counter .
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Fri Aug 07, 2009 9:20 am    Post subject:
Reply with quote

Thank you for your suggestions

I will try doing this
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Fri Aug 07, 2009 9:33 am    Post subject:
Reply with quote

Hello,

If there are questions/problems while working on the code, reply here and someone will be able to help.

Good luck icon_smile.gif
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1238
Location: Richfield, MN, USA

PostPosted: Fri Aug 07, 2009 9:38 am    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

If this suggestion is followed, only 1 entry in the array will receive data. . .
That reminds me of a logic error I dealt with many years ago. A program I was responsible for maintaining all of a sudden couldn't find descriptions that were supposed to be in a table built at run time. It didn't take long to find the error. The programmer had correctly checked for the maximum number of occurrences of the table, but when it was exceeded, he decided to reset the value of the subscript/index to 1 and keep on truckin', instead of abending the program with an error message. As a result the table had but one entry in it (it had an ODO clause) since one additional input description was added since the previous run. icon_mad.gif
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Fri Aug 07, 2009 10:38 am    Post subject:
Reply with quote

Hello,

My array is succesfully working. icon_biggrin.gif

While doing that I obsereved a new thing.

0130-WRITE-AFILE.
MOVE FLFR-IN-REC TO FLFR-DMV-OUT-REC.
WRITE FLFR-DMV-OUT-REC.

my code is like this. When I tried to display 'FLFR-DMV-OUT-REC', in spool nothing is coming but records are written to output file.
But display FLFR-IN-REC is diplaying the whole record properly.

How come this?
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 07, 2009 12:35 pm    Post subject:
Reply with quote

Hi Prasad,

From my part... Welcoming you to the forum... icon_biggrin.gif

Could you be a little more specific on what your clarification is ?

Quote:
When I tried to display 'FLFR-DMV-OUT-REC'

For a start I dont see any DISPLAY statements in the sample code that you have provided... icon_wink.gif .. and are u sure u gave the statement as
DISPLAY 'FLFR-DMV-OUT-REC'
or
DISPLAY FLFR-DMV-OUT-REC.

Quote:
in spool nothing is coming but records are written to output file.

DISPLAY statments writes into the output device which when assigned to a file writes records to a file or otherwise to the SPOOL.
Back to top
View user's profile Send private message
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Fri Aug 07, 2009 1:22 pm    Post subject:
Reply with quote

FILE SECTION.
.
.
.
DATA RECORDS ARE FLFR-IN-REC.
01 FLFR-IN-REC.
COPY FLFRREC.





0130-WRITE-AFILE.
MOVE FLFR-IN-REC TO FLFR-DMV-OUT-REC.
WRITE FLFR-DMV-OUT-REC.
PERFORM 0140-STORE-FLFRFL-IN-ARRAY.
DISPLAY 'PRASAD=' FLFR-DMV-OUT-REC.

This is not working

DISPLAY 'PRASAD=' FLFR-IN-REC.

This working


Working means, in either of the cases output file is updated properly, but problem is with dislay
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Aug 07, 2009 1:33 pm    Post subject:
Reply with quote

had you bothered to search this forum or RTFM you would have know that
after a WRITE, the FD record area nolonger points to the same address as before the WRITE.

and before you ask, 'duh, what do you mean', suggest that you do a little research.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1238
Location: Richfield, MN, USA

PostPosted: Fri Aug 07, 2009 6:35 pm    Post subject:
Reply with quote

As Dick mentioned, the record area in your FD is no longer available to you after the WRITE statement. If you relocate your DISPLAY statement from after the WRITE to before the WRITE, your DISPLAY statement should work okay. It will pay in the long run to become intimately familiar with both the Language Reference Manual and Programing Guide.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us