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
 

 

To find the starting position of a string presen in a record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
siddhartha biswas
Currently Banned

New User


Joined: 04 May 2008
Posts: 15
Location: india

PostPosted: Fri Sep 19, 2008 11:49 am    Post subject: To find the starting position of a string presen in a record
Reply with quote

Hi all,

I have a requirement in which I need to check whether a string say 'APPLE' is present in a file record . If present I need to find the starting position of 'APPLE'. Can anyone suggest a solution?
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: Fri Sep 19, 2008 12:21 pm    Post subject:
Reply with quote

Hello,

Using the literal and the length of the literal, you could use reference modification and parse the record looking for the literal or the "end-of-record.

You would set up a loop that set the begin position to 1 and increment the begin position each time the literal did not match the "current" data from the record.

When you "match", the start positon of the compare is the answer you want. If you parse over the entire record with out a hit, you are done with that record.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Fri Sep 19, 2008 12:46 pm    Post subject:
Reply with quote

Hi,

Do as Dick said, here is sample code which may help you

Code:
1. Put it in loop
    PERFORM <PARA1> VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 75

PARA1
-------
      IF WS-RECORD(WS-I:5) = 'APPLE'
             MOVE WS-I                TO  WS-STRFND-CNT
     ELSE
             CONTINUE
     END-IF


WS-STRFND-CNT data item will have the position of APPLE string..

Hope you got
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Sep 19, 2008 4:35 pm    Post subject:
Reply with quote

One thing to be noted here is
Quote:

UNTIL WS-I > 75


This is OK if length of variable is 80.

As you are referencing next five characters while matching it should not go beyond length.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Fri Sep 19, 2008 6:00 pm    Post subject:
Reply with quote

Hi Sambhaji,

Good catch icon_wink.gif
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
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Record Not found in AlX but record re... mukun264 COBOL Programming 7 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts To Merge mutliple records into a sing... anandgbe DFSORT/ICETOOL 6 Wed Feb 22, 2017 8:49 am


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