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

Storing data in cobol array


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 06, 2009 3:35 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 06, 2009 3:55 pm
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 06, 2009 4:48 pm
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
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: 1249
Location: Richfield, MN, USA

PostPosted: Thu Aug 06, 2009 9:34 pm
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
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

Moderator Emeritus


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

PostPosted: Fri Aug 07, 2009 8:45 am
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
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
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

Moderator Emeritus


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

PostPosted: Fri Aug 07, 2009 9:33 am
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: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 07, 2009 9:38 am
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
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
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
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
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: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 07, 2009 6:35 pm
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
PPRASAD2

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Fri Aug 07, 2009 6:51 pm
Reply with quote

Yes Terry and Dick, I saw it's working

Thank you
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Aug 07, 2009 7:15 pm
Reply with quote

Sometime in the future, if you are feeling more confident with your skills -

www.ibmmainframes.com/viewtopic.php?p=176368&highlight=#176368

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

New User


Joined: 06 Aug 2009
Posts: 21
Location: chennai

PostPosted: Sat Aug 08, 2009 12:12 am
Reply with quote

hey

Is any thing wrong in my code?
FD REPORT-FILE
RECORD CONTAINS 149 CHARACTERS
BLOCK CONTAINS 0 RECORDS
LABEL RECORDS ARE STANDARD
DATA RECORDS ARE REPORT-RECORD.
01 REPORT-RECORD.
05 MOBIUS-DETAIL-LINE.
.
.
.
.


SET AI TO 1.
PERFORM 0180-PRINT-HEADING.
PERFORM 0170-READ-ARRAY VARYING AI FROM 1 BY 1 UNTIL
AI > 1000.
.
.
.
.
0170-READ-ARRAY.

MOVE FILING-DETAILS-TABLE(AI) TO REPORT-RECORD.
MOVE REPORT-DETAIL-LINE-CC(AI) TO MOBIUS-DETAIL-LINE.
MOVE REPORT-DETAIL-SYMBOL(AI) TO MOBIUS-DETAIL-SYMBOL.
MOVE REPORT-DETAIL-NUMBER(AI) TO MOBIUS-DETAIL-NUMBER.
WRITE REPORT-RECORD.


when I display array contents , it is displaying properly but in out put records are not coming
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


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

PostPosted: Sat Aug 08, 2009 1:12 am
Reply with quote

You need to show us the definition of your COBOL table and tell us whether or not you are checking the file status of all file I-O including the WRITE statement and what you mean by
Quote:
in out put records are not coming
Back to top
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Sun Aug 09, 2009 7:31 am
Reply with quote

Prasad,

I doubt with your array declaration for the above problem. Can you post the array declaration here...?

Also your performing the loop until AI reaches 1001 (atleast 1000 times). since your loading the array using your input file, load the array until end of file and keep increament some counter(declare some counter variable) for each read of your i/p file, then at end of last recod your counter will be having total number of record that your i/p file have. Then you can perform the array as below

PERFORM 0170-READ-ARRAY VARYING AI FROM 1 BY 1 UNTIL
AI > 1000 or AI > your-counter-variable

or

PERFORM 0170-READ-ARRAY VARYING AI FROM 1 BY 1 UNTIL
AI > your-counter-variable
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top