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

Replace Occurences in Internal Table.

former_member184739
Contributor
0 Likes
8,603

Hello Experts,

  I have internal table like shown below.

APPEND 'SO_SEL' TO itab.
APPEND 'SO_TEST' TO itab.

In the above internal can we replace ‘SO’ with only ‘S’.I tried using statement

REPLACE ALL OCCURRENCES OF REGEX  '\b(SO)\b'
IN TABLE itab WITH 'S'
RESPECTING CASE .


But its not working.Please advise.


Thanks

prabahran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,061

Hi,

REPLACE ALL OCCURRENCES OF 'SO' IN itab WITH ' S'.

Regards,

Vijay

Hello Experts,

  I have internal table like shown below.

APPEND 'SO_SEL' TO itab.
APPEND 'SO_TEST' TO itab.

In the above internal can we replace ‘SO’ with only ‘S’.I tried using statement

REPLACE ALL OCCURRENCES OF REGEX  '\b(SO)\b'
IN TABLE itab WITH 'S'
RESPECTING CASE .


But its not working.Please advise.


Thanks

prabahran

7 REPLIES 7
Read only

Former Member
0 Likes
4,062

Hi,

REPLACE ALL OCCURRENCES OF 'SO' IN itab WITH ' S'.

Regards,

Vijay

Read only

0 Likes
4,061

Hi Vijay,

I tried as per your suggestion but its not working.Please see the below screenshots(Before & After Replace statement). 'SO' gets replaced by 'S' in column SELANAME but 'S' present in the column 'KIND' gets shifted into column 'SELNAME'.Please advise if i am wrong.

Thanks

prabahran

 

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
4,061

Have you already tried with the CHARACTER/BYTE MODE additions?

Read only

0 Likes
4,061

hi Prabaharan ,

could you tell me how you are using the replace statement ?

i tried myself , not getting such prblm  :

types : begin of ty_sel,
          selname(8),
          kind(1),
         end of ty_sel.

data : pt_selection type standard table of ty_sel,
         wa_sel type ty_sel.

wa_sel-selname = 'p_fmarea'.
wa_sel-kind    = 'P'.
append wa_sel to pt_selection.

wa_sel-selname = 'p_layout'.
wa_sel-kind    = 'P'.
append wa_sel to pt_selection.

wa_sel-selname = 'SO_ABCAX'.
wa_sel-kind    = 'S'.
append wa_sel to pt_selection.

wa_sel-selname = 'SO_XYZ'.
wa_sel-kind    = 'S'.
append wa_sel to pt_selection.

wa_sel-selname = 'SO_PQR'.
wa_sel-kind    = 'S'.
append wa_sel to pt_selection.

LOOP AT pt_selection into wa_sel.
replace all occurrences of 'SO' in wa_sel-selname with 'S'.
modify pt_selection from wa_sel.
ENDLOOP.

Read only

0 Likes
4,061

Hi Yogesh,

could you tell me how you are using the replace statement ?

REPLACE ALL OCCURRENCES OF REGEX 'SO_'   IN TABLE itab WITH 'S_'

RESPECTING CASE.

i didnt loop the table instead i used the above statement.

Thanks

prabaharan

Read only

0 Likes
4,061

hi prabaharan ,

I consider it you do it by looping the table & replacing in the field.

OR

define the field ( in which you need replacement ) as the last field in internal table.

when you are using

REPLACE ALL OCCURRENCES OF REGEX 'SO_'   IN TABLE itab WITH 'S_'

RESPECTING CASE.


TABLE itab is being considered as string here , when you are replacing 'SO_' with 'S_' , actually you are replacing 3 characters by 2 characters , hence all the characters on right are being shifted one place to left .


Read only

Former Member
0 Likes
4,061

Hi ,

Modify your code  as below:

APPEND 'SO_SEL' TO itab.
APPEND 'SO_TEST' TO itab.

REPLACE ALL OCCURRENCES OF REGEX 'SO'
   IN TABLE itab WITH 'S'
   RESPECTING CASE.

This worked for me

Thanks.