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 w as an Exchange Infrastructure technical analyst. His other skills and interests are J ava/C+ programming, XML, and SOAP. orks +
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: SERVI CE( 255) , BUSI DENTI FS LI KE BORI DENT OCCURS 0, LS_BORI DENT t ype BORI DENT.
CLEAR LS_BORI DENT. LS_BORI DENT- LOGSYS = SPACE. LS_BORI DENT- OBJ TYPE = ' ZGOS' . LS_BORI DENT- OBJ KEY = OBJ ECT- KEY. APPEND LS_BORI DENT t o BUSI DENTI FS. SWC_GET_ELEMENT CONTAI NER ' Ser vi ce' SERVI CE. SWC_SET_TABLE CONTAI NER ' BusI dent i f s' BUSI DENTI FS.
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.
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.
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.