Code: Alles auswählen.
DATA: LV_FILE TYPE STRING,
LT_CONVERTED_DATA TYPE TRUXS_T_TEXT_DATA.
* Daten konvertieren
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
I_LINE_HEADER = 'X'
I_FILENAME = IV_FILE
TABLES
I_TAB_SAP_DATA = AUSZUGEBENDE_TABELLE
CHANGING
I_TAB_CONVERTED_DATA = LT_CONVERTED_DATA
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
IF SY-BATCH IS INITIAL.
MESSAGE E004(Z01) WITH IV_FILE.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'Fehler beim Konvertieren der Daten für Datei', IV_FILE.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
ENDIF.
ENDIF.
LV_FILE = 'Dateiname.csv'.
CHECK SY-BATCH IS INITIAL. " keine Frontend-Ausgabe bei Hintergrundbetrieb des Jobs
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
FILENAME = LV_FILE
CHANGING
DATA_TAB = LT_CONVERTED_DATA
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
NOT_SUPPORTED_BY_GUI = 22
ERROR_NO_GUI = 23
OTHERS = 24.
IF SY-SUBRC <> 0.
IF SY-BATCH IS INITIAL.
MESSAGE I003(Z01) WITH LV_FILE SY-SUBRC.
ELSE.
WRITE: / 'Fehler beim Schreiben der Datei', LV_FILE NO-GAP,':', SY-SUBRC.
ENDIF.
ENDIF.
Code: Alles auswählen.
* so
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = 'c:\temp\test.csv'
filetype = 'ASC'
trunc_trailing_blanks_eol = 'X'
CHANGING
data_tab = data_table
EXCEPTIONS
file_write_error = 1
no_batch = 2
...
*oder auch so
data ooutfile type string.
outfile = 'c:\temp\test.csv'.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = outfile
filetype = 'ASC'
trunc_trailing_blanks_eol = 'X'
CHANGING
data_tab = data_table
EXCEPTIONS
file_write_error = 1
no_batch = 2
Code: Alles auswählen.
DATA data_table TYPE TABLE OF t100.
DATA i_tab_converted_data TYPE truxs_t_text_data.
DATA outfile TYPE string.
SELECT * FROM t100 UP TO 100 ROWS
INTO CORRESPONDING FIELDS OF TABLE @data_table.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = data_table
CHANGING
i_tab_converted_data = i_tab_converted_data
EXCEPTIONS
conversion_failed = 1.
outfile = 'c:\temp\test.csv'.
cl_gui_frontend_services=>gui_download(
EXPORTING
filename = outfile
CHANGING
data_tab = i_tab_converted_data
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24 ).
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Code: Alles auswählen.
DATA: gc_subject TYPE so_obj_des VALUE 'E-Mail Versand mit der Klasse CL_BCS',
gc_raw TYPE char03 VALUE 'RAW',
gv_sent_to_all TYPE os_boolean,
gv_email TYPE adr6-smtp_addr,
gv_text TYPE bcsy_text,
binary_content TYPE solix_tab,
size TYPE so_obj_len,
gr_send_request TYPE REF TO cl_bcs,
gr_bcs_exception TYPE REF TO cx_bcs,
gr_recipient TYPE REF TO if_recipient_bcs,
gr_sender TYPE REF TO cl_sapuser_bcs,
gr_document TYPE REF TO cl_document_bcs.
DATA: i_tab_converted_data TYPE c length 255,
gv_string TYPE string.
* CSV in String umformen
i_tab_converted_data = 'Irgendein;Text;steht;hier;in;CSV'.
gv_string = i_tab_converted_data.
TRY.
* Send Request erstellen
gr_send_request = cl_bcs=>create_persistent( ).
* Sender:
gr_sender = cl_sapuser_bcs=>create( sy-uname ).
* Sender zum Request hinzufügen
CALL METHOD gr_send_request->set_sender
EXPORTING
i_sender = gr_sender.
* Empfänger
gv_email = 'test@test.de'.
gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
* Empfänger zum Request hinzufügen
CALL METHOD gr_send_request->add_recipient
EXPORTING
i_recipient = gr_recipient
i_express = 'X'.
* E-Mail Body
APPEND 'Mailversand-Beispiel' TO gv_text.
gr_document = cl_document_bcs=>create_document(
i_type = gc_raw
i_text = gv_text
i_length = '12'
i_subject = gc_subject ).
* Body anhängen
CALL METHOD gr_send_request->set_document( gr_document ).
* String (CSV Inhalt) umformen, um es als Anhang zu versenden
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = gv_string
iv_codepage = '4103'
iv_add_bom = 'X'
IMPORTING
et_solix = binary_content
ev_size = size ).
* E-Mail Anhang
CALL METHOD gr_document->add_attachment
EXPORTING
i_attachment_type = 'CSV'
i_attachment_subject = 'TEST.CSV'
i_attachment_size = size
i_att_content_hex = binary_content.
* E-Mail senden
CALL METHOD gr_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = gv_sent_to_all ).
IF gv_sent_to_all = 'X'.
WRITE 'E-Mail erfolgreich versendet!'.
ENDIF.
* wird benötigt, um Mail zu versenden
COMMIT WORK.
* Ausnahmebehandlung
CATCH cx_bcs INTO gr_bcs_exception.
WRITE:
'Error vom Typ: ',
gr_bcs_exception->error_type.
ENDTRY.