Hallo zusammen
ich habe ein Problem...
Ich möchte ein Mail verschicken mit einem .xls file als Anhang. Es zeigt aber die Spaltenname nicht an.
ich habe einige Stunden verbracht mit der Suche nach einr lösung aber es möchte einfach nicht funktionieren
Was stimmt bei mir im Programm nicht ?
Ich hoffe ihr habt eine Idee
Danke und Grüsse
Hier ist mein Code
METHOD generate_mail_and_send_it.
lo_send_request = cl_bcs=>create_persistent( ).
w_text-line = 'Test'.
APPEND w_text TO i_text.
CLEAR w_text.
lo_document = cl_document_bcs=>create_document( "create document
i_type = 'TXT' "Type of document HTM, TXT etc
i_text = i_text "email body internal table
i_subject = p_sub ). "email subject here p_sub input parameter
* Pass the document to send request
lo_send_request->set_document( lo_document ).
*-----------------------------------------------------------------------
***Set attachment *
*-----------------------------------------------------------------------
SELECT * FROM mbewh INTO TABLE it_mbewh UP TO 50 ROWS.
LOOP AT it_mbewh INTO wa_mbewh.
CONCATENATE wa_mbewh-MATNR wa_mbewh-BWKEY wa_mbewh-BWTAR wa_mbewh-aedtm INTO lv_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
CONCATENATE lv_data_string lv_string INTO lv_data_string SEPARATED BY cl_abap_char_utilities=>newline.
APPEND wa_attachment_header TO lit_attachment_header.
ENDLOOP.
*-----------------------------------------------------------------------
* Convert string to xstring *
*-----------------------------------------------------------------------
CALL FUNCTION 'HR_KR_STRING_TO_XSTRING'
EXPORTING
* codepage_to = '8300'
unicode_string = lv_data_string
* OUT_LEN =
IMPORTING
xstring_stream = lv_xstring
EXCEPTIONS
invalid_codepage = 1
invalid_string = 2
OTHERS = 3.
IF sy-subrc <> 0.
IF sy-subrc = 1 .
ELSEIF sy-subrc = 2 .
WRITE:/ 'invalid string ' .
ENDIF.
ENDIF.
*-----------------------------------------------------------------------
*Xstring to binary *
*-----------------------------------------------------------------------
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
TABLES
binary_tab = lit_binary_content.
*-----------------------------------------------------------------------
*add attachment *
*-----------------------------------------------------------------------
CLEAR l_attsubject .
CONCATENATE 'MBEWH Report' sy-datum INTO l_attsubject.
*-----------------------------------------------------------------------
* Create Attachment *
*-----------------------------------------------------------------------
lo_document->add_attachment( EXPORTING
i_attachment_type = 'XLS'
i_attachment_subject = l_attsubject
i_attachment_header = lit_attachment_header
i_att_content_hex = lit_binary_content ).
TRY.
lo_sender = cl_sapuser_bcs=>create( sy-uname ). "sender is the logged in user
*-----------------------------------------------------------------------
* Set sender to send request *
*-----------------------------------------------------------------------
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* CATCH CX_ADDRESS_BCS.
* Catch exception here
ENDTRY.
*-----------------------------------------------------------------------
* Set recipient *
*-----------------------------------------------------------------------
lo_recipient = cl_cam_address_bcs=>create_internet_address( p_email ). "Here Recipient is email input p_email
TRY.
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**Catch exception here
ENDTRY.
*-----------------------------------------------------------------------
* Send email
*-----------------------------------------------------------------------
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X' ).
COMMIT WORK.
ENDMETHOD.