Code: Alles auswählen.
DATA: h_binary_content TYPE solix_tab.
DATA: h_size TYPE so_obj_len.
DATA: h_sent_to_all TYPE os_boolean.
DATA: h_main_text TYPE bcsy_text.
DATA: h_send_request TYPE REF TO cl_bcs.
DATA: h_document TYPE REF TO cl_document_bcs.
DATA: h_recipient TYPE REF TO if_recipient_bcs.
DATA: h_bcs_exception TYPE REF TO cx_bcs.
DATA: h_subject(50) TYPE c.
DATA: h_string TYPE string,
l_string TYPE string,
wa_string TYPE string,
it_string TYPE STANDARD TABLE OF string,
l_atttyp TYPE soodk-objtp VALUE 'CSV'. "'XLSX'.
*$*$-------------------------------------------------GLOBAL VARIABLES---
*$*$---CONSTANTS--------------------------------------------------------
CONSTANTS: c_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
c_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
* CONCATENATE text-t0p c_tab sy-cprog c_crlf
* text-t0v c_tab sy-slset c_crlf
* text-t0u c_tab c_tab sy-uname c_crlf
* text-t0s c_tab sy-sysid c_crlf
* text-t0d c_tab c_tab sy-datum c_tab sy-uzeit c_crlf
* INTO h_string.
APPEND h_string TO h_main_text.
* => Prepare data
LOOP AT lt_iout INTO wa_string.
IF l_string IS INITIAL.
CONCATENATE wa_string c_crlf INTO l_string.
ELSE.
CONCATENATE l_string wa_string c_crlf INTO l_string.
ENDIF.
ENDLOOP.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = l_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = h_binary_content
ev_size = h_size ).
CATCH cx_bcs.
" MESSAGE e445(so).
ENDTRY.
* h_subject = sy-repid.
CONCATENATE ' Provision ' lv_date_from(6) into h_subject.
* Email send
TRY.
* -------- create persistent send request ------------------------
h_send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document object from internal table with text
h_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = h_main_text
i_subject = h_subject ).
* add the spread sheet as attachment to document object
h_document->add_attachment(
i_attachment_type = l_atttyp
i_attachment_subject = h_subject
i_attachment_size = h_size
i_att_content_hex = h_binary_content ).
* add document object to send request
h_send_request->set_document( h_document ).
* LOOP AT it_user.
* --------- add recipient (e-mail address) -----------------------
* create recipient object
h_recipient = cl_cam_address_bcs=>create_internet_address( 'email@mail.de' ).
* add recipient object to send request
h_send_request->add_recipient( h_recipient ).
* ENDLOOP.
* ---------- send document ---------------------------------------
h_sent_to_all = h_send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
Code: Alles auswählen.
CALL FUNCTION 'Z_CREATE_XLSX_MAIL'
EXPORTING
i_excel_len = lv_len
* I_SENDER =
* TT_TEXT =
i_subject = l_subject
i_filename = lv_file
* I_USE_NOREPLY =
TABLES
i_excelx = exclbin
i_user = t_email_receivers
EXCEPTIONS
assigment_error = 1
OTHERS = 2.
COMMIT WORK AND WAIT.
* ODER
CALL FUNCTION 'Z_CREATE_XLSX_MAIL' in update task
EXPORTING
i_excel_len = lv_len
* I_SENDER =
* TT_TEXT =
i_subject = l_subject
i_filename = lv_file
* I_USE_NOREPLY =
TABLES
i_excelx = exclbin
i_user = t_email_receivers
EXCEPTIONS
assigment_error = 1
OTHERS = 2.
* dann kein COMMIT !
Code: Alles auswählen.
FUNCTION Z_CREATE_XLSX_MAIL .
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_EXCEL_LEN) TYPE I
*" VALUE(I_SENDER) TYPE AD_SMTPADR OPTIONAL
*" VALUE(TT_TEXT) TYPE BCSY_TEXT OPTIONAL
*" VALUE(I_SUBJECT) TYPE SO_OBJ_DES
*" VALUE(I_FILENAME) TYPE SO_OBJ_DES OPTIONAL
*" VALUE(I_USE_NOREPLY) TYPE XFELD OPTIONAL
*" TABLES
*" I_EXCELX STRUCTURE SOLIX
*" I_USER STRUCTURE USREFUS
*" EXCEPTIONS
*" ASSIGMENT_ERROR
*"----------------------------------------------------------------------
DATA lv_len TYPE i.
* -------- convert document -------------------------------
* for email contents
DATA lv_internetadr TYPE adr6-smtp_addr.
DATA lv_attname TYPE sood-objdes.
DATA send_request TYPE REF TO cl_bcs.
DATA ls_soli TYPE soli.
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 sent_to_all TYPE os_boolean.
DATA sender TYPE REF TO if_sender_bcs.
DATA l_sendadr TYPE adr6-smtp_addr.
DATA l_atta_size TYPE sood-objlen.
DATA l_smtp_addr TYPE ad_smtpadr.
DATA s_user TYPE usrefus.
l_atta_size = i_excel_len.
TRY.
* create the send request
send_request = cl_bcs=>create_persistent( ).
* email subject
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = tt_text
i_subject = i_subject ).
* add list attachment to document
IF i_filename IS INITIAL.
CONCATENATE i_subject '.xlsx' INTO lv_attname.
ELSE.
CONCATENATE i_filename '.xlsx' INTO lv_attname.
ENDIF.
*ALI X X ABAP list document
*ARC X Archive object (image)
*BCS X External Document Storage
*BIN X Binary document
*DLI X Distribution list
*EXT X X PC document
*FOL X Folder
*GRA X X SAP Business Graphics
*OBJ X Business object
*OFO X Object folder
*OTF X OTF document
*R3I X IDoc
*RAW X X SAP editor document
*SCR X SAPscript document
*URL Link to Internet/Intranet
*WIM X Work item
*XXL X X Document for list viewer
document->add_attachment( i_attachment_type = 'EXT'
i_attachment_subject = lv_attname
i_attachment_size = l_atta_size
i_att_content_hex = i_excelx[] ).
*=============== prep send
* add document to send request
send_request->set_document( document ).
** create internal recipient
* LOOP AT i_user INTO s_user.
* recipient = cl_sapuser_bcs=>create( s_user-bname ).
* send_request->add_recipient( recipient ).
* ENDLOOP.
* create internal recipient
LOOP AT i_user INTO s_user WHERE bname NE ' ' AND useralias eq ' '.
recipient = cl_sapuser_bcs=>create( s_user-bname ).
send_request->add_recipient( recipient ).
ENDLOOP.
* create Email recipient and add to send request
LOOP AT i_user INTO s_user WHERE useralias NE ' '.
l_smtp_addr = s_user-useralias.
recipient = cl_cam_address_bcs=>create_internet_address( l_smtp_addr ).
send_request->add_recipient( i_recipient = recipient ).
ENDLOOP.
* create sender and add to send request
IF NOT i_use_noreply IS INITIAL.
CONCATENATE 'Noreply@' sy-sysid '-' sy-mandt '.de' INTO l_sendadr.
sender = cl_cam_address_bcs=>create_internet_address( l_sendadr ).
send_request->set_sender( EXPORTING i_sender = sender ).
ELSE.
IF NOT i_sender IS INITIAL.
l_sendadr = i_sender.
sender = cl_cam_address_bcs=>create_internet_address( l_sendadr ).
send_request->set_sender( EXPORTING i_sender = sender ).
ENDIF.
ENDIF.
* send
send_request->set_send_immediately( i_send_immediately = 'X' ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
CATCH cx_bcs INTO bcs_exception.
MESSAGE s865(so) WITH bcs_exception->error_type DISPLAY LIKE 'E'.
ENDTRY.
* commit work and wait.
ENDFUNCTION.
Code: Alles auswählen.
CONSTANTS : first_column TYPE char1 VALUE 'A'
.
DATA : worksheet TYPE REF TO zcl_excel_worksheet
, worksheet_title TYPE zexcel_sheet_title
, table_settings TYPE zexcel_s_table_settings
.
DATA : excel TYPE REF TO zcl_excel ##NEEDED.
table_settings-table_style = zcl_excel_table=>builtinstyle_medium2.
table_settings-show_row_stripes
= abap_true.
table_settings-nofilters = abap_true.
table_settings-top_left_column
= first_column.
table_settings-top_left_row = 01.
IF excel IS NOT BOUND.
CREATE OBJECT excel.
worksheet = excel->get_active_worksheet( ).
ELSE.
worksheet = excel->add_new_worksheet( ).
ENDIF.
worksheet_title = sy-datum.
worksheet->set_title( worksheet_title ).
worksheet->bind_table(
ip_table = i_data[]
is_table_settings = table_settings
).
*** Create output
DATA:
cl_writer TYPE REF TO zif_excel_writer.
DATA: xdata TYPE xstring. " Will be used for sending as email
" t_rawdata TYPE solix_tab, " Will be used for downloading or open directly
" bytecount TYPE i. " Will be used for downloading or open directly
CREATE OBJECT cl_writer TYPE zcl_excel_writer_2007.
xdata = cl_writer->write_file( excel ).
i_excel = cl_bcs_convert=>xstring_to_solix( iv_xstring = xdata ).
i_excel_len = xstrlen( xdata ).
ENDIF.
Code: Alles auswählen.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = C_FIELD_SEPARATOR
I_LINE_HEADER = I_LINE_HEADER
I_FILENAME = I_FILENAME
TABLES
I_TAB_SAP_DATA = I_TAB_SAP_DATA
CHANGING
I_TAB_CONVERTED_DATA = I_TAB_CONVERTED_DATA
EXCEPTIONS
CONVERSION_FAILED = C_RC4.
Folgende Benutzer bedankten sich beim Autor Tron für den Beitrag (Insgesamt 2):
Icke0801 • Schnibblerei
https://github.com/abap2xlsx/abap2xlsxSchnibblerei hat geschrieben: ↑04.04.2022 18:26Könntest du den Code der Klasse zcl_excel_worksheet und zcl_excel anhängen :)