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

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


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Fri Sep 19, 2008 12:21 pm
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top