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

Special Character Replacement.

Former Member
0 Likes
1,897

Hello Gurus,

I have a requirement where in i have to replace the special character.

EG:

TEXT : Vendor & is not defined in company code &

Value1 E3008991

Value2 1101

i need to replace the '&' with specific value. if there are 3 '&''s in a text i need to replace all the 3 with different values.

I want the final output like this :

Vendor E3008991 is not defined in company code 1101

Can any one plz guide me....

1 ACCEPTED SOLUTION
Read only

yogendra_bhaskar
Contributor
0 Likes
1,818

Hi Saikanth ,

Try this code :

data : lv_text(100) VALUE 'Vendor & is not defined in company code &' ,

        Value1(8) value  'E3008991' ,

        Value2(4) VALUE  '1101'.

WRITE : lv_text.

REPLACE FIRST OCCURRENCE OF '&' IN lv_text WITH Value1.

REPLACE FIRST OCCURRENCE OF '&' IN lv_text WITH Value2.

WRITE : lv_text.



Regards


Yogendra Bhaskar

10 REPLIES 10
Read only

archanapawar
Contributor
0 Likes
1,818

Hi Saikanth,

Use message class to fulfill this requirement.

MESSAGE e035 with value1 value2.

Or you can use text elements instead to fulfill the requirement.

Read only

0 Likes
1,818

But the text that i'm fetching is from the internal table and i dnt know how many & will be present for a text. based on the & i need to replace with values

Read only

0 Likes
1,818

Hi Saikant,

I am little confused with your question now.

If you don't know how many & you will be getting in work area, how will you know what values you need to put in each of the &?

In addition to that, from where are you fetching this text into internal table?

Read only

0 Likes
1,818

From the EDIDS table i'm fetching the

STATXT - status text

STAPA1 - parameter1

STAPA2 - parameter2

STAPA3 - parameter3

STAPA4 - parameter4

into an internal table.

In the status text i need to replace the '&' with the parameters.

in some of the status text there are 3'&''s and in some there are 2&'s. i need to replace the & of the status text in the sequential order with the parameters 1,2,3,4

Read only

0 Likes
1,818

Hi Saikant,

Use FM 'MESSAGE_PREPARE' to display the message. You can pass message ID, number from EDIDS and use fields STAPA1, STAPA2, STAPA3, STAPA4 to display the final message.

Refer below code:

V_MSGNO = EDIDS-STAMNO.

CALL FUNCTION 'MESSAGE_PREPARE'

  EXPORTING

    msg_id                       = EDIDS-STAMID

    msg_no                       = V_MSGNO

   MSG_VAR1                     = EDIDS-STAPA1

   MSG_VAR2                     = EDIDS-STAPA2

   MSG_VAR3                     = EDIDS-STAPA3

   MSG_VAR4                     = EDIDS-STAPA4

IMPORTING

   MSG_TEXT                     = V_TEXT.

Read only

VenkatRamesh_V
Active Contributor
0 Likes
1,818

Hi,

Try,

DATA text TYPE string VALUE 'xxababcdcdxx'.

REPLACE ALL OCCURRENCES OF 'abcd' IN text WITH ``.



Hope it helpful.


Regards,

Venkat.

Read only

yogendra_bhaskar
Contributor
0 Likes
1,819

Hi Saikanth ,

Try this code :

data : lv_text(100) VALUE 'Vendor & is not defined in company code &' ,

        Value1(8) value  'E3008991' ,

        Value2(4) VALUE  '1101'.

WRITE : lv_text.

REPLACE FIRST OCCURRENCE OF '&' IN lv_text WITH Value1.

REPLACE FIRST OCCURRENCE OF '&' IN lv_text WITH Value2.

WRITE : lv_text.



Regards


Yogendra Bhaskar

Read only

0 Likes
1,818

Thank you Guys for ur valuable suggestions...

Read only

0 Likes
1,818

I hope your issue is resolved. If it is resolved, kindly close the thread.

Read only

Former Member
0 Likes
1,818

Hi Saikanth,

Use this below code, I hope it's useful for your requirement.

DATA : text TYPE string,

        value1 TYPE char8 VALUE 'E3008991',

        value2 TYPE char4 VALUE '1101',

        lv_lv TYPE string,

        lv_lv1 TYPE string,

        indx TYPE sy-index VALUE '1'.

DATA : lv_split TYPE TABLE OF char40,

        lv_wa TYPE string.

text 'Vendor &&& is not defined in company code &&&'.

SPLIT text AT '&' INTO TABLE lv_split.

CLEAR text.

LOOP AT lv_split INTO lv_wa .

   IF lv_wa IS NOT INITIAL.

     IF indx = 1.

       lv_lv = lv_wa.

     ELSEIF indx = sy-tabix.

       lv_lv1 = lv_wa.

     ENDIF.

   ENDIF.

       indx = sy-tabix + 1.

   CLEAR lv_wa.

ENDLOOP.

CONCATENATE lv_lv value1 lv_lv1 value2 INTO text SEPARATED BY space.

MESSAGE text TYPE 'S'.


Regard,


Karthik.