BOR-Integration
In diesem Beispiel laden wir eine im BOR (Business Object Repository) gespeicherte Excel-Datei, verändern diese und Speichern sie als neues Dokument wieder im BOR ab. Dabei wird die Excel-Datei nicht auf dem PC zwischengespeichert. Stattdessen werden die entsprechenden Methoden der Desktop Office Integration verwendet.
Information
Die in diesem Fall als Template verwendete Excel-Datei muss mithilfe der Transaktion OAER in das Business Objects Repository geladen werden!
TIPP 1:
Sie können auch eigene “Klassen” definieren. Um ZMYCLASS zu erstellen, rufen Sie die Transaktion SBDSV1 auf und pflegen Sie den Eintrag ZMYCLASS und ordnen Sie den Objekttyp “OT” zu. Mit Transaktion SBDSV3 können Sie einen Text definieren.
Sie können auch einen Exit-Funktionsbaustein eintragen, wie z.B. DYNDOC_BDS_APPLICATION_EXIT, der bei PICTURES-OT hinterlegt ist. Wenn Sie Ihren eigenen Exit verwenden, können Sie z.B. das Hochladen bestimmter Dateitypen in bestimmten Klassen verhindern, automatisch Schlagworte hinzufügen oder zusätzlich wichtige Attribute abfragen.
TIPP 2:
In diesem Programmbeispiel wird die Exceldatei wieder unter dem Typ “BDS_SHEET – Tabellenvorlage” gespeichert. Sie können auch einen anderen Typen festlegen! Schauen Sie dazu in die Transaktion OAC2.
Coding
REPORT ZZ_BOR_DOI_DEMO. *** Definition of Control references DATA cl_container TYPE REF TO cl_gui_container. DATA cl_control TYPE REF TO i_oi_container_control."OIContainerCtrl DATA cl_document TYPE REF TO i_oi_document_proxy. "Office Dokument DATA cl_spreadsheet TYPE REF TO i_oi_spreadsheet. " Spreadsheet DATA gv_url TYPE bds_uri. TYPE-POOLS: soi. *** Selection screen PARAMETER p_class TYPE bds_clsnam DEFAULT 'ZMYCLASS'. PARAMETER p_cltyp TYPE bds_clstyp DEFAULT 'OT'. PARAMETER p_tmpnam TYPE bds_typeid DEFAULT 'TEMPLATE'. PARAMETER p_newnam TYPE bds_typeid DEFAULT 'NewDocument_1'. START-OF-SELECTION. *** Get URL for desired template PERFORM get_template_url CHANGING gv_url. *** Create document using DOI and load from BOR PERFORM load_document USING gv_url. *** Save changed document as new document in BOR PERFORM save_document_as. *** Clean up work PERFORM cleanup. *&---------------------------------------------------------------------* *& Form get_template_url *&---------------------------------------------------------------------* FORM get_template_url CHANGING cv_url. DATA lt_uris TYPE STANDARD TABLE OF bapiuri. DATA ls_uri TYPE bapiuri. *** get URL for desired template CALL FUNCTION 'BDS_BUSINESSDOCUMENT_GET_URL' EXPORTING classname = p_class classtype = p_cltyp object_key = p_tmpnam TABLES uris = lt_uris EXCEPTIONS OTHERS = 7. *** if more versions exist, you might use the SIGNATURE parameter *** to define the right version READ TABLE lt_uris INTO ls_uri INDEX 1. cv_url = ls_uri-uri. ENDFORM. "get_template_url *&---------------------------------------------------------------------* *& Form load_document *&---------------------------------------------------------------------* FORM load_document USING iv_url. TYPES: tyt_errors TYPE STANDARD TABLE OF REF TO i_oi_error WITH NON-UNIQUE DEFAULT KEY. DATA: error TYPE REF TO i_oi_error, t_errors TYPE tyt_errors, ole_sheet TYPE ole2_object, ole_appl TYPE ole2_object, ole_cell TYPE ole2_object, lv_handle TYPE cntl_handle. *** Create instance of OI CALL METHOD c_oi_container_control_creator=>get_container_control IMPORTING control = cl_control error = error. APPEND error TO t_errors. *** init control CALL METHOD cl_control->init_control EXPORTING inplace_enabled = space no_flush = 'X' r3_application_name = 'Demo BOR' parent = cl_container IMPORTING error = error EXCEPTIONS OTHERS = 2. APPEND error TO t_errors. *** Get Documentproxy CALL METHOD cl_control->get_document_proxy EXPORTING document_type = 'Excel.Sheet' " EXCEL * document_type = 'Word.Document' " WORD no_flush = 'X' IMPORTING document_proxy = cl_document error = error. APPEND error TO t_errors. *** Load document from BOR CALL METHOD cl_document->open_document EXPORTING document_title = 'Demo BOR' document_url = iv_url no_flush = 'X' open_inplace = space IMPORTING error = error. APPEND error TO t_errors. *** generate Spreadsheetinterface CALL METHOD cl_document->get_spreadsheet_interface EXPORTING no_flush = ' ' IMPORTING error = error sheet_interface = cl_spreadsheet. APPEND error TO t_errors. *** get handle of document for work with OLE CALL METHOD cl_document->get_document_handle EXPORTING no_flush = 'X' IMPORTING error = error handle = lv_handle. APPEND error TO t_errors. *** get OLE application object GET PROPERTY OF lv_handle-obj 'Application' = ole_appl. *** get OLE cell object CALL METHOD OF ole_appl 'Cells' = ole_cell EXPORTING #1 = 1 "line #2 = 5. "column *** set cell value SET PROPERTY OF ole_cell 'Value' = 'Document changed!'. *** get active sheet for other operations... GET PROPERTY OF lv_handle-obj 'ActiveSheet' = ole_sheet. *** display errors LOOP AT t_errors INTO error. CALL METHOD error->raise_message EXPORTING type = 'E' EXCEPTIONS message_raised = 1 flush_failed = 2. ENDLOOP. ENDFORM. " build_spreadsheet_interface *&---------------------------------------------------------------------* *& Form save_document_as *&---------------------------------------------------------------------* FORM save_document_as . DATA lt_uris TYPE STANDARD TABLE OF bapiuri. DATA ls_uri TYPE bapiuri. DATA lv_object_key TYPE bapibds01-objkey. DATA lt_data TYPE STANDARD TABLE OF bapiconten. DATA lv_doc_size TYPE i. DATA lt_signature TYPE STANDARD TABLE OF bapisignat. DATA ls_signature TYPE bapisignat. DATA lt_components TYPE STANDARD TABLE OF bapicompon. DATA ls_component TYPE bapicompon. *** Save DOI document to internal table CALL METHOD cl_document->save_document_to_table CHANGING document_size = lv_doc_size document_table = lt_data. *** fill signature ls_signature-prop_name = 'BDS_DOCUMENTTYPE'. "#EC NOTEXT ls_signature-prop_value = 'BDS_SHEET'. APPEND ls_signature TO lt_signature. ls_signature-prop_name = 'BDS_DOCUMENTCLASS'. "#EC NOTEXT ls_signature-prop_value = 'XLS'. APPEND ls_signature TO lt_signature. ls_signature-prop_name = 'DESCRIPTION'. "#EC NOTEXT ls_signature-prop_value = 'Tricktresor.de'. APPEND ls_signature TO lt_signature. ls_signature-prop_name = 'LANGUAGE'. "#EC NOTEXT ls_signature-prop_value = sy-langu. APPEND ls_signature TO lt_signature. *** fill component info CONCATENATE p_newnam '.xls' INTO ls_component-comp_id. ls_component-mimetype = 'application/vnd.ms-excel'. ls_component-comp_size = lv_doc_size. APPEND ls_component TO lt_components. *** create new document from changed template CALL FUNCTION 'BDS_BUSINESSDOCUMENT_CREA_TAB' EXPORTING classname = p_class classtype = p_cltyp client = sy-mandt object_key = p_newnam TABLES signature = lt_signature components = lt_components content = lt_data EXCEPTIONS OTHERS = 7. IF sy-subrc <> 0. BREAK-POINT. ENDIF. ENDFORM. " save_as *&---------------------------------------------------------------------* *& Form cleanup *&---------------------------------------------------------------------* FORM cleanup. *** close document CALL METHOD cl_document->close_document. *** destroy control CALL METHOD cl_control->destroy_control EXPORTING no_flush = ' '. *** free objects FREE cl_spreadsheet. CLEAR: cl_spreadsheet. IF NOT cl_document IS INITIAL. CALL METHOD cl_document->release_document. ENDIF. FREE: cl_document, cl_control. CLEAR: cl_document, cl_control. ENDFORM. "cleanup
- 7. December: Excel Racing Simulation – Root Vole Race - 7. Dezember 2024
- 5. December: ABAPConf - 5. Dezember 2024
- 4. December: Only a lazy developer is a good developer - 4. Dezember 2024