Page 1 of 2

IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 8:19 pm
by jscagli
Trying to write a rexx program in which i compare a portion of a record from fileA (flat file) against a portion of a record from all the records in fileB (flat file). If no match is found i then read the next record from fileA and compare it to all the records in fileB. The problem is once all the records in fileB have been read once I can't seem to read the file again. I know the rc goes from 0 to 2 once all the records are read and this causes the EOF marker to go from 'no' to 'yes'. However i do not know how to reset this so fileB can be read multiple times (until all records from fileA have been read).

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 8:27 pm
by enrico-sorichetti
pretty primitive approach

when a match is found what happens ???
are You going to modify file A or file B ???

if You describe the requirement rather than your attempt to a solution You might receive better suggestions

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 8:40 pm
by jscagli
No need to get insulting. This is my first time posting a question. When a match is found the record from fileB that has the match is copied over to a separate file.

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 9:38 pm
by NicC
How big are your files? Are they sorted? What have you tried in the area of closing and re-opening the file? Have you considered using JOINKEYS within your sort product?

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 10:24 pm
by jscagli
FileA is about 1200 records. FileB is approx 35,000 records. They are not sorted. I am taking an eight byte field from each record in fileA and comparing it to an eight byte field in each record in fileB. When a match is found in fileB I move a copy of that record over to a separate outfile. The record in fileA must be compared to 'every' record in fileB. Then the next record in fileA is compared to every record in fileB - and so on. I guess my problem is how do I get the fileB dataset reopened after a record from fileA has has gone through all the fileB records. The fileA records are only read once. thx

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 10:41 pm
by Pedro
They are not sorted.

The first step of your rexx program should be to sort the files.

Based on the sizes of the files, I would try to only read FileB only one time.

You should index FileA something like this, which builds an array of keys in fileA:
allkeys. = 'null'
EXECIO ...  (STEM filea.
Do ix  = 1 to filea.0
  keyA = substr(filea.ix,27,8)
  allkeys.keyA = keyA
End

Then as you read in records from FileB, see if there is a match:
keyb = substr(fileb,27,8)
If  allkeys.keyb ^= 'null' Then ...

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 10:57 pm
by Pedro
It sounds like you wanted to read fileB 1200 times:
1200 x 35000 = 42 million records

I think that would take you many minutes of elapsed time.

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 11:12 pm
by jscagli
Both fileA and fileB could be broken down into smaller chunks if that would make any difference. I'm getting the feeling that in rexx a sequential file can only be read through once which is interesting because I know LMM services will allow you to read through all the members in a pds multiple times.

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Thu Feb 06, 2014 11:47 pm
by Pedro
However i do not know how to reset this so fileB can be read multiple times (until all records from fileA have been read).

This is a technical forum. The details of the program are important. Show us the code that reads the file until EOF and then tries again. And show us a trace.

I suspect you need to read about the FINIS parameter of EXECIO. Or possibly, use the linenum parameter (after the DD name):
EXECIO 1 DISKR MYDATA 1

Re: IN rexx how to read a seq. flat file multiple times

PostPosted: Fri Feb 07, 2014 3:15 am
by NicC
With those small numbers of records you could read them all into 2 stems and then process stem a against stem b