View previous topic :: View next topic
|
Author |
Message |
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi,
I have one question:
If i open one file in INPUT mode in a COBOL program and READ it till EOF. And i want read the same file from first record with out close the file. And i don’t want to close it and open again. . what i need to do?
Note: The file is the flat file and no keys.
Please help me for the Answer.
Regards,
Nath. |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
One possible solution: Allocate the same input file to two different DDNAMES in the JCL ( e.g. INPUT1 and INPUT2 ) and open them both with DISP=SHR. When the first one (INPUT1) hits EOF, switch to reading the other one (INPUT2). |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
As worded, I don't see any possibility of doing that. Is it some trick question? |
|
Back to top |
|
|
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi Ronald,
your solution is actually good one. but i want to read it several times like that for checking one value in the file.
Hi Anuj,
May be this is a trick question and this is my requirement also.
Regards,
Nath. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
rguhanath wrote: |
Hi Ronald,
your solution is actually good one. but i want to read it several times like that for checking one value in the file.
Hi Anuj,
May be this is a trick question and this is my requirement also.
Regards,
Nath. |
That is a the worst way of doing that, what a terrible waste of resources. How many records are in the file and how many times do you have to search it? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
And i want read the same file from first record with out close the file. And i don’t want to close it and open again. . what i need to do?
Note: The file is the flat file and no keys. |
You absolutely, categorically do not want to do this. It is a waste of resources and is a very bad way to design a process -- not to mention it can take a LOT of time.
Either redesign the process to read the file no more than one time, or tell us what the REAL requirements are and let us help you come up with a realistic, reasonable approach. |
|
Back to top |
|
|
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi Craq Giegerich,
Please let me know if you have the answer for any number of records and number of times (its not constant, may be its searching in thousends or lacks or more than) that i want to search it.
Regards,
Nath. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
did You ever hear of sort....
have all the files involved sorted on the <same key>
see the sticky two files match
Your idea is just BAD if You tell more we might come up with better suggestions |
|
Back to top |
|
|
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi,
Here i am giving you my requirement.
I am having one file says FILE 1 and another file says FILE 2. in FILE 1 having many records. in FILE 2 also having more records with unique data from 1 to 30 position.
i have to check the each record in FILE 1 with FILE 2 (1 to 30) data and fetch some value from the matched record in FILE 2. if not matched, then read another record in FILE 1 and Read the file FILE 2 again for searching it.
two files are not key indexed files. both are flat files and different record length. And both files are not having constant records.
Regards.
Nath. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
When you say
Quote: |
and fetch some value from the matched record in FILE 2 |
- so what make them "matched"? And if thery are matched on "something" - that "something" can be treated as "key" to sort both the files on. And once you got such files, you just need a simple file-match program, for which Enrico has already given you the directions. |
|
Back to top |
|
|
dneufarth
Active User
Joined: 27 Apr 2005 Posts: 420 Location: Inside the SPEW (Southwest Ohio, USA)
|
|
|
|
based on 'your requirement' you are stuck with and open/read/close scenario.
as suggested. sort and use a match/merge(update) as shown in a 'sticky' in this forum
could try to load the lookup file in a table if you want random lookups based on file1.
requirements are one thing; solutions abound |
|
Back to top |
|
|
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi,
Thanks for your suggestion !
i will try by uisng sort and merging.
Thanks and Regards,
Nath. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Good Luck... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
i will try by uisng sort and merging. |
It is also a trivial bit of COBOL code. . .
Near the top of the COBOL part of the forum is a "Sticky" that contains working/tested code for exactly what you want to do.
Whoever directed that the file should be searched over and over should not be permitted to define any more requirements. . . |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Actually, I have recently implemented a similar situation where a request file had to be re-read from first record every time there was a date break in a transaction file.
The programme was already coded using IMS checkpoint/restart with GSAM I/O.
Restarting from first record was done by issuing a get unique 'GU' call to the GSAM input file, with a doubleword RBA (relative block address) of fullword 1 followed by a fullword zero binary. This works even if you have reached eof in the file. |
|
Back to top |
|
|
santy Warnings : 1 New User
Joined: 19 Jul 2007 Posts: 22 Location: mumbai
|
|
|
|
you can do that using cobol code also but for that also you have to use 'key parameter of your files.
open file1 in input mode.
open file2 in input mode.
read file1 using key1 at EOF
read file2 using key2 at EOF
if (KEY1=KEY2) then
display "key1 match found in file2"
else
display "key1 not match into file2"
end-if
close file2.
close file1. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Basically, that "solution" will not work for the requirement. . .
There is no "key" to "use" in a sequential file. . .
Please post only tested solutions that meet the requirement. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
santy, as posted your "solution" reads one record from each file and then closes the files and stops. You have no loop to repeatedly read data. Furthermore, even if a loop is implemented, your code completely ignores the possibility that the two files do not have the same number of records. As Dick mentioned, please do not post code unless you have tested it and made sure it (1) works, (2) solves the requirement, and (3) does not introduce other problems. Your code fails all 3 of these areas. |
|
Back to top |
|
|
|