View previous topic :: View next topic
|
Author |
Message |
siddhartha biswas Currently Banned New User
Joined: 04 May 2008 Posts: 15 Location: india
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
One thing to be noted here is
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Hi Sambhaji,
Good catch |
|
Back to top |
|
|
|