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

matching string

Former Member
0 Likes
1,271

hii,

i want to match a field's substring

like

field

ABC,

ABD,

ABE

here first two char r constant.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,045

hi,

Check this..



DATA: str1 TYPE string, 
          str2 TYPE string. 

str1 = 'ABCDEFGH'. 
str2 = '*ABC'. 

IF str1 CS str2. 
  WRITE : str1, 'Conatins', str2.
ENDIF. 

Contains String: True if the content of operand2 is contained in operand1. Upper/lower case is not taken
into account, trailing blanks of the left operand are taken into account. If operand1 is of type string and 
initial, or of type c and contains only blank characters, the logical expression is false, unless operand2 
is also of type string and initial, or of type c and only contains blank characters. In this case the logical 
expression is always true. If the result of the comparison is true, sy-fdpos contains the offset of 
operand2 in operand1. If the result of the comparison is negative, sy-fdpos contains the length of 
operand1.

Edited by: Avinash Kodarapu on Feb 10, 2009 10:52 AM

7 REPLIES 7
Read only

Former Member
0 Likes
1,045

Hi Akshaya,

Welcome to Our Forum.

Can you explain your requirement briefly.

Thanks.

Read only

0 Likes
1,045

ok..

wat shud i write

if field = 'AB?'

it shud check

ABC

ABD

ABE

Read only

Former Member
0 Likes
1,046

hi,

Check this..



DATA: str1 TYPE string, 
          str2 TYPE string. 

str1 = 'ABCDEFGH'. 
str2 = '*ABC'. 

IF str1 CS str2. 
  WRITE : str1, 'Conatins', str2.
ENDIF. 

Contains String: True if the content of operand2 is contained in operand1. Upper/lower case is not taken
into account, trailing blanks of the left operand are taken into account. If operand1 is of type string and 
initial, or of type c and contains only blank characters, the logical expression is false, unless operand2 
is also of type string and initial, or of type c and only contains blank characters. In this case the logical 
expression is always true. If the result of the comparison is true, sy-fdpos contains the offset of 
operand2 in operand1. If the result of the comparison is negative, sy-fdpos contains the length of 
operand1.

Edited by: Avinash Kodarapu on Feb 10, 2009 10:52 AM

Read only

Former Member
0 Likes
1,045

Hi Akshaya

lv_a = ABC.

lv_b = ABD.

then we can compare them like

IF lv_a(2) = lv_b(2). "lv_a(2) = 'AB' = lv_b(2)

Pushpraj

Read only

viquar_iqbal
Active Contributor
0 Likes
1,045

Hi

Welcome to SDN

you can use offsets and compare them

Thanks

Viquar Iqbal

Read only

Former Member
0 Likes
1,045

Hi Akshaya,

Try using offset because you are using Character strings.

like here in your case ABC and ABD are there.

So you can try it out like,

w_string0(2) = w_string10(2).

or if you want the 2nd and 3rd characters you can increment your offset like .

w_string+W_count(w_count1).

w_count = w+count + 1.

w_count1 = w_count1 + 1 .

Try using this logic hope it helps!

Much Regards,

Amuktha.

Read only

Former Member
0 Likes
1,045

hi,


DATA:
counter TYPE i value '5',
fl_flag,
str1 TYPE char12 VALUE 'good morning',
str2 TYPE char12 VALUE 'good morning'.

DO counter TIMES.
  IF str1(sy-index) = str2(sy-index).
    fl_flag = 'X'.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
IF fl_flag = 'X'.
  WRITE:
    'letter to letter mapped'.
ENDIF.

In the counter variable mention the position till where you want to check the strings.

Thanks

Sharath