* https://www.consolut.com/fileadmin/user_upload/SAP_PrintDoku/de/BCCIOFFI/BCCIOFFI.PDF
* https://www.saptechpro.com/post/SAPRDEMO_MS_DEMO
* https://www.saptechpro.com/post/SAPRDEMODOCUMENTCONTAINER2
* Eventhandler für Excel on_closed
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: on_close FOR EVENT on_close_document OF i_oi_document_proxy
IMPORTING
document_proxy
has_changed.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
METHOD on_close.
MESSAGE 'Excel closed.' TYPE 'S' DISPLAY LIKE 'W'.
ENDMETHOD.
ENDCLASS.
* Dummy-Screen für cl_gui_container=>default_screen deklarieren
SELECTION-SCREEN BEGIN OF SCREEN 100.
SELECTION-SCREEN END OF SCREEN 100.
START-OF-SELECTION.
TRY.
* Daten mit DOI (Excel inplace) anzeigen
DATA: o_oic TYPE REF TO i_oi_container_control.
DATA: o_oid TYPE REF TO i_oi_document_proxy.
DATA: o_err TYPE REF TO i_oi_error.
DATA: it_errors TYPE STANDARD TABLE OF REF TO i_oi_error WITH NON-UNIQUE DEFAULT KEY.
c_oi_container_control_creator=>get_container_control( IMPORTING
control = o_oic
error = o_err ).
APPEND o_err TO it_errors.
IF abap_true = o_err->has_succeeded.
o_oic->init_control( EXPORTING
inplace_enabled = abap_false
no_flush = abap_true
r3_application_name = 'Excel Daten'
parent = cl_gui_container=>default_screen
register_on_close_event = abap_true
IMPORTING
error = o_err ).
APPEND o_err TO it_errors.
IF abap_true = o_err->has_succeeded.
o_oic->get_document_proxy( EXPORTING
document_type = soi_doctype_excel_sheet " 'Excel.Sheet'
IMPORTING
document_proxy = o_oid
error = o_err ).
APPEND o_err TO it_errors.
IF abap_true = o_err->has_succeeded.
* neues, leeres Workbook einfügen
o_oid->create_document( EXPORTING
document_title = 'Excel Test'
open_inplace = abap_false
IMPORTING
error = o_err ).
* Event-Handler für on_close Event
SET HANDLER lcl_events=>on_close FOR o_oid.
* Abfrage nach dem Automation-Handle des Dokumentes
DATA: lv_cntl_handle TYPE cntl_handle.
o_oid->get_document_handle( IMPORTING
handle = lv_cntl_handle
error = o_err ).
APPEND o_err TO it_errors.
IF abap_true = o_err->has_succeeded.
* Ole-Funktionen Direkt aufrufen
DATA: o_xl_ole TYPE ole2_object.
DATA: o_cell_ole TYPE ole2_object.
GET PROPERTY OF lv_cntl_handle-obj 'Application' = o_xl_ole.
CALL METHOD OF o_xl_ole 'Cells' = o_cell_ole
EXPORTING
#1 = 1
#2 = 1.
SET PROPERTY OF o_cell_ole 'Value' = 'Test'.
FREE OBJECT o_cell_ole.
FREE OBJECT o_xl_ole.
* leere Toolbar ausblenden
cl_abap_list_layout=>suppress_toolbar( ).
* cl_gui_container=>default_screen erzwingen
CALL SCREEN 100.
* Schließen eines Dokuments in der Office-Anwendung
o_oid->close_document( IMPORTING error = o_err ).
APPEND o_err TO it_errors.
IF o_err->has_succeeded = abap_true.
* Schließen eines Visual-Basic-Dokuments
o_oid->close_activex_document( IMPORTING error = o_err ).
APPEND o_err TO it_errors.
IF o_err->has_succeeded = abap_true.
* Freigabe des für das Dokument reservierten Speichers
o_oid->release_document( IMPORTING error = o_err ).
APPEND o_err TO it_errors.
IF o_err->has_succeeded = abap_true.
FREE: o_oid.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
* baut das Control ab
o_oic->destroy_control( IMPORTING error = o_err ).
APPEND o_err TO it_errors.
IF o_err->has_succeeded = abap_true.
FREE: o_oic.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
* Ausgabe Fehlerprotokoll
DATA: lv_message_id TYPE sy-msgid.
DATA: lv_message_number TYPE sy-msgno.
DATA: lv_param1 TYPE sy-msgv1.
DATA: lv_param2 TYPE sy-msgv2.
DATA: lv_param3 TYPE sy-msgv3.
DATA: lv_param4 TYPE sy-msgv4.
LOOP AT it_errors ASSIGNING FIELD-SYMBOL(<e>).
<e>->get_message( IMPORTING
message_id = lv_message_id
message_number = lv_message_number
param1 = lv_param1
param2 = lv_param2
param3 = lv_param3
param4 = lv_param4
).
WRITE: / <e>->error_code, lv_message_id, lv_message_number, lv_param1, lv_param2, lv_param3, lv_param4.
ENDLOOP.
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.