Code: Alles auswählen.
<?xml version="1.0" encoding="utf-16"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"><asx:values><DATA_NODE><T000><MANDT>000</MANDT><MTEXT>SAP AG</MTEXT><ORT01>Walldorf</ORT01><MWAER>EUR</MWAER><ADRNR/><CCCATEGORY>S</CCCATEGORY><CCCORACTIV>2</CCCORACTIV><CCNOCLIIND/><CCCOPYLOCK>X</CCCOPYLOCK><CCNOCASCAD/><CCSOFTLOCK/><CCORIGCONT/><CCIMAILDIS/><CCTEMPLOCK/><CHANGEUSER>OCA</CHANGEUSER><CHANGEDATE>2007-10-06</CHANGEDATE><LOGSYS>CS2CLNT000</LOGSYS></T000><T000><MANDT>001</MANDT><MTEXT>Auslieferungsmandant R11</MTEXT><ORT01>Kundstadt</ORT01><MWAER>USD</MWAER><ADRNR/><CCCATEGORY>C</CCCAT
Code: Alles auswählen.
REPORT z_test7.
*Prepare Mail Object
DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
CLASS cl_bcs DEFINITION LOAD.
DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL. "document object
DATA : i_text TYPE bcsy_text. "Table for body
DATA : w_text LIKE LINE OF i_text. "work area for message body
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL. "sender
DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL. "recipient
DATA: lx_document_bcs TYPE REF TO cx_document_bcs.
**Selection screen
PARAMETERS : p_email TYPE adr6-smtp_addr. "Email input
***Attachment data
DATA : lt_tadir TYPE TABLE OF tadir,
wa_tadir TYPE tadir.
DATA : lv_string TYPE string,
lv_data_string TYPE string,
lv_xstring TYPE xstring.
DATA: lit_binary_content TYPE solix_tab,
lv_attsubject TYPE sood-objdes.
DATA: lt_t000 TYPE STANDARD TABLE OF t000.
DATA: lv_xml TYPE string.
DATA: lo_xml_doc TYPE REF TO cl_xml_document.
DATA: lt_attach TYPE soli_tab.
START-OF-SELECTION.
lo_send_request = cl_bcs=>create_persistent( ).
CONCATENATE 'Testnachricht' sy-datum ' ' sy-timlo INTO lv_attsubject RESPECTING BLANKS.
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 = lv_attsubject ). "email subject here p_sub input parameter
lo_send_request->set_document( lo_document ).
SELECT * FROM t000 INTO TABLE lt_t000.
CALL TRANSFORMATION id SOURCE data_node = lt_t000 RESULT XML lv_xml.
CREATE OBJECT lo_xml_doc.
lo_xml_doc->parse_string( lv_xml ).
CALL FUNCTION 'SO_STRING_TO_TAB'
EXPORTING
content_str = lv_xml
TABLES
content_tab = lt_attach.
* Create Attachment
TRY.
lo_document->add_attachment(
i_attachment_type = 'XLS'
i_attachment_subject = lv_attsubject
i_att_content_text = lt_attach
).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
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.
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.
ENDTRY.
TRY.
CALL METHOD lo_send_request->set_send_immediately
EXPORTING
i_send_immediately = 'X'. "here selection screen input p_send
CATCH cx_send_req_bcs.
ENDTRY.
TRY.
** Send email
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X' ).
COMMIT WORK.
IF sy-subrc = 0. "mail sent successfully
WRITE :/ 'Mail sent successfully'.
ENDIF.
CATCH cx_send_req_bcs.
*catch exception here
ENDTRY.
Vielleicht liegt es an der Dateiendung?debianfan hat geschrieben: * Create Attachment
TRY.
lo_document->add_attachment(
i_attachment_type = 'XLS'
i_attachment_subject = lv_attsubject
i_att_content_text = lt_attach
).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report YTEST_ABAP_FORUM *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT YTEST_ABAP_FORUM .
*Prepare Mail Object
DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
CLASS cl_bcs DEFINITION LOAD.
DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL. "document object
DATA : i_text TYPE bcsy_text. "Table for body
DATA : w_text LIKE LINE OF i_text. "work area for message body
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL. "sender
DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL. "recipient
DATA: lx_document_bcs TYPE REF TO cx_document_bcs.
**Selection screen
PARAMETERS : p_email TYPE adr6-smtp_addr default 'sapuser@localhost'. "Email input
***Attachment data
DATA : lt_tadir TYPE TABLE OF tadir,
wa_tadir TYPE tadir.
DATA : lv_string TYPE string,
lv_data_string TYPE string,
lv_xstring TYPE xstring.
DATA: lit_binary_content TYPE solix_tab,
lv_attsubject TYPE sood-objdes.
DATA: lt_t000 TYPE STANDARD TABLE OF t000.
DATA: lx_xml TYPE xstring.
DATA: lo_xml_doc TYPE REF TO cl_xml_document.
*DATA: lt_attach TYPE solix_tab.
data lt_attach TYPE table of SOLIX.
DATA: l_xlen TYPE i.
START-OF-SELECTION.
lo_send_request = cl_bcs=>create_persistent( ).
CONCATENATE 'Testnachricht' sy-datum ' ' sy-timlo INTO lv_attsubject.
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 = lv_attsubject ). "email subject here p_sub input parameter
lo_send_request->set_document( lo_document ).
SELECT * FROM t000 INTO TABLE lt_t000.
CALL TRANSFORMATION id SOURCE data_node = lt_t000 RESULT XML lx_xml.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lx_xml
APPEND_TO_TABLE = ' '
IMPORTING
OUTPUT_LENGTH = l_xlen
tables
binary_tab = lt_attach.
* CREATE OBJECT lo_xml_doc.
* lo_xml_doc->parse_string( lv_xml ).
* CALL FUNCTION 'SO_STRING_TO_TAB'
* EXPORTING
* content_str = lv_xml
* TABLES
* content_tab = lt_attach.
* Create Attachment
*ALI X X ABAPList-Dokument
*ARC X Archivobjekt (Image)
*BCS X Externe Dokumentablage
*BIN X Binäres Dokument
*DLI X Verteilerliste
*EXT X X PC-Dokument
*FAX X X Telefax
*FOL X Mappe
*GRA X X SAP-Graphik
*OBJ X Business Objekt
*OFO X Object folder
*OTF X OTF-Dokument
*R3I X IDoc
*RAW X X SAP-Editor-Dokument
*SCR X SAPscript-Dokument
*URL Link ins Inter-/Intranet
*WIM X Workitem
*XXL X X Dokument für Listviewer
data l_attsize TYPE SOOD-OBJLEN.
l_attsize = l_xlen.
TRY.
lo_document->add_attachment(
i_attachment_type = 'XML'
I_ATTACHMENT_SIZE = l_attsize
i_attachment_subject = lv_attsubject
I_ATT_CONTENT_HEX = lt_attach
).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
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.
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.
ENDTRY.
TRY.
CALL METHOD lo_send_request->set_send_immediately
EXPORTING
i_send_immediately = 'X'. "here selection screen input p_send
CATCH cx_send_req_bcs.
ENDTRY.
TRY.
** Send email
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X' ).
COMMIT WORK.
IF sy-subrc = 0. "mail sent successfully
WRITE :/ 'Mail sent successfully'.
ENDIF.
CATCH cx_send_req_bcs.
*catch exception here
ENDTRY.
Gar nicht. Leider.debianfan hat geschrieben:Aber wie gebe ich ihm beim CALL Transformation mit, dass er UTF8 anstatt UTF16 verwenden soll?
Code: Alles auswählen.
DATA conv_out TYPE REF TO cl_abap_conv_out_ce.
DATA conv_in TYPE REF TO cl_abap_conv_in_ce.
DATA outx TYPE xstring.
DATA len TYPE i.
"Damit aus "führen" führen wird...
conv_out = cl_abap_conv_out_ce=>create( encoding = '1160' ). "1160 = windows-1252
conv_out->convert( EXPORTING data = in IMPORTING buffer = outx len = len ).
conv_in = cl_abap_conv_in_ce=>create( input = outx encoding = '4110' ). "4110 = UTF-8
conv_in->read( EXPORTING n = len IMPORTING data = out ).