SAP MDG · REPLICATION INBOUND
How do I implement an SAP MDG inbound email notification method that creates an Excel attachment and sends it with BCS?
Use the MDG STA inbound `SEND_EMAIL` pattern: build the mail body, convert the internal table `it_email_log1` into XLSX with SALV export utilities, convert the XSTRING to binary, then send it with `CL_BCS` and a recipient created by `CL_CAM_ADDRESS_BCS`.
Use the MDG STA inbound `SEND_EMAIL` pattern: build the mail body, convert the internal table `it_email_log1` into XLSX with SALV export utilities, convert the XSTRING to binary, then send it with `CL_BCS` and a recipient created by `CL_CAM_ADDRESS_BCS`.
The STA inbound sample uses a clear 4-step email pattern: prepare a short text body, turn `it_email_log1` into an XLSX attachment through SALV runtime utilities, convert the XSTRING to binary, and send the message with `CL_BCS`. The recipient is created with `CL_CAM_ADDRESS_BCS=>create_internet_address`, and the send result is checked before `COMMIT WORK AND WAIT`.
Process flow
- Prepare the mail body in `SOLISTI1` lines.
- Get a reference to `it_email_log1` and assign it to a generic table field-symbol.
- Use `CL_SALV_TABLE=>FACTORY` to create a SALV table on the internal table.
- Build the field catalog with `CL_SALV_CONTROLLER_METADATA=>GET_LVC_FIELDCATALOG`.
- Create result data with `CL_SALV_EX_UTIL=>FACTORY_RESULT_DATA_TABLE`.
- Transform the result to XLSX with `CL_SALV_BS_TT_UTIL=>IF_SALV_BS_TT_UTIL~TRANSFORM`.
- Convert the XSTRING to binary using `SCMS_XSTRING_TO_BINARY`.
- Create the send request with `CL_BCS=>CREATE_PERSISTENT` and build the document with `CL_DOCUMENT_BCS=>CREATE_DOCUMENT`.`,`Add the XLSX attachment with `ADD_ATTACHMENT`.`,`Create the recipient with `CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_A...
SCOT
Configure outbound SAPconnect/SMTP delivery so BCS emails can be sent.
SOST
Monitor sent, waiting, and error emails after the `CL_BCS` send call.
Referenced tables
| Object | Purpose |
|---|---|
it_email_log1 | Source internal table whose full field set is exported to the XLSX attachment. |
ILLUSTRATIVE ABAP SAMPLE
STA inbound email notification pattern
Source-supported sample based on `ZCL_SI_MDG_STA_INBOUND->SEND_EMAIL`.
1METHOD send_email.
2 DATA:
3 lo_send_request TYPE REF TO cl_bcs,
4 lo_document TYPE REF TO cl_document_bcs,
5 lo_recipient TYPE REF TO if_recipient_bcs,
6 lt_body TYPE TABLE OF solisti1,
7 ls_body TYPE solisti1,
8 lt_binary_attach TYPE solix_tab,
9 lv_subject TYPE so_obj_des VALUE 'STA Error Messages',
10 lv_sent_to_all TYPE os_boolean,
11 lo_data_ref TYPE REF TO data,
12 lo_bcs_exception TYPE REF TO cx_bcs,
13 lv_xstring TYPE xstring,
14 lo_table TYPE REF TO cl_salv_table.
15
16 FIELD-SYMBOLS: <fs_filtered> TYPE ANY TABLE.
17
18 " 1. Prepare email body text
19 CLEAR ls_body.
20 ls_body-line = 'Dear Recipient,'.
21 APPEND ls_body TO lt_body.
22
23 ls_body-line = ''.
24 APPEND ls_body TO lt_body.
25
26 ls_body-line = 'Please find attached the STA Interface Error Log with all relevant fields.'.
27 APPEND ls_body TO lt_body.
28
29 ls_body-line = ''.
30 APPEND ls_body TO lt_body.
31
32 ls_body-line = 'Regards,'.
33 APPEND ls_body TO lt_body.
34
35 ls_body-line = 'Data Governance Team'.
36 APPEND ls_body TO lt_body.
37
38 " 2. Create dynamic table structure with all fields from lt_email_log1
39 GET REFERENCE OF it_email_log1 INTO lo_data_ref.
40 ASSIGN lo_data_ref->* TO <fs_filtered>.
41
42 TRY.
43 cl_salv_table=>factory(
44 IMPORTING r_salv_table = lo_table
45 CHANGING t_table = <fs_filtered> ).
46
47 DATA(lt_fcat) = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
48 r_columns = lo_table->get_columns( )
49 r_aggregations = lo_table->get_aggregations( ) ).
50
51 DATA(lo_result) =
52 cl_salv_ex_util=>factory_result_data_table(
53 r_data = lo_data_ref
54 t_fieldcatalog = lt_fcat ).
55
56 cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform(
57 EXPORTING
58 xml_type = if_salv_bs_xml=>c_type_xlsx
59 xml_version = cl_salv_bs_a_xml_base=>get_version( )
60 r_result_data = lo_result
61 xml_flavour = if_salv_bs_c_tt=>c_tt_xml_flavour_export
62 gui_type = if_salv_bs_xml=>c_gui_type_gui
63 IMPORTING
64 xml = lv_xstring ).
65
66 CATCH cx_root INTO DATA(lx_err).
67 CLEAR lv_xstring.
68 WRITE: / 'Excel generation failed:', lx_err->get_text( ).
69 RETURN.
70 ENDTRY.
71
72 " 3. Convert to binary
73 CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
74 EXPORTING
75 buffer = lv_xstring
76 TABLES
77 binary_tab = lt_binary_attach.
78
79 " 4. Send Email
80 TRY.
81 lo_send_request = cl_bcs=>create_persistent( ).
82
83 lo_document = cl_document_bcs=>create_document(
84 i_type = 'RAW'
85 i_text = lt_body
86 i_subject = sy-sysid && ' ' && lv_subject ).
87
88 lo_document->add_attachment(
89 i_attachment_type = 'BIN'
90 i_attachment_subject = 'STA_Error_Log.xlsx'
91 i_att_content_hex = lt_binary_attach ).
92
93 lo_send_request->set_document( lo_document ).
94
95 lo_recipient = cl_cam_address_bcs=>create_internet_address( 'DL_CG_SAP_MDG@te.com' ).
96 lo_send_request->add_recipient( lo_recipient ).
97 lo_send_request->set_send_immediately( abap_true ).
98
99 lv_sent_to_all = lo_send_request->send( i_with_error_screen = abap_true ).
100
101 IF lv_sent_to_all = abap_true.
102 COMMIT WORK AND WAIT.
103 WRITE: / 'Email sent successfully to: DL_CG_SAP_MDG@te.com'.
104 ELSE.
105 WRITE: / 'Email sending failed. Check SOST or SCOT settings.'.
106 ENDIF.
107
108 CATCH cx_send_req_bcs INTO lo_bcs_exception.
109 WRITE: / 'Send error:', lo_bcs_exception->get_text( ).
110 CATCH cx_document_bcs INTO lo_bcs_exception.
111 WRITE: / 'Document creation error:', lo_bcs_exception->get_text( ).
112 CATCH cx_address_bcs INTO lo_bcs_exception.
113 WRITE: / 'Recipient address error:', lo_bcs_exception->get_text( ).
114 ENDTRY.
115
116 COMMIT WORK AND WAIT.
117
118ENDMETHOD.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I send a generated XLSX attachment from an SAP MDG inbound proxy method?
- What is the ABAP pattern for emailing STA error logs from MDG processing?
- How do I build and send an Excel attachment with CL_BCS in SAP ABAP?
Possible questions
- How do I implement an SAP MDG inbound email notification method that creates an Excel attachment and sends it with BCS?
- How can I send a generated XLSX attachment from an SAP MDG inbound proxy method?
- What is the ABAP pattern for emailing STA error logs from MDG processing?
- How do I build and send an Excel attachment with CL_BCS in SAP ABAP?
- Which MDG inbound class contains SEND_EMAIL for STA processing?