on 2023 Aug 03 2:36 PM
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.
Hi Luka,
something seems not to fit when saving the email file. You can look for permission problems (TA: SU53). If it is possibly a permission problem.
What I also noticed, you have entered as i_attachment_type = 'EXT'. When sending the file it is sent without the correct file type.
With i_attachment_type = 'XLS' you send an Excel file. Try it with this.
Regards
Jim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear turkaj,
Firs of all, thank you for your time and input.
I checked SU53, it says that "the last authorization check was successful". I think its not authorization check because there is another exception "NOT _AUTHORIZED". I guess thats the exception that would be caught in that case.
I changed the attachment type to 'EXT' as you proposed, but the same exception is caught.
Any other ideas? Why would this not be allowed?
While trying to find some answers, I saw that this FM (SDOK_PHIO_STORE_CONTENT) is used for storing content in the Kpro (knowledge provider) service. However, I don't know anything about this. Maybe this additional information could help you (or someone else) help me.
Regards,
Luka.
Attachment type 'EXT' should not be a problem. The file name and extension are in the attachment name (subject), or possibly in &SO_FILENAME=xxxxxxxxxxxx if the extension is 4 or more characters e.g., .xlsx.
EDIT: I see that you're trying to attach .xlsx, you should use &SO_FILENAME=xxxxxxxxxxxx.xlsx. I don't know if it's the reason of the exception.
i_attachment_header = VALUE #( ( line = |&SO_FILENAME=List_of_roles.xlsx| ) )
Thanks to both of you for suggestions, like I said I tested this program in another system and its working fine. Nevertheless I will try adding the i_attachment_header like Sandra suggested and I will also see if I can find anything in SCOT settings that could causing the exception.
If theres any other suggestions feel free to write them 🙂
User | Count |
---|---|
109 | |
9 | |
8 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.