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

Read record from first record.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Thu Sep 02, 2010 6:32 pm
Reply with quote

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
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Thu Sep 02, 2010 6:44 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Thu Sep 02, 2010 6:46 pm
Reply with quote

As worded, I don't see any possibility of doing that. Is it some trick question?
Back to top
View user's profile Send private message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Thu Sep 02, 2010 6:53 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Sep 02, 2010 6:58 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Thu Sep 02, 2010 7:03 pm
Reply with quote

Suggest you tell us what is your requirement. What you tell us sounds like that you already "thought of a solution" and now wants to "fit to the requirement". Hopefully, there can be some alternate solution once the requirement is clear.

There is this existing thread, which is loosly connected to your situation, please have a look.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 02, 2010 7:05 pm
Reply with quote

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
View user's profile Send private message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Thu Sep 02, 2010 7:07 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Thu Sep 02, 2010 7:20 pm
Reply with quote

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
View user's profile Send private message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Thu Sep 02, 2010 7:47 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Thu Sep 02, 2010 7:53 pm
Reply with quote

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
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 420
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Thu Sep 02, 2010 7:54 pm
Reply with quote

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
View user's profile Send private message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Thu Sep 02, 2010 8:06 pm
Reply with quote

Hi,

Thanks for your suggestion !

i will try by uisng sort and merging.

Thanks and Regards,
Nath.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Fri Sep 03, 2010 7:51 pm
Reply with quote

Good Luck...icon_smile.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Sep 03, 2010 11:21 pm
Reply with quote

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. . . icon_sad.gif
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Sat Sep 04, 2010 3:54 am
Reply with quote

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
View user's profile Send private message
santy
Warnings : 1

New User


Joined: 19 Jul 2007
Posts: 22
Location: mumbai

PostPosted: Wed Sep 08, 2010 9:53 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Sep 08, 2010 7:16 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Sep 08, 2010 7:24 pm
Reply with quote

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
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

 


Similar Topics
Topic Forum Replies
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts combine multiple unique records into ... DFSORT/ICETOOL 2
No new posts SORT on detail record, then repeat he... DFSORT/ICETOOL 3
No new posts how to complete the end of a record w... DFSORT/ICETOOL 2
No new posts Sort based on the record type DFSORT/ICETOOL 1
Search our Forums:

Back to Top