Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

search for a field in a sequential file
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: search for a field in a sequential file
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    Post subject: Re: search for a field in a sequential file
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: 147
Location: Columbia, MO

PostPosted: Mon Oct 22, 2007 11:39 pm    Post subject: Reply to: search for a field in a sequential file
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    Post subject:
Reply with quote

Sort would be good, it's a simple task.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Oct 22, 2007 11:46 pm    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Oct 23, 2007 12:31 am    Post subject: Reply to: search for a field in a sequential file
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    Post subject: Reply to: search for a field in a sequential file
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

Site Director


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

PostPosted: Tue Oct 23, 2007 8:18 am    Post subject:
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: 130
Location: Guntur

PostPosted: Tue Oct 23, 2007 2:29 pm    Post subject:
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    Post subject: Reply to: search for a field in a sequential file
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

Site Director


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

PostPosted: Tue Oct 23, 2007 10:16 pm    Post subject:
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    Post subject: Reply to: search for a field in a sequential file
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

Site Director


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

PostPosted: Wed Oct 24, 2007 12:27 am    Post subject:
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    Post subject: Reply to: search for a field in a sequential file
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

Site Director


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

PostPosted: Wed Oct 24, 2007 8:43 pm    Post subject:
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    Post subject: Reply to: search for a field in a sequential file
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    Post subject: Reply to: search for a field in a sequential file
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: 1703
Location: Australia

PostPosted: Fri Nov 16, 2007 4:30 am    Post subject: Reply to: search for a field in a sequential file
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us