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 query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts Extract record for change in combinat... Trinadh DFSORT/ICETOOL 6 Thu Nov 23, 2017 3:32 pm
No new posts Extract Record using range of Data scorp_rahul23 DFSORT/ICETOOL 3 Wed Nov 15, 2017 11:54 pm
No new posts Squeeze record left so that zeroes ar... Vignesh Sid SYNCSORT 5 Fri Nov 10, 2017 1:40 pm
No new posts Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm

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