Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts Repeat part of record multiple times Learncoholic DFSORT/ICETOOL 4 Tue Aug 29, 2017 11:33 am
No new posts String after '.' (period) is not copy... balaji81_k SYNCSORT 6 Wed Aug 23, 2017 9:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us