Skip to Content
avatar image
Former Member

Special Character Replacement.

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....

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Dec 22, 2014 at 07: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 22, 2014 at 06: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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • Dec 22, 2014 at 06:59 AM

    Hi,

    Try,

    DATA text TYPE string VALUE 'xxababcdcdxx'.

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



    Hope it helpful.


    Regards,

    Venkat.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 22, 2014 at 07: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.

    Add comment
    10|10000 characters needed characters exceeded