Code: Alles auswählen.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = gt_ausgabe
CHANGING
i_tab_converted_data = i_tab_converted_data
EXCEPTIONS
conversion_failed = 1.
Code: Alles auswählen.
DATA: lv_recipient TYPE adr6-smtp_addr.
DATA: lv_subject TYPE string.
lv_recipient = 'email@email.com'.
lv_subject = 'Testemail'.
DATA(lv_html_text) = VALUE string( ).
lv_html_text = |<BODY> | &&
|<P><B>Test</B></BR>| &&
|</BODY>|.
DATA(it_body_txt) = cl_document_bcs=>string_to_soli( ip_string = lv_html_text ).
TRY.
* it_body_txt beinhaltet die Zeilen des Body-Textes
* die Zeilen sind jeweils char255 Zeichen lang
* eine Zeile (line) ist vom Typ SOLI
* Document (Mail) erzeugen
* Email-Subject (i_subject) darf hier max. 50 Zeichen lang sein (Subject-Darstellung in der SOST)
* die "richtige" Übergabe des Email-Subjects erfolgt weiter unten in der Funktion set_message_subject( )
DATA(o_document) = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = it_body_txt
i_subject = CONV so_obj_des( lv_subject ) ).
* Sendrequest erzeugen
DATA(o_send_request) = cl_bcs=>create_persistent( ).
* Email-Subject festlegen, ip_subject ist vom Typ String
o_send_request->set_message_subject( ip_subject = lv_subject ).
* Die Mail an den Sendrequest hängen
o_send_request->set_document( o_document ).
* SAP-User als Sender
DATA(o_sender) = cl_sapuser_bcs=>create( sy-uname ).
* Email-Adresse als Sender
* DATA(o_sender) = cl_cam_address_bcs=>create_internet_address( i_address_string = 'email@email.com' ).
o_send_request->set_sender( o_sender ).
* Empfänger -> beachte: u.U. sind Email-Adressen mit Umlauten nicht zulässig -> Exception
DATA(o_recipient) = cl_cam_address_bcs=>create_internet_address( lv_recipient ).
o_send_request->add_recipient( i_recipient = o_recipient
i_express = abap_true
" i_copy = abap_true " CC
" i_blind_copy = abap_true " BCC
).
* Sofort senden
o_send_request->set_send_immediately( abap_true ).
* Dokument senden
IF o_send_request->send( i_with_error_screen = abap_true ) = abap_true.
WRITE: / 'Email gesendet.'.
ELSE.
WRITE: / 'Fehler beim Email-Versand.'.
ENDIF.
* Persistenzdienste des Objektes starten, sonst wird ggf. die Mail nicht gesendet
COMMIT WORK.
CATCH cx_root INTO DATA(e_text).
WRITE: / e_text->get_text( ).
ENDTRY.
Code: Alles auswählen.
DATA: lv_recipient TYPE adr6-smtp_addr.
DATA: lv_subject TYPE string.
lv_recipient = 'email@email.com'.
lv_subject = 'Testemail'.
DATA(lv_html_text) = VALUE string( ).
lv_html_text = |<BODY> | &&
|<P><B>Test</B></BR>| &&
|</BODY>|.
DATA(it_body_txt) = cl_document_bcs=>string_to_soli( ip_string = lv_html_text ).
TRY.
* it_body_txt beinhaltet die Zeilen des Body-Textes
* die Zeilen sind jeweils char255 Zeichen lang
* eine Zeile (line) ist vom Typ SOLI
* Document (Mail) erzeugen
* Email-Subject (i_subject) darf hier max. 50 Zeichen lang sein (Subject-Darstellung in der SOST)
* die "richtige" Übergabe des Email-Subjects erfolgt weiter unten in der Funktion set_message_subject( )
DATA(o_document) = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = it_body_txt
i_subject = CONV so_obj_des( lv_subject ) ).
* Sendrequest erzeugen
DATA(o_send_request) = cl_bcs=>create_persistent( ).
* Email-Subject festlegen, ip_subject ist vom Typ String
o_send_request->set_message_subject( ip_subject = lv_subject ).
* Die Mail an den Sendrequest hängen
o_send_request->set_document( o_document ).
* SAP-User als Sender
DATA(o_sender) = cl_sapuser_bcs=>create( sy-uname ).
* Email-Adresse als Sender
* DATA(o_sender) = cl_cam_address_bcs=>create_internet_address( i_address_string = 'email@email.com' ).
o_send_request->set_sender( o_sender ).
* Empfänger -> beachte: u.U. sind Email-Adressen mit Umlauten nicht zulässig -> Exception
DATA(o_recipient) = cl_cam_address_bcs=>create_internet_address( lv_recipient ).
o_send_request->add_recipient( i_recipient = o_recipient
i_express = abap_true
" i_copy = abap_true " CC
" i_blind_copy = abap_true " BCC
).
* Sofort senden
o_send_request->set_send_immediately( abap_true ).
* Dokument senden
IF o_send_request->send( i_with_error_screen = abap_true ) = abap_true.
WRITE: / 'Email gesendet.'.
ELSE.
WRITE: / 'Fehler beim Email-Versand.'.
ENDIF.
* Persistenzdienste des Objektes starten, sonst wird ggf. die Mail nicht gesendet
COMMIT WORK.
CATCH cx_root INTO DATA(e_text).
WRITE: / e_text->get_text( ).
ENDTRY.
Code: Alles auswählen.
DATA(lv_html_text) = VALUE string( ).
*lv_html_text = |<BODY> | &&
* |<P><B>Test</B></BR>| &&
* |</BODY>|.
*
DATA(it_body_txt) = cl_document_bcs=>string_to_soli( ip_string = string ).
Vielleicht ist es ja gar nicht so schlimm wie es aussieht. Auf diversen Kundensystemen die ich kenne, wurde in der SCOT der SMTP-Knoten so eingestellt, dass in nicht-Produktivsystemen Emails nur an firmeninterne Emailadressen und explizit gelistete Einzeladressen ( z.B. meine )geschickt werden können und der Rest auf Fehler läuft. ( Und wenn man gewisse eigengestrickte Bausteine verwendet wird auf nichtproduktiven Systemem noch ein Extratext eingefügt in Betreff und Mailtext, der darauf hinweist, dass es ein Test ist )DeathAndPain hat geschrieben:Das wäre aber schlimm, denn das würde bedeuten, dass bei Testen von Code irgendwelche Emails in der Gegend rumfliegen und die Empfänger verunsichern können.
Code: Alles auswählen.
report bcs_example_7.
* This report provides an example for sending an Excel
* attachment in Unicode Systems
constants:
gc_tab type c value cl_bcs_convert=>gc_tab,
gc_crlf type c value cl_bcs_convert=>gc_crlf.
parameters:
mailto type ad_smtpadr
default 'john.doe@crazy-company.com'. "#EC *
data send_request type ref to cl_bcs.
data document type ref to cl_document_bcs.
data recipient type ref to if_recipient_bcs.
data bcs_exception type ref to cx_bcs.
data main_text type bcsy_text.
data binary_content type solix_tab.
data size type so_obj_len.
data sent_to_all type os_boolean.
start-of-selection.
perform create_content.
perform send.
*&---------------------------------------------------------------------*
*& Form send
*&---------------------------------------------------------------------*
form send.
try.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document object from internal table with text
append 'Hello world!' to main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Test Created By BCS_EXAMPLE_7' ). "#EC NOTEXT
* add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = 'ExampleSpreadSheet' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
* add document object to send request
send_request->set_document( document ).
* --------- add recipient (e-mail address) -----------------------
* create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
* add recipient object to send request
send_request->add_recipient( recipient ).
* ---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
if sent_to_all is initial.
message i500(sbcoms) with mailto.
else.
message s022(so).
endif.
* ------------ exception handling ----------------------------------
* replace this rudimentary exception handling with your own one !!!
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
endform. "send
*&---------------------------------------------------------------------*
*& Form create_content
*&---------------------------------------------------------------------*
* Create Example Content
* 1) Write example text into a string
* 2) convert this string to solix_tab
*----------------------------------------------------------------------*
form create_content.
data lv_string type string.
data ls_t100 type t100.
* --------------------------------------------------------------
* as example content we use some system messages out of t100
* get them for all installed languages from db
* and write one line for each language into the spread sheet
* columns are separated by TAB and each line ends with CRLF
concatenate 'This Is Just Example Text!' "#EC NOTEXT
gc_crlf gc_crlf
into lv_string.
* header line
concatenate lv_string
'MSGID' gc_tab
'MSGNO' gc_tab
'Language' gc_tab "#EC NOTEXT
'Text' gc_crlf "#EC NOTEXT
into lv_string.
* data lines
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '182'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '316'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
* --------------------------------------------------------------
* convert the text string into UTF-16LE binary data including
* byte-order-mark. Mircosoft Excel prefers these settings
* all this is done by new class cl_bcs_convert (see note 1151257)
try.
cl_bcs_convert=>string_to_solix(
exporting
iv_string = lv_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
importing
et_solix = binary_content
ev_size = size ).
catch cx_bcs.
message e445(so).
endtry.
endform. "create_content
*---------------------------------------------------------------
* NOTES:
*---------------------------------------------------------------
* UTF-16LE including the BOM (Byte order mark)
* is preferred by Microsoft Excel. If you want to create
* other binary content you may choose another codepage (e.g.
* '4110' (UTF-8) which is standard for e-mails).
* Find SAP codepage names in the drop down list
* for the codepage setting of node SMTP in transaction SCOT.
* Or: leave iv_codepage and iv_add_bom empty. Then the target
* codepage is set according to SAPconnect settings
*
* Important:
* SAP neither guarantees that the attachment created
* by this report can be opened by all Excel Versions nor
* that it can be opened by any 3rd party software at all
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174