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

search for a field in a sequential file


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

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Mon Oct 22, 2007 10:26 pm
Reply with quote

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

Senior Member


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

PostPosted: Mon Oct 22, 2007 10:35 pm
Reply with quote

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

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Mon Oct 22, 2007 11:39 pm
Reply with quote

File Aid is a lot more efficient than a program for this application.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Mon Oct 22, 2007 11:42 pm
Reply with quote

Sort would be good, it's a simple task.
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: Mon Oct 22, 2007 11:46 pm
Reply with quote

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

Senior Member


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

PostPosted: Mon Oct 22, 2007 11:49 pm
Reply with quote

Sounds to me like a homework assignment.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Tue Oct 23, 2007 12:15 am
Reply with quote

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

Moderator Emeritus


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

PostPosted: Tue Oct 23, 2007 12:31 am
Reply with quote

icon_smile.gif
Back to top
View user's profile Send private message
gchitra

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Tue Oct 23, 2007 8:09 am
Reply with quote

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

Moderator Emeritus


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

PostPosted: Tue Oct 23, 2007 8:18 am
Reply with quote

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

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Tue Oct 23, 2007 2:29 pm
Reply with quote

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

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Tue Oct 23, 2007 10:04 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Tue Oct 23, 2007 10:16 pm
Reply with quote

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

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Tue Oct 23, 2007 11:49 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Wed Oct 24, 2007 12:27 am
Reply with quote

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

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Wed Oct 24, 2007 6:08 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Wed Oct 24, 2007 8:43 pm
Reply with quote

Hello Chitra,

Quote:
Till then have a nice day and good luck!!!!
You also icon_smile.gif

Someone will be here if there are questions while coding/testing.
Back to top
View user's profile Send private message
gchitra

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Wed Oct 24, 2007 11:14 pm
Reply with quote

Thank you very much, Dick.
Back to top
View user's profile Send private message
gchitra

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Fri Nov 16, 2007 1:25 am
Reply with quote

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

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Fri Nov 16, 2007 4:30 am
Reply with quote

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

Moderator Emeritus


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

PostPosted: Fri Nov 16, 2007 4:44 am
Reply with quote

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

New User


Joined: 08 Jun 2005
Posts: 36
Location: Burtonsville, MD

PostPosted: Sat Nov 17, 2007 12:29 am
Reply with quote

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

Moderator Emeritus


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

PostPosted: Sat Nov 17, 2007 1:55 am
Reply with quote

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
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 Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts Unable to interpret a hex value to De... COBOL Programming 7
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts how to eliminate null indicator value... DB2 7
No new posts Format Binary file to EBCDIC JCL & VSAM 4
Search our Forums:

Back to Top