Skip to Content

TEXT_SYMBOL_REPLACE for variables longer than 132 char?

Hi all,

I am replacing variables in standard texts correctly using FMs INIT_TEXTSYMBOL, GET_TEXTSYMBOL, SET_TEXTSYMBOL and TEXT_SYMBOL_REPLACE.

The problem is that when I use TEXT_SYMBOL_REPLACE, the content of my variable is longer than 132 char (used in tables parameter 'LINES'), so the output results in my variable being truncated.

Anybody could help me? Thank you very much

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Feb 10, 2017 at 09:18 PM

    I think you can't use symbols of more than 132 characters. A workaround could be defining several symbols in the text (pay attention to not split words).

    Add comment
    10|10000 characters needed characters exceeded

    • In fact, I think the limit is 131 characters, not 132 (tested in 7.31). Anyway, one generic solution is to replace repeatedly with 131 characters at a time, then add a symbol at the end of these 131 characters for the rest of characters, repeat again, until all characters of the symbol appear in the SAPscript text (kind of recursive).

      DATA longtext(2000) TYPE c.
      DATA ls_header TYPE thead.
      DATA ls_line TYPE tline.
      DATA lt_line TYPE TABLE OF tline.
      ls_header-tdspras = sy-langu.
      ls_header-tdlinesize = 72.
      ls_line-tdformat = '/'.
      ls_line-tdline = 'START&LONGTEXT&END'.
      APPEND ls_line TO lt_line.
      'Lorem ipsum dolor sit amet, consectetur adipiscing '
      'elit, sed do eiusmod tempor incididunt ut labore et '
      'dolore magna aliqua. Ut enim ad minim veniam, quis '
      'nostrud exercitation ullamco laboris nisi ut aliquip ex '
      'ea commodo consequat. Duis aute irure dolor in '
      'reprehenderit in voluptate velit esse cillum dolore eu '
      'fugiat nulla pariatur. Excepteur sint occaecat '
      'cupidatat non proident, sunt in culpa qui officia '
      'deserunt mollit anim id est laborum.'
      PERFORM text_symbol_replace USING ls_header CHANGING lt_line.
      LOOP AT lt_line INTO ls_line.
        WRITE : / ls_line-tdline.
      *&      Form  text_symbol_replace
      FORM text_symbol_replace
              is_header TYPE thead
              ct_line   TYPE tline_tab.
        TYPES : BEGIN OF ty_ls_longsymbol,
                  name            TYPE itcst-name,
                  itfname         TYPE itcst-name, "symbol name in form &SYMBOL&
                  tempname        TYPE itcst-name, "symbol name in form ^SYMBOL$
                  symendoff       TYPE i, " highest offset at end of "max_text" where symbol can be located
                  original_value  TYPE string,
                  work_value      TYPE string,
                  ref_value       TYPE REF TO data,
                  fully_replaced  TYPE abap_bool,
                  pos             TYPE i,
                END OF ty_ls_longsymbol.
              max_len           TYPE i VALUE 131.
        DATA: lt_symbol         TYPE TABLE OF itcst,
              max_text(max_len) TYPE c,
              ls_longsymbol     TYPE ty_ls_longsymbol,
              lt_longsymbol     TYPE TABLE OF ty_ls_longsymbol,
              type              TYPE abap_typekind.
              <ls_longsymbol>   TYPE ty_ls_longsymbol,
              <ls_symbol>       TYPE itcst,
              <field>           TYPE simple.
        " Get the list of symbol names contained in the SAPscript text
            lines   = ct_line
            symbols = lt_symbol.
        " Get those symbols whose values are C or STRING with value longer
        " than 131 (if any) and store them for later special processing
            " NOTE : there's a maximum of 131 characters because for some
            " reason TEXT_SYMBOL_REPLACE ignores the 132th character (731).
        LOOP AT lt_symbol ASSIGNING <ls_symbol>.
          ASSIGN (<ls_symbol>-name) TO <field>.
          IF sy-subrc = 0.
            DESCRIBE FIELD <field> TYPE type.
            IF type CA 'Cg' AND strlen( <field> ) > max_len.
              ls_longsymbol-name = <ls_symbol>-name.
              CONCATENATE '&' <ls_symbol>-name '&' INTO ls_longsymbol-itfname.
              CONCATENATE '^' <ls_symbol>-name '$' INTO ls_longsymbol-tempname.
              ls_longsymbol-symendoff = max_len - strlen( ls_longsymbol-itfname ).
              ls_longsymbol-original_value = <field>.
              ls_longsymbol-work_value = <field>.
              ls_longsymbol-fully_replaced = abap_false.
              APPEND ls_longsymbol TO lt_longsymbol.
          LOOP AT lt_longsymbol ASSIGNING <ls_longsymbol> WHERE fully_replaced = abap_false.
            max_text = <ls_longsymbol>-work_value.
            IF strlen( <ls_longsymbol>-work_value ) > max_len.
              " regex to get last word:
              " if the LONGTEXT symbol/variable is 143 characters as follows (from position 106) :
              " 6789 110 456789 120 456789 130 456789 140
              " sed do eiusmod tempor incididunt ut labore
              " it will be replaced with a text containing the pseudo symbol which must not be longer than 131 characters :
              " 6789 110 456789 120 456789 130
              " sed do eiusmod ^LONGTEXT$
              FIND REGEX ' [^ ]+$' IN max_text(<ls_longsymbol>-symendoff) MATCH OFFSET <ls_longsymbol>-pos.
              IF sy-subrc = 0.
                ADD 1 TO <ls_longsymbol>-pos.
                <ls_longsymbol>-pos = <ls_longsymbol>-symendoff.
              max_text+<ls_longsymbol>-pos = <ls_longsymbol>-tempname.
              <ls_longsymbol>-fully_replaced = abap_true.
            ASSIGN <ls_longsymbol>-ref_value->* TO <field>.
            <field> = max_text.
              header = is_header
              lines  = ct_line.
          LOOP AT lt_longsymbol ASSIGNING <ls_longsymbol> WHERE fully_replaced = abap_false.
            REPLACE ALL OCCURRENCES OF <ls_longsymbol>-tempname IN TABLE ct_line WITH <ls_longsymbol>-itfname.
            <ls_longsymbol>-work_value = <ls_longsymbol>-work_value+<ls_longsymbol>-pos.
          IF sy-subrc <> 0.
            " all symbols are fully replaced
        " restore original symbol values
        LOOP AT lt_longsymbol ASSIGNING <ls_longsymbol>.
          ASSIGN <ls_longsymbol>-ref_value->* TO <field>.
          <field> = <ls_longsymbol>-original_value.
      ENDFORM.                    "text_symbol_replace 
  • Feb 11, 2017 at 12:11 PM

    Thank you Sandra, but I need to use symbols of more than 132 characters, and I don't want to define more than one symbol...

    Add comment
    10|10000 characters needed characters exceeded