SDN Contribution How to Attach Documents to Any Custom Program Using Generic Object Services Applies to: SAP R/3 4.6C Summary This sample code describes the steps needed to easily add file attachment feature to any custom report/module pool by using Generic Object Services (GOS). Users will have the possibility to store documents or notes for a specific application (instead of for a specific document as usual). Created on: 23 March 2006 Author Bio Manuel Bassani lives in Vicenza (Italy) and has worked with SAP technologies as a freelancer since 2001. After some years as an ABAP senior developer in several projects, he actually works as an Exchange Infrastructure technical analyst. His other skills and interests are Java/C++ programming, XML, and SOAP. © 2006 SAP AG 1 Table of Contents Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Table of Contents ............................................................................................................................ 2 Business Object Creation ................................................................................................................ 2 Integrating GOS in Custom Programs............................................................................................. 4 Case 1: File Attachment in Report Selection Screen................................................................... 4 Case 1: Screenshot .................................................................................................................. 5 Case 2: File Attachment in Lists .................................................................................................. 6 Case 2: Screenshot .................................................................................................................. 6 Case 3: File Attachment in Module Pool...................................................................................... 7 Case 3: Main program .............................................................................................................. 7 Case 3: Dynpro 100 logic ....................................................................................................... 10 Case 3: Screenshot – GOS toolbar........................................................................................ 10 Case 3: Screenshot – GOS Integrated in Dynpro Toolbar..................................................... 11 Related Content............................................................................................................................. 11 Disclaimer and Liability Notice....................................................................................................... 12 Business Object Creation In order to make GOS work with a custom program instead of a document, it is necessary to create a custom Business object that implements interface IFGOSASERV. Once BO is created it must be set to released status. 1. Run transaction SWO1 (Business Object Builder), choose an object name, select “Object Type” radio button and press “Create” button. © 2006 SAP AG 2 2. A popup appears. Fill fields Object type, Object name, Name, Description and Program. Choose Application = '*'. Leave Supertype blank. 3. In the main page position the mouse pointer on “Interfaces” and press F5 (add object). In the popup choose interface IFGOSASERV 4. Add key fields by position on “Key Fields” and press F5. Choose table field TRDIR-NAME © 2006 SAP AG 3 5. Position on method GOSAddObjects and press F6 (redefine). Insert the following code: DATA: SERVICE(255), BUSIDENTIFS LIKE BORIDENT OCCURS 0, LS_BORIDENT type BORIDENT. CLEAR LS_BORIDENT. LS_BORIDENT-LOGSYS = SPACE. LS_BORIDENT-OBJTYPE = 'ZGOS'. LS_BORIDENT-OBJKEY = OBJECT-KEY. APPEND LS_BORIDENT to BUSIDENTIFS. SWC_GET_ELEMENT CONTAINER 'Service' SERVICE. SWC_SET_TABLE CONTAINER 'BusIdentifs' BUSIDENTIFS. 6. Save and genetate Business Object. Set release status to “released” Integrating GOS in Custom Programs Case 1: File Attachment in Report Selection Screen REPORT ZGOS_1. CONSTANTS: OBJTYPE TYPE BORIDENT-OBJTYPE VALUE 'ZGOS'. DATA: MANAGER TYPE REF TO CL_GOS_MANAGER, © 2006 SAP AG 4 OBJ TYPE BORIDENT. PARAMETERS: MATNR TYPE MARA-MATNR. AT SELECTION-SCREEN OUTPUT. CLEAR OBJ. * SET OBJECT TYPE TO 'ZGOS' OBJ-OBJTYPE = OBJTYPE. * SET OBJECT KEY = REPORT NAME SELECT SINGLE NAME FROM TRDIR INTO OBJ-OBJKEY WHERE NAME = SY-REPID. * CALL GOS MANAGER WITHOUT CONTAINER (WILL BE DISPLAYED IN THE TOOLBAR) CREATE OBJECT MANAGER EXPORTING IS_OBJECT = OBJ EXCEPTIONS OTHERS = 1. Case 1: Screenshot © 2006 SAP AG 5 Case 2: File Attachment in Lists CONSTANTS: OBJTYPE TYPE BORIDENT-OBJTYPE VALUE 'ZGOS'. DATA: MANAGER TYPE REF TO CL_GOS_MANAGER, OBJ TYPE BORIDENT. PARAMETERS: MATNR TYPE MARA-MATNR. START-OF-SELECTION. CLEAR OBJ. * SET OBJECT TYPE TO 'ZGOS' OBJ-OBJTYPE = OBJTYPE. * SET OBJECT KEY = REPORT NAME SELECT SINGLE NAME FROM TRDIR INTO OBJ-OBJKEY WHERE NAME = SY-REPID. * CALL GOS MANAGER WITHOUT CONTAINER (WILL BE DISPLAYED IN THE TOOLBAR) CREATE OBJECT MANAGER EXPORTING IS_OBJECT = OBJ EXCEPTIONS OTHERS = 1. WRITE: 'WRITE SOMETHING'. Case 2: Screenshot © 2006 SAP AG 6 Case 3: File Attachment in Module Pool This example shows how to integrate GOS features both via GOS toolbar and via dynpro toolbar Case 3: Main program REPORT ZGOS_3. CONSTANTS: OBJTYPE TYPE BORIDENT-OBJTYPE VALUE 'ZGOS'. TYPES: BEGIN OF EXCLUDE_TYPE, FCODE LIKE RSMPE-FUNC, END OF EXCLUDE_TYPE. DATA: MANAGER TYPE REF TO CL_GOS_MANAGER, OBJ TYPE BORIDENT, OK_CODE TYPE SY-UCOMM, EXCLUDE_TAB TYPE STANDARD TABLE OF EXCLUDE_TYPE, EXCLUDE_WA TYPE EXCLUDE_TYPE. * TOOLBAR: DISPLAY GOS TOOLBAR IN DYNPRO * DIRECT: CALL GOS SERVICES DIRECTLY FROM DYNPRO TOOLBAR PARAMETERS: TOOLBAR RADIOBUTTON GROUP GR1 DEFAULT 'X', DIRECT RADIOBUTTON GROUP GR1. START-OF-SELECTION. © 2006 SAP AG 7 * CALL SCREEN CALL SCREEN '0100'. *&---------------------------------------------------------------------* *& Module init OUTPUT *&---------------------------------------------------------------------* MODULE INIT OUTPUT. * INIT IF MANAGER IS INITIAL. OBJ-OBJTYPE = OBJTYPE. SELECT SINGLE NAME FROM TRDIR INTO OBJ-OBJKEY WHERE NAME = SY-REPID. * WITH GOS TOOLBAR IF TOOLBAR = 'X'. CLEAR: EXCLUDE_TAB, EXCLUDE_WA. MOVE 'ATTACH' TO EXCLUDE_WA-FCODE. APPEND EXCLUDE_WA TO EXCLUDE_TAB. MOVE 'LIST' TO EXCLUDE_WA-FCODE. APPEND EXCLUDE_WA TO EXCLUDE_TAB. SET PF-STATUS 'MAIN' EXCLUDING EXCLUDE_TAB. CREATE OBJECT MANAGER EXPORTING IS_OBJECT = OBJ IP_NO_COMMIT = 'R' © 2006 SAP AG 8 EXCEPTIONS OTHERS = 1. * WITHOUT GOS TOOLBAR (DIRECT SERVICE CALL) ELSE. SET PF-STATUS 'MAIN'. CREATE OBJECT MANAGER EXPORTING IP_NO_COMMIT = 'R' EXCEPTIONS OTHERS = 1. ENDIF. ENDIF. ENDMODULE. " init OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* MODULE USER_COMMAND_0100 INPUT. CASE OK_CODE. WHEN 'BACK' OR 'LEAVE' OR 'EXIT'. LEAVE TO SCREEN '0000'. * CALL CREATE ATTACHMENT SERVICE FROM TOOLBAR WHEN 'ATTACH'. CALL METHOD MANAGER->START_SERVICE_DIRECT EXPORTING IP_SERVICE = 'CREATE_ATTA' IS_OBJECT = OBJ © 2006 SAP AG 9 EXCEPTIONS NO_OBJECT = 1 OBJECT_INVALID = 2 EXECUTION_FAILED = 3 OTHERS = 4. WHEN 'LIST'. CALL METHOD MANAGER->START_SERVICE_DIRECT EXPORTING IP_SERVICE = 'VIEW_ATTA' IS_OBJECT = OBJ EXCEPTIONS NO_OBJECT = 1 OBJECT_INVALID = 2 EXECUTION_FAILED = 3 OTHERS = 4. ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT Case 3: Dynpro 100 logic PROCESS BEFORE OUTPUT. MODULE INIT. PROCESS AFTER INPUT. MODULE USER_COMMAND_0100. Case 3: Screenshot – GOS toolbar © 2006 SAP AG 10 Case 3: Screenshot – GOS Integrated in Dynpro Toolbar Related Content Some useful links: Generic Object Services (BC-SRV-GBT) Generic Object Services (GOS) - in Background [by Ram Manohar Tiwari] © 2006 SAP AG 11 Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document. © 2006 SAP AG 12