Hello everyone,
I made a sample program that is collecting some data from any table in SAP (in my example its from KNA1) and sending that data to email address as .xlsx attachment. In my system it works exactly as it should. However, when I copied it to another system and tried to execute it its not working. Program is catching CX_BCS exception everytime it gets to the line of code that is adding attachment to the document.
*&---------------------------------------------------------------------*
*& Report Z_TST_ALV_MAIL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_TST_ALV_MAIL_2.
DATA: gt_kna1 type table of kna1,
gr_table type REF TO cl_salv_table.
select *
from kna1
into CORRESPONDING FIELDS OF TABLE @gt_kna1.
try.
cl_salv_table=>factory(
* EXPORTING
* list_display = if_salv_c_bool_sap=>false " ALV Displayed in List Mode
* r_container = " Abstract Container for GUI Controls
* container_name =
IMPORTING
r_salv_table = gr_table " Basis Class Simple ALV Tables
CHANGING
t_table = gt_kna1
).
CATCH cx_salv_msg. " ALV: General Error Class with Message
endtry.
DATA: gv_xstring type xstring,
gv_xlen type int4,
gt_binary_table type solix_tab,
gr_request type ref to cl_bcs,
gv_body_text type bcsy_text,
gv_subject type so_obj_des,
gr_recipient type ref to if_recipient_bcs,
gr_document type ref to cl_document_bcs,
gv_size type so_obj_len.
TRY.
gv_xstring = gr_table->to_xml( if_salv_bs_xml=>c_type_xlsx ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gv_xstring
* APPEND_TO_TABLE = ' '
IMPORTING
OUTPUT_LENGTH = gv_xlen
tables
binary_tab = gt_binary_table
.
gr_request = cl_bcs=>create_persistent( ).
APPEND 'Dear tester, the customer data is in excel file' TO gv_body_text.
gv_subject = 'Customer data'.
gr_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_subject = gv_subject
* i_length =
* i_language = space
* i_importance =
* i_sensitivity =
i_text = gv_body_text
* i_hex =
* i_header =
* i_sender =
* iv_vsi_profile =
).
* CATCH cx_document_bcs. " BCS: Document Exceptions
gv_size = gv_xlen.
gr_document->add_attachment(
i_attachment_type = 'EXT'
i_attachment_subject = gv_subject && '.xlsx'
i_attachment_size = gv_size
i_att_content_hex = gt_binary_table ).
gr_request->set_document( gr_document ).
gr_recipient = cl_cam_address_bcs=>create_internet_address( 'testing@test.com' ).
gr_request->add_recipient( gr_recipient ).
gr_request->send( ).
MESSAGE 'E-mail sent.' TYPE 'S'.
CATCH cx_bcs.
MESSAGE 'E-mail not sent!' TYPE 'A'.
ENDTRY.
COMMIT WORK.
Further debbuging (into gr_document->add_attachment(...) ) showed me that the exception is issued while trying to execute FM: SDOK_PHIO_STORE_CONTENT
And sy-subrc is equal '2'. So the exception is "NOT ALLOWED"

If anyone can help me solve this issue, please do. In any case, thanks for your time.
Best regards.