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: 

FM TEXT_SYMBOL_REPLACE refuses to replace &EKKO-AEDAT&

Mithun_Kumar
Active Participant
0 Kudos
2,017

Hi, I've a simple requirement to replace some text symbols in a standard text with actual data. The std text is like this:

My Code is in a BAdI implementation class, is like this:

    DATA: lv_textsym TYPE string,
          ekko       TYPE ekko.

    CALL FUNCTION 'ME_EKKO_SINGLE_READ'
      EXPORTING
        pi_ebeln         = CONV ebeln( is_nast-objky )                " Purchasing Document Number
      IMPORTING
        po_ekko          = ekko                 " Purchasing Document Header
      EXCEPTIONS
        no_records_found = 1
        OTHERS           = 2.

    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      RETURN.
    ENDIF.

    CHECK sy-subrc EQ 0.
    SELECT SINGLE name1 FROM  adrc AS a
                        INNER JOIN t001 AS t
                                ON t~adrnr = a~addrnumber
                               AND t~bukrs  = @ekko-bukrs
           INTO @DATA(x_t001_name1).

    CALL FUNCTION 'INIT_TEXTSYMBOL'.

    LOOP AT lt_tlines INTO DATA(ls_line).
      FIND ALL OCCURRENCES OF '&' IN ls_line-tdline RESULTS DATA(lt_result).
      LOOP AT lt_result INTO DATA(ls_result).
        CHECK sy-tabix MOD 2 = 1.
        CALL FUNCTION 'GET_TEXTSYMBOL'
          EXPORTING
            line         = ls_line-tdline
            start_offset = ls_result-offset
          IMPORTING
            name         = lv_textsym.

        IF lv_textsym IS NOT INITIAL.
          ASSIGN (lv_textsym) TO FIELD-SYMBOL(<fs_textsym>).
          lv_textsym := |&{ lv_textsym }&|.

          IF <fs_textsym> IS ASSIGNED.
            CALL FUNCTION 'SET_TEXTSYMBOL'
              EXPORTING
                header       = ls_thead
                name         = lv_textsym
                value        = <fs_textsym>.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDLOOP.

    CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
      EXPORTING
        header = ls_thead
      TABLES
        lines  = lt_tlines.

    CALL FUNCTION 'FORMAT_TEXTLINES'
      EXPORTING
        formatwidth = 128
      TABLES
        lines       = lt_tlines
      EXCEPTIONS
        bound_error = 1
        OTHERS      = 2.

    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

LT_TLINES and LS_THEAD are filled with READ_TEXT as usual.

In debugging, I see the values correctly available:

But after the TEXT_SYMBOL_REPLACE, it comes out blank:

Any ideas, what could be going wrong here?

1 ACCEPTED SOLUTION

Mithun_Kumar
Active Participant
934

Thank you everyone for trying to help. It's completely strange that for some others, even my other colleagues, this issue wasn't reproduced, but for me it never worked.

Then I tried to replace the symbol in the text itself, to &EKKO-BEDAT&, and lo and behold, it worked fine! However, it's definitely not the right date the client wants, so I changed it back to &EKKO-AEDAT& and it didn't work again. Completely clueless why this field is special.

Then, I discovered a different FM, and change the code to the following:

DATA: lt_syms    TYPE TABLE OF itcst.    
.
.
.
    CALL FUNCTION 'INIT_TEXTSYMBOL'.

    CALL FUNCTION 'TEXT_SYMBOL_COLLECT'
      TABLES
        lines   = lt_tlines                 " Text lines
        symbols = lt_syms.                " Symbols found

    LOOP AT lt_syms INTO DATA(ls_symb).
      ASSIGN (ls_symb-name) TO FIELD-SYMBOL(<fs_textsym>).
      DATA(lv_textsym) = |&{ ls_symb-name }&|.

      IF <fs_textsym> IS ASSIGNED.
        CALL FUNCTION 'TEXT_SYMBOL_SETVALUE'
          EXPORTING
            name  = lv_textsym                 " Symbol name
            value = <fs_textsym>.                 " Symbol value
      ENDIF.
    ENDLOOP.

    CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
      EXPORTING
        header = ls_thead
      TABLES
        lines  = lt_tlines.

    CALL FUNCTION 'FORMAT_TEXTLINES'
      EXPORTING
        formatwidth = 128
      TABLES
        lines       = lt_tlines
      EXCEPTIONS
        bound_error = 1
        OTHERS      = 2.

Now, guess what... It works like a charm.

Somehow, the GET_TEXTSYMBOL, SET_TEXTSYMBOL pair didn't like EKKO-AEDAT specifically for me, and I've zero idea why. But anyway now this code is much smaller, and works perfectly. So I'm over and out!

14 REPLIES 14

FredericGirod
Active Contributor
0 Kudos
934

Did you try .

            CALL FUNCTION 'SET_TEXTSYMBOL'
              EXPORTING
                header       = ls_thead
                name         = lv_textsym
                value        = <fs_textsym>
                replace      = abap_true.

Mithun_Kumar
Active Participant
0 Kudos
934

Yes, frdric.girod , have tried it too. Same result...

joltdx
Active Contributor
0 Kudos
934

Hi!

I have never used these function modules so my question might be totally off, but is it correct to call GET_TEXTSYMBOL/SET_TEXTSYMBOL inside the loop and then TEXT_SYMBOL_REPLACE outside of it in this case?

Sandra_Rossi
Active Contributor
934
lv_textsym := |value|.

hmmm Pascal experience? 😉

Sandra_Rossi
Active Contributor
934

I can't reproduce your bug with this minimal code:

DATA: lv_textsym TYPE string,
      ls_thead   TYPE thead,
      lt_tlines  TYPE TABLE OF tline.

lt_tlines = VALUE #(
( tdformat = '*' tdline = |Sehr geehrte Damen und Herren| )
( tdformat = '*' tdline = |anbei erhalten Sie unsere Bestellung mit der Bestellnummer:| )
( tdformat = '*' tdline = |&EKKO-EBELN& vom &EKKO-AEDAT&| )
( tdformat = '*' tdline = |Dieses Dokument wurde elektroni sch erstellt und ist daher auch Ohne| )
( tdformat = ' ' tdline = |Unterschrift gûltig.| )
( tdformat = '*' tdline = |Mit freundlichen GrüBen| ) ).

DATA(ekko) = VALUE ekko( ebeln = '48A0005652' aedat = '20200713' ).

CALL FUNCTION 'INIT_TEXTSYMBOL'.

LOOP AT lt_tlines INTO DATA(ls_line).
  FIND ALL OCCURRENCES OF '&' IN ls_line-tdline RESULTS DATA(lt_result).
  LOOP AT lt_result INTO DATA(ls_result).
    CHECK sy-tabix MOD 2 = 1.
    CALL FUNCTION 'GET_TEXTSYMBOL'
      EXPORTING
        line         = ls_line-tdline
        start_offset = ls_result-offset
      IMPORTING
        name         = lv_textsym.

    IF lv_textsym IS NOT INITIAL.
      ASSIGN (lv_textsym) TO FIELD-SYMBOL(<fs_textsym>).
      lv_textsym := |&{ lv_textsym }&|.

      IF <fs_textsym> IS ASSIGNED.
        CALL FUNCTION 'SET_TEXTSYMBOL'
          EXPORTING
            header = ls_thead
            name   = lv_textsym
            value  = <fs_textsym>.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDLOOP.

CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
  EXPORTING
    header = ls_thead
  TABLES
    lines  = lt_tlines.

CALL FUNCTION 'FORMAT_TEXTLINES'
  EXPORTING
    formatwidth = 128
  TABLES
    lines       = lt_tlines
  EXCEPTIONS
    bound_error = 1
    OTHERS      = 2.

ASSERT 1 = 1. " debug helper

Mithun_Kumar
Active Participant
0 Kudos
934

Thanks for the effort sandra.rossi .

Ha Ha... Pascal! Did that so long ago.... Don't know how that creeped in. 😉

Anyway, it's really strange how you're not able to reproduce with the same code. And for me it's happening no matter what I try to change. Still breaking my head on it.

Even tried to change the text, removed this symbol and added again manually; still the same.

Mithun_Kumar
Active Participant
935

Thank you everyone for trying to help. It's completely strange that for some others, even my other colleagues, this issue wasn't reproduced, but for me it never worked.

Then I tried to replace the symbol in the text itself, to &EKKO-BEDAT&, and lo and behold, it worked fine! However, it's definitely not the right date the client wants, so I changed it back to &EKKO-AEDAT& and it didn't work again. Completely clueless why this field is special.

Then, I discovered a different FM, and change the code to the following:

DATA: lt_syms    TYPE TABLE OF itcst.    
.
.
.
    CALL FUNCTION 'INIT_TEXTSYMBOL'.

    CALL FUNCTION 'TEXT_SYMBOL_COLLECT'
      TABLES
        lines   = lt_tlines                 " Text lines
        symbols = lt_syms.                " Symbols found

    LOOP AT lt_syms INTO DATA(ls_symb).
      ASSIGN (ls_symb-name) TO FIELD-SYMBOL(<fs_textsym>).
      DATA(lv_textsym) = |&{ ls_symb-name }&|.

      IF <fs_textsym> IS ASSIGNED.
        CALL FUNCTION 'TEXT_SYMBOL_SETVALUE'
          EXPORTING
            name  = lv_textsym                 " Symbol name
            value = <fs_textsym>.                 " Symbol value
      ENDIF.
    ENDLOOP.

    CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
      EXPORTING
        header = ls_thead
      TABLES
        lines  = lt_tlines.

    CALL FUNCTION 'FORMAT_TEXTLINES'
      EXPORTING
        formatwidth = 128
      TABLES
        lines       = lt_tlines
      EXCEPTIONS
        bound_error = 1
        OTHERS      = 2.

Now, guess what... It works like a charm.

Somehow, the GET_TEXTSYMBOL, SET_TEXTSYMBOL pair didn't like EKKO-AEDAT specifically for me, and I've zero idea why. But anyway now this code is much smaller, and works perfectly. So I'm over and out!

934

Great to know! Anyway, that's the way to do, because TEXT_SYMBOL_* function modules are released, and not *_TEXTSYMBOL.

Sandra_Rossi
Active Contributor
0 Kudos
934

When you copy/paste my standalone code in a new program, are you saying that it doesn't work? (mine is running well on an ABAP 7.52 system)

If so, that means there's probably a SAP Note to fix that.

Mithun_Kumar
Active Participant
0 Kudos
934

I think it might be a difference between calling it in a Program vs in a class method.

matt
Active Contributor
0 Kudos
934

I think that's highly unlikely.

Mithun_Kumar
Active Participant
0 Kudos
934

Still no idea of the reason, Matthew.

Anyway, now with the new code all's working fine.

shais
Participant
934

Your original code

LOOP AT lt_tlines INTO DATA(ls_line).
  FIND ALL OCCURRENCES OF '&' IN ls_line-tdline RESULTS DATA(lt_result).
  LOOP AT lt_result INTO DATA(ls_result).
    CHECK sy-tabix MOD 2 = 1.
    CALL FUNCTION 'GET_TEXTSYMBOL'
      EXPORTING
        line         = ls_line-tdline
        start_offset = ls_result-offset
      IMPORTING
        name         = lv_textsym.

might not handle correctly a case in which the text symbol spans over more than one line.

e.g.

&EKKO-A
EDAT&

Mithun_Kumar
Active Participant
934

Yes, you're right about that. However this wasn't really the issue.

You can see the solution I found which worked perfectly.