View previous topic :: View next topic
|
Author |
Message |
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
Thanks for reply Bill
LRECL is 133 and record count not more than 1000 |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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....
Bill |
|
Back to top |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
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 |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
Bill,
Can you provide any sample code which functions like your explanation.
I am new to development. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
No. I was the only guy working on this item.
Thanks for your help. I like your energy. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If this suggestion is followed, only 1 entry in the array will receive data. . . |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Sorry I forgot to inccrement the counter . |
|
Back to top |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
Thank you for your suggestions
I will try doing this |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If there are questions/problems while working on the code, reply here and someone will be able to help.
Good luck |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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. |
|
Back to top |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
Hello,
My array is succesfully working.
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Prasad,
From my part... Welcoming you to the forum...
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... .. 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 |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
Yes Terry and Dick, I saw it's working
Thank you |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
PPRASAD2
New User
Joined: 06 Aug 2009 Posts: 21 Location: chennai
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
sasikumar1984
Active User
Joined: 02 Jul 2007 Posts: 109 Location: Chennai - India
|
|
|
|
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 |
|
|
|