Code: Alles auswählen.
form download.
open dataset filename for output in text mode encoding default.
if sy-subrc ne 0.
write: 'File cannot be opened'.
exit.
endif.
loop at itab3.
concatenate
itab3-vkorg
itab3-vbeln
itab3-kunnr
itab3-name1
itab3-text1
itab3-matnr
itab3-maktx
itab3-prctr
itab3-text2
itab3-c_wadat
itab3-c_olfmng
itab3-c_preis
itab3-waerk
itab3-c_netwr
itab3-c_hzdat
into v_transfer separated by ';'.
transfer v_transfer to filename.
endloop.
write: /001 'download Completed'.
close dataset filename.
endform.
Code: Alles auswählen.
DATA: t_lines TYPE ty_tline,
v_html_txt TYPE string.
* Aufbau csv-Anhang
* Kopf
DATA(v_string) = 'Mat.nr.' && cl_bcs_convert=>gc_tab &&
'Kurztext' && cl_bcs_convert=>gc_tab &&
'ST' && cl_bcs_convert=>gc_tab &&
'MArt' && cl_bcs_convert=>gc_tab &&
'PH1 Text' && cl_bcs_convert=>gc_tab &&
'PH2 Text' && cl_bcs_convert=>gc_tab &&
'PH3 Text' && cl_bcs_convert=>gc_tab &&
'Menge' && cl_bcs_convert=>gc_tab &&
'ME' && cl_bcs_convert=>gc_tab &&
'Datum' && cl_bcs_convert=>gc_crlf.
* Daten
LOOP AT itab ASSIGNING FIELD-SYMBOL(<s_itab>).
v_string = v_string &&
<s_itab>-matnr && cl_bcs_convert=>gc_tab &&
<s_itab>-maktx && cl_bcs_convert=>gc_tab &&
<s_itab>-mstav && cl_bcs_convert=>gc_tab &&
<s_itab>-mtart && cl_bcs_convert=>gc_tab &&
<s_itab>-prodh1t && cl_bcs_convert=>gc_tab &&
<s_itab>-prodh2t && cl_bcs_convert=>gc_tab &&
<s_itab>-prodh3t && cl_bcs_convert=>gc_tab &&
|{ <s_itab>-menge DECIMALS = 0 NUMBER = ENVIRONMENT }| && cl_bcs_convert=>gc_tab &&
<s_itab>-meins && cl_bcs_convert=>gc_tab &&
|{ <s_itab>-datum DATE = USER }| && cl_bcs_convert=>gc_crlf.
ENDLOOP. "itab
* Konvertieren nach binär
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = v_string
iv_codepage = '4103'
iv_add_bom = abap_true
IMPORTING
et_solix = DATA(t_binary_content)
ev_size = DATA(v_size) ).
CATCH cx_bcs.
MESSAGE e445(so).
RETURN.
ENDTRY.
* Inhalt Email-Body aus SO10-Text
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'ST'
language = sy-langu
name = 'Z_EMAIL_BODY'
object = 'TEXT'
TABLES
lines = t_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc NE 0.
v_html_txt = space.
ELSE.
LOOP AT t_lines ASSIGNING FIELD-SYMBOL(<s_lines>) WHERE tdformat NE '/*'.
v_html_txt = v_html_txt && <s_lines>-tdline.
ENDLOOP.
ENDIF.
* Email-Versand
TRY.
* Sende-Request anlegen
DATA(o_send_request) = cl_bcs=>create_persistent( ).
* Empfänger-Email-Adressen aus Selektionsmaske dem Sende-Request hinzufügen
LOOP AT so_rec.
DATA(o_recipient) = cl_cam_address_bcs=>create_internet_address( receiver ). "Email-Adresse des Empfängers
o_send_request->add_recipient( i_recipient = o_recipient
i_express = abap_true ).
ENDLOOP.
* Body erzeugen
DATA(t_body_txt) = cl_document_bcs=>string_to_soli( ip_string = v_html_txt ).
DATA(o_document) = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = t_body_txt
i_subject = 'Verfügbarer Bestand' ). "Betreff
* csv-Datei anhängen
o_document->add_attachment( i_attachment_type = 'csv' "Datei-Endung
i_attachment_subject = 'Bestand' "Dateiname
i_attachment_size = v_size
i_att_content_hex = t_binary_content ).
* Dokument (Body und Anhang) an Sende-Request hängen
o_send_request->set_document( o_document ).
* senden und Status abfragen
IF o_send_request->send( i_with_error_screen = abap_true ) = abap_true.
WRITE: / 'Email gesendet.'.
ELSE.
MESSAGE 'Fehler beim Email-Versand' TYPE 'E'.
ENDIF.
COMMIT WORK.
CATCH: cx_send_req_bcs, cx_document_bcs, cx_address_bcs.
MESSAGE 'Fehler beim Email-Versand' TYPE 'E'.
ENDTRY.
Code: Alles auswählen.
* Sende-Request anlegen
DATA(o_send_request) = cl_bcs=>create_persistent( ).
* Empfänger-Email-Adresse hinzufügen
DATA(o_recipient) = cl_cam_address_bcs=>create_internet_address( receiver ). "Email-Adresse des Empfängers
o_send_request->add_recipient( i_recipient = o_recipient
i_express = abap_true ).
* Datei anhängen
o_document->add_attachment( i_attachment_type = 'csv' "Datei-Endung
i_attachment_subject = 'Bestand' "Dateiname
i_attachment_size = v_size
i_att_content_hex = t_binary_content ).
* Dokument (Body und Anhang) an Sende-Request hängen
o_send_request->set_document( o_document ).
* senden und Status abfragen
IF o_send_request->send( i_with_error_screen = abap_true ) = abap_true.
Sorry, aber das kann ich nicht nachvollziehen. Die Verwendung der cl_bcs* ist doch viel einfacher, als der Aufbau der Parameter der "alten" Funktionsbausteine.jocoder hat geschrieben: ↑06.12.2019 08:41@Armin93:
Standardmäßig sind die Mailfunktionen auch in den Funktionsbausteinen SO_NEW_DOCUMENT_ATT_SEND_API1, SO_NEW_DOCUMENT_SEND_API1 und in den Klassen CL_SWF_MAIL_SAPOFFICE_OBJ, CL_UWS_PUBLISHING vorhanden.
Dadurch brauchst du nicht so viel Boilerplate-Code und das ganze Programm wird gleich viel übersichtlicher.
Code: Alles auswählen.
form send_mail.
loop at itab2.
concatenate
itab2-bukrs
itab2-rbeln
itab2-kndnr
itab2-name1
itab2-text1
itab2-matnr
itab2-maktx
itab2-prctr
itab2-text2
itab2-c_budat
itab2-c_absmg
itab2-c_preis
itab2-frwae
itab2-c_summe1
itab2-c_hzdat
into itab10-v_transfer separated by ';'.
append itab10.
endloop.
* Daten
LOOP AT itab10 ASSIGNING FIELD-SYMBOL(<s_itab>).
v_string = v_string &&
<s_itab>-v_transfer && cl_bcs_convert=>gc_crlf.
ENDLOOP. "itab
* Konvertieren nach binär
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = v_string
iv_codepage = '4103'
iv_add_bom = abap_true
IMPORTING
et_solix = DATA(t_binary_content)
ev_size = DATA(v_size) ).
CATCH cx_bcs.
MESSAGE e445(so).
RETURN.
ENDTRY.
* Inhalt Email-Body aus SO10-Text
call function 'READ_TEXT'
exporting
id = 'ST'
language = sy-langu
name = 'Z_EMAIL_BODY'
object = 'TEXT'
tables
lines = t_lines
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
others = 8.
if sy-subrc ne 0.
v_html_txt = space.
else.
loop at t_lines assigning field-symbol(<s_lines>) where tdformat ne '/*'.
v_html_txt = v_html_txt && <s_lines>-tdline.
endloop.
endif.
* Email-Versand
try.
* Sende-Request anlegen
data(o_send_request) = cl_bcs=>create_persistent( ).
* Empfänger-Email-Adressen aus Selektionsmaske dem Sende-Request hinzufügen
loop at itab10.
data(o_recipient) = cl_cam_address_bcs=>create_internet_address( 'armin.sediqi@sag.at' ). "Email-Adresse des Empfängers
o_send_request->add_recipient( i_recipient = o_recipient
i_express = abap_true ).
endloop.
* Body erzeugen
data(t_body_txt) = cl_document_bcs=>string_to_soli( ip_string = v_html_txt ).
data(o_document) = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = t_body_txt
i_subject = 'Tägliche Umsatzabfrage' ). "Betreff
* txt-Datei anhängen
o_document->add_attachment( i_attachment_type = 'txt' "Datei-Endung
i_attachment_subject = 'SAP_SALES'
i_attachment_size = v_size
i_att_content_hex = t_binary_content ).
* Dokument (Body und Anhang) an Sende-Request hängen
o_send_request->set_document( o_document ).
* senden und Status abfragen
if o_send_request->send( i_with_error_screen = abap_true ) = abap_true.
write: / 'Email gesendet.'.
else.
message 'Fehler beim Email-Versand' type 'E'.
endif.
commit work.
catch: cx_send_req_bcs, cx_document_bcs, cx_address_bcs.
message 'Fehler beim Email-Versand' type 'E'.
endtry.
endform.
Code: Alles auswählen.
form send_mail.
loop at itab2.
concatenate
itab2-bukrs
itab2-rbeln
itab2-kndnr
itab2-name1
itab2-text1
itab2-matnr
itab2-maktx
itab2-prctr
itab2-text2
itab2-c_budat
itab2-c_absmg
itab2-c_preis
itab2-frwae
itab2-c_summe1
itab2-c_hzdat
into itab10-v_transfer separated by ';'.
append itab10.
endloop.
* Daten
LOOP AT itab10 ASSIGNING FIELD-SYMBOL(<s_itab>).
v_string = v_string &&
<s_itab>-v_transfer && cl_bcs_convert=>gc_crlf.
ENDLOOP. "itab
* Konvertieren nach binär
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = v_string
iv_codepage = '4103'
iv_add_bom = abap_true
IMPORTING
et_solix = DATA(t_binary_content)
ev_size = DATA(v_size) ).
CATCH cx_bcs.
MESSAGE e445(so).
RETURN.
ENDTRY.
* Inhalt Email-Body aus SO10-Text
call function 'READ_TEXT'
exporting
id = 'ST'
language = sy-langu
name = 'Z_EMAIL_BODY'
object = 'TEXT'
tables
lines = t_lines
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
others = 8.
if sy-subrc ne 0.
v_html_txt = space.
else.
loop at t_lines assigning field-symbol(<s_lines>) where tdformat ne '/*'.
v_html_txt = v_html_txt && <s_lines>-tdline.
endloop.
endif.
* Email-Versand
try.
* Sende-Request anlegen
data(o_send_request) = cl_bcs=>create_persistent( ).
* Empfänger-Email-Adressen aus Selektionsmaske dem Sende-Request hinzufügen
loop at itab10.
data(o_recipient) = cl_cam_address_bcs=>create_internet_address( 'armin.sediqi@sag.at' ). "Email-Adresse des Empfängers
o_send_request->add_recipient( i_recipient = o_recipient
i_express = abap_true ).
endloop.
* Body erzeugen
data(t_body_txt) = cl_document_bcs=>string_to_soli( ip_string = v_html_txt ).
data(o_document) = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = t_body_txt
i_subject = 'Tägliche Umsatzabfrage' ). "Betreff
* txt-Datei anhängen
o_document->add_attachment( i_attachment_type = 'txt' "Datei-Endung
i_attachment_subject = 'SAP_SALES'
i_attachment_size = v_size
i_att_content_hex = t_binary_content ).
* Dokument (Body und Anhang) an Sende-Request hängen
o_send_request->set_document( o_document ).
* senden und Status abfragen
if o_send_request->send( i_with_error_screen = abap_true ) = abap_true.
write: / 'Email gesendet.'.
else.
message 'Fehler beim Email-Versand' type 'E'.
endif.
commit work.
catch: cx_send_req_bcs, cx_document_bcs, cx_address_bcs.
message 'Fehler beim Email-Versand' type 'E'.
endtry.
endform.