View previous topic :: View next topic
|
Author |
Message |
Pons
New User
Joined: 25 May 2007 Posts: 61 Location: Coimbatore
|
|
|
|
Hi All,
My requirement is to find table of string from the file.
The file is not sorted. So i need to open a file for each search and have close it. It is an Sequential file. So i plan to move all the file things to array and using that array (Table) for searching.
My question is how to determine the array size (Table size), the file records may vary from each run. So how to find out the total number of records and how to declare the table accordingly...
Please advice. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
You can't! |
|
Back to top |
|
|
Pons
New User
Joined: 25 May 2007 Posts: 61 Location: Coimbatore
|
|
|
|
Hi,
Then how to handle my requirement. What logic can i follow.. |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
This might not good one, but...
Read PS two times...
One for counting records,
The OCCURS DEPENDING ON clause specifies variable-length tables.
One for moving to table... |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Pons wrote: |
Then how to handle my requirement. What logic can i follow.. |
Assuming multiple search strings, I'd read them in and format an "A" record and release them to sort. Then I'd read the file to be searched and format a "B" record and release them to sort.
I'd then retreive the sorted records easily checking the "B" record following an "A" record to see if the sort key string matches. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
gnanas wrote: |
This might not good one, but...
Read PS two times...
One for counting records,
The OCCURS DEPENDING ON clause specifies variable-length tables.
One for moving to table... |
The table is still defined (allocated) for the max size so why bother with two reads. Set the depending on to the max, load the table and set the depending on to the actual count, just one read loop is all you need. |
|
Back to top |
|
|
tushar.zibbu
New User
Joined: 08 Mar 2007 Posts: 6 Location: Assam
|
|
|
|
Hello Pons,
If I have understood the requirement, the solution is very simple. While uploading the records into an ARRAY, you can keep a COUNT for the number of records loaded (lets say WS-IN-REC-COUNT). Then the same variable (WS-IN-REC-COUNT) can be used in Working-Storage Section while declaring the ARRAY (Depending on WS-IN-REC-COUNT).
I guess that has answered your question. If not, please let me know. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
As noted earlier - DEPENDING ON is not dynamic allocation - you still must specify at compile time the max size.
If you must do this dynamically - here's how:
1. Set up a template COBOL program to do what you want, with a placeholder token (e.g., <asize>) for the array size.
2. Have another program count the file size, then copy the template to a temp file, replacing <asize> with the actual value for this run.
3. Input the temp file into the compile/link/run proc.
4. Assuming you don't blow a compile limit, you're OK.
5. Note that this is an unusual production job, in that you are executing a program (this instance of the template) which has strictly speaking not undergone a formal production turnover except as the template, so some installations might balk. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Another stupid design problem. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
What's wrong with defining the table in linkage after a getmain? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
Craq - To what are you referring? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Phrzby Phil wrote: |
Craq - To what are you referring? |
The original requirements. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
I skipped that part and went right to the more interesting part of actually doing a dynamic COBOL array, albeit in several steps.
I make no representation that dynamic arrays are the way to solve the op's problem. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If you post some sample data and how you want the process to work, we can probably offer better suggestions. . . |
|
Back to top |
|
|
Pons
New User
Joined: 25 May 2007 Posts: 61 Location: Coimbatore
|
|
|
|
Thanks a lot for your advices.
Dick my requirement:
1. From the PS file i need to read the LOB (Line of business), is it H (HOME) then i need to update the table.
2. If that particular key have an LOB as A (AUTO) also, then i need to add these home and auto values and need to update the table.
3. Here the file is not sorted. For that i need to search each and every key from the file for AUTO or HOME LOB is present.
As per my knowledge,
I try to read the file first and get the key, after that i try to use the array to find the auto lob for that key; For this search i need the solution.
How can i handle this.... Please give the soluction using cobol program. I cant change the job and i cant sort the file....
Sample data's:
XXHXXXXX XXXXX100.AAAAAAAA.AA - 1 RECORED
XXHXXXXX XXXXX200.BBBBBBBB.BB - 2 RECORED
XXAXXXXX XXXXX100.CCCCCCC.CC - 3 RECORED
XXHXXXXX XXXXX200.DDDDDDD.DD - 4 RECORED
XXAXXXXX XXXXX300.AAAAAAAA.AA - 5 RECORED
XXAXXXXX XXXXX100.XXXXXXXX.XX - 6 RECORED
See here 1st recored and 5th recored have the same key and so i need to add 100 and 300 = 400 and need to update this 400 to table for both H and A.
But 2nd recored have only one recored H so i just want to update the 200 in to table for H.
I hope you got my point. If not let me know... |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Pons wrote: |
I cant change the job and i cant sort the file.... |
You should not need to 'change the job' to do an internal sort..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Please give the soluction using cobol program. I cant change the job and i cant sort the file.... |
If you use cobol, that would be changing the job wouldn't it?
What reason is there that you can't sort a copy of the original file for use in your process? As was already mentioned, what reason is there that you cannot use an internal sort of the file withn your process?
The original file would remain unchanged, but you would have a file that you could use without wasting so much development time as well as system resources. Processing the sorted data (regardless of how the sort is done) will make the code much more straight forward (which means it will be running sooner), as well as running much faster.
You do not want to open/close the file over and over in your process. |
|
Back to top |
|
|
|