Arcobjects: Integrate An Arcobjects Application in Sapgui: Mapctrl - Loadmxfile Strfilepath
Arcobjects: Integrate An Arcobjects Application in Sapgui: Mapctrl - Loadmxfile Strfilepath
Requirements: R/3 version 4.0b and higher (sample code is for 4.6b) Visual Basic 6.0 ArcObjects and the proper license and hardware key Description: The following steps describe how to create a basic ArcObjects application in Visual Basic that can be used in SAPGUI. It includes sample code that integrates the application using SAPs Desktop Office Integration. Please see http://www.sappro.com/V2I2A1.html for more information. 1) Create an ActiveX document executable (exe) in VB. Name your project SAPGIS and name the document Map. 2) Add an ArcObjects map control to the user document and name it MapCtrl. 3) In the UserDocument_Initialize procedure event add the following code: MapCtrl.LoadMxFile strFilePath Where strFilePath contains the path to an ArcMap document file. 4) Add a Command button to the user document and name it CustomEvent 5) In the CustomEvent_OnMouseDown procedure add the following code:
UserDocument.Parent.SendCustomEvent "CustomEvent1", 2,Value1,Value2
6) Compile the project into SAPGIS.exe 7) Integrate the ActiveX application using standard SAP Desktop Office Integration techniques. As a sample follow these steps: a. In R/3, create an ordinary report (executable program type 1), name it Z_ARCOBJECTS_DEMO b. Cut and paste the following code into the report you just created. The code uses standard Desktop Office Integration techniques in SAP.
REPORT Z_ARCOBJECTS_DEMO. CALL SCREEN 100. *XXXXXXXXXXXXXXX START ActiveX Doc Proxy Definition XXXXXXXXXXXXXXXXXX
*--------------------------------------------------------------------* * CLASS c_gis_tool DEFINITION *--------------------------------------------------------------------* * ........ * *--------------------------------------------------------------------* CLASS c_gis_tool DEFINITION. PUBLIC SECTION. DATA: gis_tool_proxy TYPE REF TO i_oi_document_proxy. METHODS: constructor IMPORTING container TYPE REF TO i_oi_container_control. METHODS: close. METHODS: on_custom FOR EVENT on_custom_event OF i_oi_document_proxy IMPORTING DOCUMENT_PROXY EVENT_NAME PARAM1 PARAM2 PARAM3 PARAM4 PARAM5 PARAM6 PARAM7 PARAM8 PARAM9 PARAM10 PARAM11 PARAM12. ENDCLASS. **************************************************************** ******** * CLASS c_gis_tool IMPLEMENTATION. **************************************************************** ******** CLASS c_gis_tool IMPLEMENTATION. **************************************************************** ******** METHOD: constructor. IF NOT me->gis_tool_proxy IS INITIAL. CALL METHOD me->close. FREE gis_tool_proxy. ENDIF. CALL METHOD container->get_document_proxy EXPORTING document_type = SAPGIS.Map document_format = 'OLE' IMPORTING document_proxy = me->gis_tool_proxy. CALL METHOD me->gis_tool_proxy->create_document EXPORTING create_view_data = 'X' open_inplace = 'X'. SET HANDLER me->on_custom FOR gis_tool_proxy.
ENDMETHOD. **************************************************************** ******** METHOD close. IF NOT me->gis_tool_proxy IS INITIAL. CALL METHOD me->gis_tool_proxy->release_document. '. SET HANDLER me->on_custom FOR gis_tool_proxy ACTIVATION '
ENDIF. ENDMETHOD. **************************************************************** ******** METHOD on_custom. * event_name will contain CustomEvent1 * param1 will contain 2 * param2 will contain Value1 * param3 will contain Value2 ENDMETHOD. **************************************************************** ******** ENDCLASS. *XXXXXXXXXXXXXXX END ActiveX Doc Proxy Definition XXXXXXXXXXXXXXXXXX *XXXXXXXXXXXXXXX START DEMO APPLICATION XXXXXXXXXXXXXXXXXX DATA: FCODE LIKE SY-UCOMM. DATA: sapgui_proxy TYPE REF TO cl_gui_custom_container. DATA: tool_container TYPE REF TO i_oi_container_control. DATA: gis_tool TYPE REF TO c_gis_tool. *&--------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&--------------------------------------------------------------------* MODULE status_0100 OUTPUT. IF sapgui_proxy IS INITIAL. CREATE OBJECT sapgui_proxy EXPORTING container_name = 'CONTAINER'. CALL METHOD c_oi_container_control_creator=>get_container_control IMPORTING control = tool_container. CALL METHOD c_oi_errors=>raise_message EXPORTING type = 'E'. CALL METHOD tool_container->init_control EXPORTING r3_application_name = 'GIS Tool' inplace_enabled = 'X' inplace_scroll_documents = '' INPLACE_SHOW_TOOLBARS = '' autoalign = 'X' parent = sapgui_proxy
register_on_close_event = '' register_on_custom_event = 'X'. CALL METHOD c_oi_errors=>raise_message EXPORTING type = 'E'. IF NOT gis_tool IS INITIAL. CALL METHOD gis_tool->close. FREE gis_tool. ENDIF. CREATE OBJECT gis_tool EXPORTING container = tool_container. CALL METHOD c_oi_errors=>raise_message EXPORTING type = 'E'. ENDIF. ENDMODULE. " STATUS_0100 OUTPUT
*&--------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&--------------------------------------------------------------------* MODULE user_command_0100 INPUT. DATA: l_fcode LIKE fcode. l_fcode = fcode. CLEAR fcode. CALL METHOD cl_gui_cfw=>dispatch. CASE l_fcode. WHEN 'EXIT'. "Zurck IF NOT gis_tool IS INITIAL. CALL METHOD gis_tool->close. FREE gis_tool. ENDIF. IF NOT tool_container IS INITIAL. CALL METHOD tool_container->destroy_control. FREE tool_container. ENDIF. LEAVE PROGRAM. ENDCASE. ENDMODULE.
c. Save the report. Create screen 0100 for the report you created using the Screen Painter. d. Using the layout editor, add a Custom control about 20 lines by 60 columns and name it CONTAINER e. Edit the flow logic of that screen and uncomment MODULE STATUS_0100 and MODULE USER_COMMAND_0100 as seen below
PROCESS BEFORE OUTPUT. MODULE STATUS_0100. PROCESS AFTER INPUT. MODULE USER_COMMAND_0100.
f. Save and activate screen 0100 and report Z_ARCOBJECTS_DEMO g. Test by executing report Z_ARCOBJECTS_DEMO