02-22-2013 10:03 PM
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
02-27-2013 5:52 PM
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
02-23-2013 9:48 AM
Hello,
I think it is nothing to do with method of class. It should work inside the class also but may be there are some problems in your program I beleieve which is not allowing to populate your dynamic variables.
Thanks,
Abhijit
02-23-2013 5:45 PM
Hi Abhijit,
The same code works just fine in a program. The READ_TEXT & TEXT_SYMBOL_REPLACE. However, in a class method, the function is not able to pull in the variables.
I have declared the variables within the class method. So for the dynamic replacement, i am not sure why it's not able to see those variables.
Is there another simply way to do the replacement? I have to avoid hardcoding the replacements and instead drive it from the HTML template.
Regards,
Jay
02-25-2013 3:42 AM
This call from a class method does not work:
method CHANGE_HTML.
DATA: ls_head TYPE thead,
lt_lines TYPE tlinetab,
wa_line TYPE tline.
**Trip Header Variables
DATA: v_companycode TYPE string VALUE '1000',
v_invoice TYPE string VALUE '000001234',
v_start_date TYPE string VALUE '02/20/2013',
v_reim_total TYPE string VALUE '200.00',
v_amt_cc TYPE string VALUE '150.00',
v_amt_emp TYPE string VALUE '50.00',
v_trip_no TYPE string,
v_request TYPE string VALUE 'Requestor Name'.
* Read the HTML Template
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = 'ST'
language = sy-langu
name = 'ZTRAVELEXPENSE_APPROVAL_HTML'
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.
MESSAGE 'Could not replace the fields' TYPE 'I'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
EXPORTING
* ENDLINE = 99999
header = ls_head
* INIT = ' '
* OPTION_DIALOG = ' '
program = sy-cprog
replace_program = 'X'
replace_standard = ' '
replace_system = 'X'
replace_text = 'X'
startline = 1
* IMPORTING
* CHANGED =
* NEWHEADER =
TABLES
lines = lt_lines
.
endmethod.
If I take the same code from the method and put this in a program, the TEXT_ELEMENT_REPLACE works just fine. So I am not sure if it's an issue with calling this in a class.
02-27-2013 5:52 PM
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
02-28-2013 7:55 PM
Thanks Kaushik.
That approach works.
I am able to replace the text symbols within the class by explicitly defining the text symbols that way.
Regards,
Jay