Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

TEXT_SYMBOL_REPLACE not working within a class method

I am developing a class.  I have a method that reads in a text object which has an HTML page.  I am then trying to replace the dynamic variables by calling the function TEXT_SYMBOL_REPLACE.  The function does not recognize the variables declared in the class.  If I write a program and call the function, it works.  I have tried passing in different values for the REPID.

   * Read the HTML Template
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
*     CLIENT                        = SY-MANDT
      id                            = 'ST'
      language                      = sy-langu
      name                          = 'MYHTMLTEXT'
      object                        = 'TEXT'
*     ARCHIVE_HANDLE                = 0
*     LOCAL_CAT                     = ' '
   IMPORTING
      header                        = ls_head
    TABLES
      lines                         = lt_lines
   EXCEPTIONS
      id                            = 1
      language                      = 2
      name                          = 3
      not_found                     = 4
      object                        = 5
      reference_check               = 6
      wrong_access_to_archive       = 7
      OTHERS                        = 8.


  IF sy-subrc <> 0.
...
  ENDIF.

   CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
  EXPORTING
*   ENDLINE                = 99999
    header                 =
*   INIT                   = ' '
*   OPTION_DIALOG          = ' '
   PROGRAM                = 'SY-REPID  "also tried SY-CPROG
   REPLACE_PROGRAM        = 'X'
   REPLACE_STANDARD       = 'X'
   REPLACE_SYSTEM         = 'X'
   REPLACE_TEXT           = 'X'
*   STARTLINE              = 1
* IMPORTING
*   CHANGED                =
*   NEWHEADER              =
  tables
    lines                  =  lt_lines
          .

Is there anyway to get this function to work within a class method?  Or is there another function?

My text object looks like:

<TD> &v_START_DATE& </TD>



I have a variable declared as V_START_DATE within the method.  I also tried putting in the program name at runtime:

<TD> &(ZCL_MYTESTCLASS=======CP)v_START_DATE& </TD>



Any help would be appreciated.

Thanks,

Jay



Former Member replied

Hi Jay,

TEXT_SYMBOL_REPLACE when called, within program LSTXVFCA, get_symbol_type form, while getting the dynamic field value, we read it based on the current program. So, in the case of Class SY-CPROG, doesn't hold the class name and hence it might not work in a class and instead it works in a normal report.

Hence, as an alternative, i suggest using Function Modules, INIT_TEXTSYMBOL, SET_TEXTSYMBOL and REPLACE_TEXTSYMBOL in the below pattern.

Once you call the read text function module, and get the data in lt_lines, then,

* Initialize the Text Symbols

CALL FUNCTION 'INIT_TEXTSYMBOL'.

* Declare your Dynamic Variables to be replaced

CALL FUNCTION 'SET_TEXTSYMBOL'

    EXPORTING

      NAME               = '&v_request&'

      VALUE              = 'Test ABCREQUEST'

      REPLACE            = 'X'.

     CALL FUNCTION 'SET_TEXTSYMBOL'

    EXPORTING

      NAME               = '&v_start_date&'

      VALUE              = '02/20/2013'

      REPLACE            = 'X'.

* Get the Total Count(i.e. the end count) of the lt_lines structure and call function module to replace your text symbols


DESCRIBE TABLE lt_lines LINES l_count.

     CALL FUNCTION 'REPLACE_TEXTSYMBOL'

        EXPORTING

             endline   = l_count

             startline = 1

        TABLES

             lines     = lt_lines.

Thus your structure is replaced with the intended variables.

Please reward points, if found useful.

Regards,

KK


3 View this answer in context
Not what you were looking for? View more on this topic or Ask a question