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

String operator

SujeetMishra
Active Contributor
0 Likes
2,360

Dear All,

I have one problem, that i want to exclude some words from my string.

eg : string = abcdefghijklmnop.

i want to dispay this string like fghi* (starting from 6th position)

can you help me out this problem.

Thanks in advance.

Regards,

Sujeet

1 ACCEPTED SOLUTION
Read only

former_member585060
Active Contributor
0 Likes
2,290

Hi,

try below code

DATA : w_st TYPE string,
            w_st2 TYPE string,
            n TYPE i.

w_st = 'abcdefghijklmnop'.
n = STRLEN( w_st ).
n = n - 6.
w_st2 = w_st+6(n).

WRITE : / w_st2.

Regards

Bala Krishna

16 REPLIES 16
Read only

Former Member
0 Likes
2,290

data : g_string type string,

l_string type string.

g_string = abcdefghijklmnop.

l_string = g_string+06(10)

write l _string.

Read only

Former Member
0 Likes
2,290

Sujeeth,

Take some temporary variable as shownn below

Data: Temp_Var type c length 15.

move string+5(11) to temp_var.

write: temp_var.

Hope it is useful

Thanks,

Babu Kilari

Read only

0 Likes
2,290

Try this code

data: string1 type string value 'abcdefghijklmnop',

string2 type string.

string2 = string1+05(10).

write string2.

Read only

0 Likes
2,290

@ SAP User,

Offset should be 05 not 06. Because SAP Calculates the string from 0th Position

@ Gayathri.

Length should be 11 not 10. If you give it as 10, the last character will be missed out.

Plz check

Thanks,

Babu Kilari

Read only

former_member585060
Active Contributor
0 Likes
2,292

Hi,

try below code

DATA : w_st TYPE string,
            w_st2 TYPE string,
            n TYPE i.

w_st = 'abcdefghijklmnop'.
n = STRLEN( w_st ).
n = n - 6.
w_st2 = w_st+6(n).

WRITE : / w_st2.

Regards

Bala Krishna

Read only

Former Member
0 Likes
2,290

Hi Sujeet,

i hope that u know the concept of Offset .

the above given solutions are based on this method of OFFSET.

pls read the library for better understanding.

eg.

data:
  w_string(15)  type c value 'netweaver'.
  w_char type string.

w_char = w_string+6(4).

the following code calculates the string specfied from 6 th pos onwards till the length provided here '4'.

w_char will contain value ver

hope u got the concept..

thanks

ravi

Read only

SujeetMishra
Active Contributor
0 Likes
2,290

Hi all,

I know string operation.

but thing is, as i have posted previously that i want "fghi*".

means start from 6th position till 10th.

  • = i have to display with my string, it doesn't mean i want all words after pos 10.

Have a Nice Day,

Regards,

Sujeet

Read only

0 Likes
2,290

Hi Sujeeth,

I think you havent mentioned your requirement properly before. Please check the same.

Anyways, Now you got the reply from Lakshmi Priya Isnt it?

Thanks,

Babu Kilari

Read only

0 Likes
2,290

Please check this code

data : string1 type string value 'abcdefghijklmnop',

string2 type string.

string2 = string1+05(11).

write string2.

Read only

0 Likes
2,290

Hi,

Test the following Sample Code Hope will solve out your problem,

DATA: string TYPE string VALUE 'abcdefghijklmnop',
      moff TYPE i,
      st_len TYPE i.
st_len = STRLEN( string ).
FIND FIRST OCCURRENCE OF 'fghi' IN string
  MATCH OFFSET moff.
IF sy-subrc EQ 0.
  st_len = st_len - moff.
  WRITE: string+moff(st_len).
ENDIF.

Please Reply if any Issue,

Best Regards,

Faisal

Read only

Former Member
0 Likes
2,290

Hi,

string = abcdefghijklmnop.

to dispay this string like fghi* (starting from 6th position)

If the position is 6,then the offset will be 5 as the starting pos is considered as 0.

From total length we need only till 10th pos from 6th .

now the

string = string+5(5).

Edited by: Lakshmi Priya Gaddam on Apr 16, 2009 8:41 AM

Read only

Former Member
0 Likes
2,290

data : l_var1 type string,

l_var2 type string.

l_var1 = 'abcdefghijklmnop'.

l_var2 = l_var1+5(5)

write: l_var2.

Regards,

Joan

Edited by: Joan Jesudasan on Apr 16, 2009 8:46 AM

Read only

Former Member
0 Likes
2,290

DATA : STR TYPE STRING VALUE 'abcdefghijklABCD',F(2),C(2),

strlen type n.

C = strlen( STR ).

F = C - 5 .

WRITE / STR+5(F).

hOPE THIS WILL SOLE UR PROBLEM......

Read only

vamsilakshman_pendurti
Active Participant
0 Likes
2,290

This message was moderated.

Read only

0 Likes
2,290

This message was moderated.

Read only

0 Likes
2,290

This message was moderated.