View previous topic :: View next topic
|
Author |
Message |
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
I need to develop a pgm to look up for a field in a sequential file. The pgm will do a find for the field in the file and if it finds, the entire record will be written to the output file. It should then skip to the next record and continue the process. Please let me know what READ statement should I use to search for the string or field.
Thanks in advance
Chitra |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
gchitra wrote: |
I need to develop a pgm to look up for a field in a sequential file. The pgm will do a find for the field in the file and if it finds, the entire record will be written to the output file. It should then skip to the next record and continue the process. Please let me know what READ statement should I use to search for the string or field.
Thanks in advance
Chitra |
The read and the search are 2 different operations. You read the file to get a record then search the record for value you are looking for. |
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
File Aid is a lot more efficient than a program for this application. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Sort would be good, it's a simple task. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
For my $.02, it depends on knowing all of the "rules".
If the only requirement is to select/copy some records with a particular value, the utility route has appeal.
If there are other "things to do" or the process may grow, i'd probably use code. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Sounds to me like a homework assignment. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
dick scherrer wrote: |
For my $.02, it depends on knowing all of the "rules".
If the only requirement is to select/copy some records with a particular value, the utility route has appeal.
If there are other "things to do" or the process may grow, i'd probably use code. |
Now DICK you know they always provide ALL the rquirements when they ask for help/ |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
Thanks for all your replies. I know we can use the READ statement to read a sequential file. Can you tell me how I do the search to look up for the particular field?
Thanks
Chitra |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If you post your input record format and describe what value(s) you want to search for, we can offer suggestions on how to code it.
Until you explain the rules, we cannot offer much. |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
Hi Chitra,
As dick said
Quote: |
If you post your input record format and describe what value(s) you want to search for
|
until and unless you provide us record format , record length and the string you want to search ,we cant give any suggestions. |
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
The input file is nearly 30,000 in length and the string that I need to search (Eg: MPD800) will be anywhere after 180 and there could be more than one occurrence of the same string in the same record. So as soon as the first occurrence is found, the pgm should move to the next record. The record that has the matching string should be written to the output file.
Let me know if you need any other information. Thanks for all your help. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
To do what you want, i'd suggest you define your input record with a "placeholder" field of 180. Define the remainder of the record as one large field of whatever the length of the record is minus the placeholder (rec-lth - 180).
Code a loop that will start at the beginning of the large field and using reference modification, compare the search value against the data in the large field. Increment the displacement in the large field until you find the value or reach the end of the data.
When there is a match, write the record to the output file. When there is no match, continue with the next read.
As you write the code there may be questions. If there are, post a reply here showing your code and what needs clarification. |
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
Thank you very much, Dick.
The search field can be anywhere after the position 180. It can be in 181 or 485. So can you please tell me what we are trying to accomplish by defining a field of 180 in the record layout? Moreover, the file is VB.
Can you also please tell me the keyword to be used to search the string?
I hope it should be something like this:
count=0
READ INPUT-FILE
perform until count = n (this count will be no: of records that should have the search string. if there are more than n records, process only the first n records)
Search for the string (I don't know the keyword for this)
if found,
move to the ws-output-rec
write the output rec
count=count+1.
read the input file
end-perform
Please let me know if it is wrong.
Thanks in advance
Chitra |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Chitra,
Quote: |
The search field can be anywhere after the position 180. It can be in 181 or 485 |
Yup, that is why we will "move" across the record from byte 181 until e-o-r (end of record). Something in the record has a "depending on"? That is how to determine e-o-r.
Quote: |
So can you please tell me what we are trying to accomplish by defining a field of 180 in the record layout? |
The 180-byte field is to "skip over" the first part of the record - the part of the record that will not be searched for the value.
Quote: |
Can you also please tell me the keyword to be used to search the string? |
The actual comparison will be an IF statement. This IF will be inside a loop that "parses" across the data area for the search-string. Something like
Code: |
move 1 to dspl
compute last-comp = (eor - lth-of-search-string)
loop-para
if data-to-be-searched(dspl:lth-of-search-string) = search-string
go to write-out.
compute dspl = dspl + 1.
if dspl > last-comp
go to read.
go to loop-para.
write-out.
write the output
increment counter
if counter = max-this-run
wrapup and end.
go to read. |
That won't compile, but gives the general process.
Quote: |
Please let me know if it is wrong. |
As long as the requirement is to stop the run after n "hits", i believe you're on the right track.
We're here if there are questions |
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
Thanks a lot, Dick. I think this gave me an idea of how to go about with the program. But I may come back to you if I need any futher clarification.
Till then have a nice day and good luck!!!!
Thanks
Chitra |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Chitra,
Quote: |
Till then have a nice day and good luck!!!! |
You also
Someone will be here if there are questions while coding/testing. |
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
Thank you very much, Dick. |
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
Hi Dick,
I used the same logic that you suggested: Following is the code:
300-READ-FILE.
READ SKELCMPI INTO WS-SKELCOMPI-REC
MOVE 1 TO WS-DISPL
PERFORM 400-PROCESS-FILE THRU 400-PROCESS-FILE-EXIT
UNTIL MATCH-FOUND OR WS-DISPL = 30145.
300-READ-FILE-EXIT.
EXIT.
400-PROCESS-FILE.
IF WS-SKELCOMPI-LAST(WS-DISPL:6) = WS-UTI-NUM
MOVE 'Y' TO WS-MATCH-SW
PERFORM 500-WRITE-FILE THRU 500-WRITE-FILE-EXIT
COMPUTE WS-COUNT = WS-COUNT + 1
ELSE
COMPUTE WS-DISPL = WS-DISPL + 1
END-IF.
But as the record length (VB) is 30279, it takes almost 30min to find the record that matches the search string. The search string is in the 3rd record (i found it manually), still it takes more time.
I could not think of any better logic. Can you suggest one that increases the performance?
Thanks
Chitra |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
as mentioned earlier, FILEAID if you have it, will do what you want.
See code below
Gerry
Code: |
//FILEAID EXEC PGM=FILEAID
//SYSPRINT DD SYSOUT=*
//SYSLIST DD SYSOUT=*
//DD01 DD DSN=INPUT FILE
//DD01O DD DSN=OUTPUT FILE
//SYSIN DD *
$$DD01 COPY OUT=0,PADCHAR=C' ',
IF=(181,0,C'MPD800') |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Chitra,
Quote: |
The search string is in the 3rd record |
If the needed record is in the 3rd input record, it should take only a few seconds - if the read/search was terminated on the first "hit". How many records are in the file? I believe most of the time is looking thru the "rest of the file". |
|
Back to top |
|
|
gchitra
New User
Joined: 08 Jun 2005 Posts: 36 Location: Burtonsville, MD
|
|
|
|
Thanks Gerry & Dick. I don't think we have a FILEAID utility, but we do have FILEAID option in the ISPF menu panel.
Dick, you are right. Most of the time is spent in looking thru the rest of the file. I manipulated the input file so that first and second record has the search string, only to check if the output is as expected. But as the search starts from byte 125 and moves one byte at a time and the string appears somewhere after byte 450, the job after running for almost 3hrs, finally abended with S322.
I can not think of anything that could better the performance. I would appreciate, if any of you can suggest a better logic.
Thanks
Chitra |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Chitra,
I may have missed the answer to this, but how many records will be in the file?
When you say 3 hours, i suspect that is wall-time. How much cpu was used?
Which sort product is used on your system? |
|
Back to top |
|
|
|