2014 Dec 22 6:36 AM
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....
2014 Dec 22 7:10 AM
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
2014 Dec 22 6:42 AM
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.
2014 Dec 22 6:47 AM
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
2014 Dec 22 6:51 AM
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?
2014 Dec 22 6:57 AM
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
2014 Dec 22 7:07 AM
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.
2014 Dec 22 6:59 AM
Hi,
Try,
DATA text TYPE string VALUE 'xxababcdcdxx'.
REPLACE ALL OCCURRENCES OF 'abcd' IN text WITH ``.
Hope it helpful.
Regards,
Venkat.
2014 Dec 22 7:10 AM
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
2014 Dec 22 7:17 AM
2014 Dec 22 7:32 AM
I hope your issue is resolved. If it is resolved, kindly close the thread.
2014 Dec 22 7:39 AM
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.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |