Application Development 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: 

Code

Former Member
0 Kudos

Hi ,

There is a single field in an ITAB I need to check th field and replace some characters for example:

ITAB-f1 = 130 " front & 12 " back

I need to change it like this :

130 inches front and 12 inches back

anyone please give me the code.

Thanks

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

If you are on a 46c release, you can to this.



report zrich_0001 .

data: begin of itab occurs 0,
      str type string,
      end of itab.


itab-str =  '130 " front & 12 " back'.
append itab.


loop at itab.
  while sy-subrc = 0.
    replace '"' with 'inches' into itab-str.
    replace '&' with 'and' into itab-str.
  endwhile.
  modify itab.
endloop.



loop at itab.
  write:/ itab-str.
endloop.

With newer releases, the REPLACE statement allows you to do ALL OCCURANCES, which means that you don't need the WHILE to loop it.

Regards,

Rich Heilman

3 REPLIES 3

amit_khare
Active Contributor
0 Kudos

Hi,

You can use REPLACE command or try this FM STRING_REPLACE

Regards,

Amit

Former Member
0 Kudos

Hi,

Loop at ITAB.
REPLACE '''' with 'Inches' into itab-f1.
REPLACE '&' with 'and' into itab-f1.
modify ITAB.
Endloop.

Regards

Sudheer

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

If you are on a 46c release, you can to this.



report zrich_0001 .

data: begin of itab occurs 0,
      str type string,
      end of itab.


itab-str =  '130 " front & 12 " back'.
append itab.


loop at itab.
  while sy-subrc = 0.
    replace '"' with 'inches' into itab-str.
    replace '&' with 'and' into itab-str.
  endwhile.
  modify itab.
endloop.



loop at itab.
  write:/ itab-str.
endloop.

With newer releases, the REPLACE statement allows you to do ALL OCCURANCES, which means that you don't need the WHILE to loop it.

Regards,

Rich Heilman