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: 

About replace stmt

Former Member
0 Kudos

Hi,

I have a string say 'C100C110C120*( 100-C130 )', in which c100,c110,c120... are different batch characteristics.

String and Batch characteristics may vary from batch to batch.

what i need to do is to replace these c100,c110 etc..with some values related to them .

ie: c100 with 500, c110 with 250, etc...

One way to do it is by using find and replace statements,

like

FIND 'C100' IN str.

if sy-subrc = 0.

REPLACE ALL OCCURRENCES OF REGEX 'C100' IN STR WITH '500'.

write str.

endif.

But there may be number of characteristics....and i need to repeat the above procedure n times for n number of batches.

so is there any alternative to do it???

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Mr.A,

Create an internal table just to hold the BATCH CHARACTERISTICs and their respective REPLACEMENT values.

Loop this internal table and do as you given in the example.

Instead of that Hardcoded value put the workarea.

i.e.


  LOOP AT IT_BATCH INTO WA_BATCH.
    FIND WA_BATCH-BC IN str.
    if sy-subrc = 0.
      REPLACE ALL OCCURRENCES OF REGEX WA_BATCH-BC IN STR WITH WA_BATCH-RV.
      write str.
    endif.
  ENDLOOP.

Here, BC is the Batch Characteristics.

RV is the Replacement Value.

Regards,

R.Nagarajan.

-


We can -


1 REPLY 1

Former Member
0 Kudos

Hi Mr.A,

Create an internal table just to hold the BATCH CHARACTERISTICs and their respective REPLACEMENT values.

Loop this internal table and do as you given in the example.

Instead of that Hardcoded value put the workarea.

i.e.


  LOOP AT IT_BATCH INTO WA_BATCH.
    FIND WA_BATCH-BC IN str.
    if sy-subrc = 0.
      REPLACE ALL OCCURRENCES OF REGEX WA_BATCH-BC IN STR WITH WA_BATCH-RV.
      write str.
    endif.
  ENDLOOP.

Here, BC is the Batch Characteristics.

RV is the Replacement Value.

Regards,

R.Nagarajan.

-


We can -