‎2016 Aug 05 9:30 AM
Hello together,
i use message controll to send a mail with an attached pdf file. This is no problem. Also the mail subject I changed with a variable and I got it. But how I can replace a Variable in the Mailtext? I created a text in so10 and if i write there normal text i get in the mail body. I tried to fill the variable with the FM
SET_TEXTSYMBOL. In the message control class i put for the replace of text symbols the routine: SAPMV45A TEXT_SYMBOL_REPLACE.
‎2016 Aug 05 10:37 AM
Hi
I've developed a solution like yours for my program but:
- The text for mail is managed by a custom editor developed by class CL_GUI_TEXTEDIT
- The user can create a text using some variables, but of course only certain variables can be used
- The text is saved in a std text
So before sending the mail the standard text is read, the variable are replaced and at tne end the body text is generated:
- I've get the text by fm read_text
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = STXH-TDID
LANGUAGE = STXH-TDSPRAS
NAME = STXH-TDNAME
OBJECT = STXH-TDOBJECT
IMPORTING
HEADER = THEAD
TABLES
LINES = TLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
- As I've written before only certain variable can be used, the variable managed by my program of course: here the variable for the text are filled:
FORM INIT_VARIABLE .
DATA: _LFA1 TYPE LFA1.
* Year
MOVE ZACMDS0093-GJAHR TO ACM_YEAR.
* Period
CONCATENATE ZACMDS0093-MONAT '/' ZACMDS0093-GJAHR INTO ACM_PERIOD.
* Vendor code
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = ZACMDS0093-LIFNR
IMPORTING
OUTPUT = ACM_VENDOR.
* Vendor name
ACM_COMPANY = ZACMDS0093-BUKRS.
IF ZACMDS0093-KSCHL = CA_KSCHL_PREF.
ACM_NAME = PROFORMA_DATA-VENDOR-NAME1.
ACM_COMP_NAME = PROFORMA_DATA-COMPANY-BUTXT.
ELSE.
* Get company data
IF T001-BUKRS <> ZACMDS0093-BUKRS.
SELECT SINGLE *
FROM T001
WHERE BUKRS = ZACMDS0093-BUKRS.
IF SY-SUBRC <> 0.
CLEAR T001.
T001-BUKRS = ZACMDS0093-BUKRS.
ENDIF.
ENDIF.
* Master vendor data
CALL FUNCTION 'Z_ACM_READ_LFA1'
EXPORTING
LIFNR = ZACMDS0093-LIFNR
BUKRS = ZACMDS0093-BUKRS
IMPORTING
E_LFA1 = _LFA1.
ACM_NAME = _LFA1-NAME1.
ACM_COMP_NAME = T001-BUTXT.
ENDIF.
WRITE SY-DATUM TO ACM_DATE.
ENDFORM. " INIT_VARIABLE
The variables have to be defined as global data in the program:
*-----------------------GLOBAL VALUE FOR TEXT -------------------------*
DATA: ACM_PERIOD(7) TYPE C,
ACM_VENDOR(10) TYPE C,
ACM_NAME(40) TYPE C,
ACM_COMPANY(4) TYPE C,
ACM_COMP_NAME(40) TYPE C,
ACM_DATE(10) TYPE C,
ACM_YEAR(4) TYPE C.
So it can replace them by fms TEXT_INCLUDE_REPLACE (but I don't use include text) and TEXT_SYMBOL_REPLACE
TLINES_MSG = TLINES.
IF NOT THEAD IS INITIAL.
TEXT_PROGRAM = SY-REPID.
CALL FUNCTION 'TEXT_INCLUDE_REPLACE'
EXPORTING
HEADER = THEAD
PROGRAM = TEXT_PROGRAM
IMPORTING
NEWHEADER = THEAD
TABLES
LINES = TLINES_MSG.
CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
EXPORTING
HEADER = THEAD
PROGRAM = TEXT_PROGRAM
IMPORTING
NEWHEADER = THEAD
TABLES
LINES = TLINES_MSG.
ENDIF.
It's important to indicate in which program the variables are defined:
TEXT_PROGRAM = SY-REPID.
Max
‎2016 Aug 05 10:37 AM
Hi
I've developed a solution like yours for my program but:
- The text for mail is managed by a custom editor developed by class CL_GUI_TEXTEDIT
- The user can create a text using some variables, but of course only certain variables can be used
- The text is saved in a std text
So before sending the mail the standard text is read, the variable are replaced and at tne end the body text is generated:
- I've get the text by fm read_text
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = STXH-TDID
LANGUAGE = STXH-TDSPRAS
NAME = STXH-TDNAME
OBJECT = STXH-TDOBJECT
IMPORTING
HEADER = THEAD
TABLES
LINES = TLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
- As I've written before only certain variable can be used, the variable managed by my program of course: here the variable for the text are filled:
FORM INIT_VARIABLE .
DATA: _LFA1 TYPE LFA1.
* Year
MOVE ZACMDS0093-GJAHR TO ACM_YEAR.
* Period
CONCATENATE ZACMDS0093-MONAT '/' ZACMDS0093-GJAHR INTO ACM_PERIOD.
* Vendor code
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = ZACMDS0093-LIFNR
IMPORTING
OUTPUT = ACM_VENDOR.
* Vendor name
ACM_COMPANY = ZACMDS0093-BUKRS.
IF ZACMDS0093-KSCHL = CA_KSCHL_PREF.
ACM_NAME = PROFORMA_DATA-VENDOR-NAME1.
ACM_COMP_NAME = PROFORMA_DATA-COMPANY-BUTXT.
ELSE.
* Get company data
IF T001-BUKRS <> ZACMDS0093-BUKRS.
SELECT SINGLE *
FROM T001
WHERE BUKRS = ZACMDS0093-BUKRS.
IF SY-SUBRC <> 0.
CLEAR T001.
T001-BUKRS = ZACMDS0093-BUKRS.
ENDIF.
ENDIF.
* Master vendor data
CALL FUNCTION 'Z_ACM_READ_LFA1'
EXPORTING
LIFNR = ZACMDS0093-LIFNR
BUKRS = ZACMDS0093-BUKRS
IMPORTING
E_LFA1 = _LFA1.
ACM_NAME = _LFA1-NAME1.
ACM_COMP_NAME = T001-BUTXT.
ENDIF.
WRITE SY-DATUM TO ACM_DATE.
ENDFORM. " INIT_VARIABLE
The variables have to be defined as global data in the program:
*-----------------------GLOBAL VALUE FOR TEXT -------------------------*
DATA: ACM_PERIOD(7) TYPE C,
ACM_VENDOR(10) TYPE C,
ACM_NAME(40) TYPE C,
ACM_COMPANY(4) TYPE C,
ACM_COMP_NAME(40) TYPE C,
ACM_DATE(10) TYPE C,
ACM_YEAR(4) TYPE C.
So it can replace them by fms TEXT_INCLUDE_REPLACE (but I don't use include text) and TEXT_SYMBOL_REPLACE
TLINES_MSG = TLINES.
IF NOT THEAD IS INITIAL.
TEXT_PROGRAM = SY-REPID.
CALL FUNCTION 'TEXT_INCLUDE_REPLACE'
EXPORTING
HEADER = THEAD
PROGRAM = TEXT_PROGRAM
IMPORTING
NEWHEADER = THEAD
TABLES
LINES = TLINES_MSG.
CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
EXPORTING
HEADER = THEAD
PROGRAM = TEXT_PROGRAM
IMPORTING
NEWHEADER = THEAD
TABLES
LINES = TLINES_MSG.
ENDIF.
It's important to indicate in which program the variables are defined:
TEXT_PROGRAM = SY-REPID.
Max
‎2016 Aug 05 12:41 PM
Thank you. In the debugger I can see that i got the value for the symbol. But now I get the Mail only with the attachement there is no text and no variable. the standard text isnt shown.
‎2016 Aug 05 1:24 PM
‎2016 Aug 07 11:38 AM
I do it in my driver program which I use for a massage class in NACE