Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with string finding.

tarangini_katta
Active Contributor
0 Likes
1,344

Hi All,

I have a string with the following values:

B1;;2009/11 Claim: 007324;SA;20081006;20091101;I004;;1032000MAR;;750;31;500481;Michael O`Leary

I want to find the 'i001' with in this string.I can't hard find this value becuase it will come from file.It does contain any value other than this with in that postion.

I want to find it through Find Rgex.

Can anybody please help.

8 REPLIES 8
Read only

former_member585060
Active Contributor
0 Likes
1,015

Hi,

Do as below,

p = 'B1;;2009/11 Claim:i001:uuiiooiji001'.

FIND 'i001' IN p.

IF sy-subrc = 0.
  your code
ENDIF.

What exactly you wan to do if it is found that value?

Regards

Bala Krishna

Read only

former_member194669
Active Contributor
0 Likes
1,015

Try something like this way


data: v_str     type string ,
      t_result  type match_result_tab ,
      wa_result like line of t_result,
      lt_result type match_result_tab.
v_str = 'B1;;2009/11 Claim: 007324;SA;20081006;20091101;I004;;1032000MAR;;750;31;500481;Michael O`Leary
'.
data matcher type ref to cl_abap_matcher.
matcher = cl_abap_matcher=>create(
  pattern = `^.* (i001) .*$`
  ignore_case = 'X'
  text = v_str ).
lt_result = matcher->find_all( ).

a®

Read only

Former Member
0 Likes
1,015

Check this:

DATA:
  w_string TYPE string VALUE 'B1;;2009/11 Claim: 007324;SA;20081006;20091101;I004;;1032000MAR;;750;31;500481;Michael O`Leary',
  w_sub_string(4) TYPE c VALUE 'I004',
  w_lenght1 TYPE i,
  w_lenght2 TYPE i,
  w_offset  TYPE i,

  w_result TYPE string.

w_lenght1 = STRLEN( w_string ).
w_lenght2 = STRLEN( w_sub_string ).

IF w_string CS w_sub_string.
  w_offset = sy-fdpos.
  w_result  = w_string+w_offset(w_lenght2).
  WRITE: w_result.
ENDIF.

Read only

Former Member
0 Likes
1,015

hi tarangini,

chk if this helps...


data:
w_str1 type string value  'B1;;2009/11Claim:007324;SA;20081006;20091101;I004;;1032000MAR;;750;31;500481;Michael O`Leary ',

w_str2 type string value 'I004'.
 
 search w_str1 for w_str2.
 
 if sy-subrc = 0.
 write: sy-fdpos. " position of w_str2 in w_str1.
 endif.

Regards,

Mdi Deeba Najam

Read only

Former Member
0 Likes
1,015

Hi,

Take 'i004' into one character variable.

Take the string into a string variable .

search string for 'i004' .

if sy-subrc eq 0.

write 😕 'Found ',sy-fdpos.---> position of the string

endif.

Else use abbreviated option with the above search

search string for 'i4' abbreviated .

This searches for i4 where ever it is in the string

Read only

Former Member
0 Likes
1,015

Hi,

Hope may be helpful,

data:

w_string type string,

w_char(10) type c.

w_string = 'B1;;2009/11 Claim:007324;SA;20081006;20091101;I004;;1032000MAR;;750;31;500481;Michael O`Leary '.

w_char = 'i001'.

search w_string for w_char.

if sy-subrc = 0.

write: / sy-fdpos.

endif.

Read only

tarangini_katta
Active Contributor
0 Likes
1,015

Hi All,

As i specified in my question is should not hard code the the value 'i004'. i want to get this based on the Postion.I want to find the I004'.In the file in that postion it may conatin I004 or anythin else.

I dont want to hard code the value.

Thanks,

Read only

former_member222860
Active Contributor
0 Likes
1,015

Hey,

One-way is to use SubString function to find the string for the specified position, for this u've to use Native Sql.

check this code:

DATA:
  v_word TYPE string VALUE
  'B1;;2009/11 Claim: 007324;SA;20081006;20091101;I004;;1032000MAR;;750;31;500481'.

  DATA: v_string type string.

parameters: pos type i,
            len type i.

exec sql.
select substr(:v_word, :pos,:len) from dual into :v_string
endexec.

write:/ v_string.

thanks\

Mahesh