Supported by

Insert variables in standard texts

Everyone uses standard texts. But did you know that standard texts can have dynamic fields in the middle? SAP calls them “text symbols”. The way to do it is identical to that of the old forms of the harmful SE71, in other words wrapping them in the & symbol. Thus: &KNA1-NAME1&. It’s really handy. I’ll show you how it’s done.

First of all you have to define the text in SO10. Choose an ID (which represents a group of texts), then a unique name for our text and finally the language in which you are going to define it:

Next, define the text:


Now the text is defined you can get it anywhere using the READ_TEXT function. The result of this function is an internal table with the lines of the text:

As you see, the dynamic fields to be replaced are still there. So far, everything is standard. Now comes the trick. We are going to use two functions for this: TEXT_SYMBOL_SETVALUE and TEXT_SYMBOL_REPLACE. The first must be invoked once for each text symbol to individually replace each one for the desired value. This just prepares these changes in the memory. The second function has to be invoked to make the changes effective. All together it is like this:

DATA: w_thead TYPE thead,
           t_tline TYPE STANDARD TABLE OF tline.

        id                      = 'ZZST'
        language                = 'P'
        name                    = 'ABAPINHO'
        object                  = 'TEXT'
        header                  = w_thead
        lines                   = t_tline
        id                      = 1
        language                = 2
        name                    = 3
        not_found               = 4
        object                  = 5
        reference_check         = 6
        wrong_access_to_archive = 7
        OTHERS                  = 8.
   CHECK sy-subrc = 0.

*     Substitui valor da encomenda
            name  = '&VBAK-NETWR&'
            value = w_vbak-netwr.

*      Substitui moeda da encomenda
            name  = '&VBAK-WAERK&'
            value = w_vbak-waerk.

            header = w_thead
            lines  = t_tline.

If you look at the lines now you will see that the symbols have been replaced with the desired values.

The letter can now be sent to make another mother and child happy.

Greetings from Abapinho.

4 comentários a “Insert variables in standard texts”

  1. Fernando Diz:

    Como faço para imprimir este texto que foi alterado?

  2. admin Diz:

    Para imprimir onde? Se for para o ecrã podes fazer WRITE do T_TLINE :)

  3. name Diz:

    I think the second screenshot is not the right one.

  4. Nuno Godinho Diz:

    Thanks, I have corrected it.

Deixe um comentário

About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).