16
Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1 Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes Applies to: SAP R3/ISU/CRM- ABAP side Summary This article explains how to create a custom Business Object Repository Object and Methods and attributes. Author(s): Anshumita Baksi Company: Tata Consultancy Services Ltd. Created on: 23 November 2006 Author Bio Anshumita Baksi is an SAP Technical Consultant with Tata Consultancy Services Ltd., India for more than 2 (two) years. She works in SAP Technical area (ABAP, Netweaver) for ISU, CRM and HR.

Creating Custom Business Object Repository (BOR) Objects, Methods, And Attributes

Embed Size (px)

DESCRIPTION

Creating Custom Business Object Repository (BOR) Objects

Citation preview

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

Applies to: SAP R3/ISU/CRM- ABAP side

Summary This article explains how to create a custom Business Object Repository Object and Methods and attributes. Author(s): Anshumita Baksi Company: Tata Consultancy Services Ltd. Created on: 23 November 2006

Author Bio

Anshumita Baksi is an SAP Technical Consultant with Tata Consultancy Services Ltd., India for more than 2 (two) years. She works in SAP Technical area (ABAP, Netweaver) for ISU, CRM and HR.

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 2

Table of Contents

Applies to: ........................................................................................................................................ 1

Summary.......................................................................................................................................... 1

Author Bio ........................................................................................................................................ 1

What is a Business Object Repository (BOR) object? .................................................................... 3

How to create a Custom BOR Object? ........................................................................................ 3

Your Custom BOR object is created. Now you need to create Methods inside it........................ 4

How to create a custom Method? ................................................................................................ 4

How to Create a Custom Attribute? ........................................................................................... 11

Sample Code Block for Attribute................................................................................................ 12

Sample Code Block for Method ................................................................................................. 13 Related Content............................................................................................................................. 15

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 3

What is a Business Object Repository (BOR) object? A business object is a problem-domain entity that you model in the SAP system, such as SalesOrder, BillingDocument and Employee. The BOR stores all the objects in the R/3 system. The repository is a group of all the objects in the R/3 system.

How to create a Custom BOR Object? The following steps should be performed in order to create a custom BOR object: Step 1: Copy a standard BOR object or create a new one using transaction SWO1 as shown in the Following figure.

Figure 1: Business Object Builder: Initial screen

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 4

Figure 2 : Copy Standard Object type

Your Custom BOR object is created. Now you need to create Methods inside it.

How to create a custom Method? Perform the following steps to create a custom method: Step 2: Create a custom method using the create option.

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 5

Figure 3: Create custom method Step 3: Create without FM template as shown below:

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 6

Figure 4: Create Method with function Module as template Step 4: Give Method-name, Name and Description.

Figure 5: Create Method- general tab Create Method- general tab

Step 5: Click on the ‘ABAP’ tab and attach a FM or BAPI, whichever is applicable.

Figure 6: Create Method- ABAP tab

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 7

Step 6: Create the FM or BAPI individually (using transaction SE37) and release the FM or BAPI, before attaching it to the method. Step 7: Create the parameters (Import and Export) with options (mandatory/ optional) with necessary ABAP dictionary field references as below:

Figure 7: Create Parameters for the Method

Figure 8: Create parameters with ABAP dictionary field proposals

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 8

Mention the type of parameter and options for it as shown:

Figure 9: Define parameters for the method The parameters are created as below:

Figure 10: Parameters created for the method Step 8: Create the program for the method generated as below: Click on the ‘Program’ tab.

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 9

Figure 11: Generate program for the Method The code will look like as below (this is auto-generated):

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 10

Figure 12: Auto generated code You just need to pass the parameters as declared before to the called function as shown above. Step10: First implement and then Release the Object type component as shown below:

Figure 13: Implement and release the Method

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 11

How to Create a Custom Attribute? i) Click on ‘Attributes’ node and after expanding, click on ‘create’ button.

Figure 14: Create Custom Attribute

ii) Create attribute without ABAP Dictionary field proposals as shown below:

Figure 15: Create attribute without ABAP dictionary field proposal

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 12

Similar to method, generate the program by clicking on ‘Program’ button. It will automatically generate the code. You can additionally put your own code as below:

Sample Code Block for Attribute GET_TABLE_PROPERTY ADR6. DATA SUBRC LIKE SY-SUBRC. * Fill TABLES ADR6 to enable Object Manager Access to Table Properties PERFORM SELECT_TABLE_ADR6 USING SUBRC. IF SUBRC NE 0. EXIT_OBJECT_NOT_FOUND. ENDIF. END_PROPERTY. * Use Form also for other(virtual) Properties to fill TABLES ADR6 FORM SELECT_TABLE_ADR6 USING SUBRC LIKE SY-SUBRC. * Select single * from ADR6, if OBJECT-_ADR6 is initial IF OBJECT-_ADR6-CLIENT IS INITIAL AND OBJECT-_ADR6-ADDRNUMBER IS INITIAL AND OBJECT-_ADR6-PERSNUMBER IS INITIAL AND OBJECT-_ADR6-DATE_FROM IS INITIAL AND OBJECT-_ADR6-CONSNUMBER IS INITIAL. data: l_adrnb type fkkvkp-adrnb, l_ADDRNUMBER type but020-ADDRNUMBER. select single adrnb from fkkvkp into l_adrnb where vkont = object-key-contractaccount. if l_adrnb is initial. select single ADDRNUMBER from but020 into l_ADDRNUMBER where partner = object-key-partner and XDFADR = 'X'. l_adrnb = l_ADDRNUMBER. endif. SELECT SINGLE * FROM ADR6 CLIENT SPECIFIED WHERE CLIENT = SY-MANDT AND ADDRNUMBER = l_adrnb AND FLGDEFAULT = 'X'. SUBRC = SY-SUBRC. IF SUBRC NE 0. EXIT. ENDIF. OBJECT-_ADR6 = ADR6. ELSE. SUBRC = 0. ADR6 = OBJECT-_ADR6. ENDIF. ENDFORM. The Custom attribute is now created and needs to be implemented and released as method.

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 13

Sample Code Block for Method This is an example of a code sample:

begin_method zcsf001 changing container.

data: l_zvat_print like zvat_print,

l_return type bapireturn,

t_zvat_printdata type standard table of zvat_printdata,

businesspartner type zvat_print-bu_partner,

contract type zvat_print-cont_num.

swc_get_element container 'BusinessPartner' businesspartner.

swc_get_element container 'Contract' contract.

l_zvat_print-bu_partner = businesspartner.

l_zvat_print-cont_num = contract.

call function 'ZBAPI_CS_VATPRINT'

exporting

vat_print = l_zvat_print

importing

return = l_return

tables

t_zvat_printdata = t_zvat_printdata

exceptions

others = 01.

case sy-subrc.

when 0. " OK

when others. " to be implemented

endcase.

end_method. Step 11: Finally release the Object as well as shown below:

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 14

Figure 16: Release and Generate the Object The custom BOR object type is successfully created and ready to be tested!

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 15

Related Content Please include at least three references to SDN documents or web pages. http://www.erpgenie.com/abap/bor.htm http://help.sap.com

Creating Custom Business Object Repository (BOR) Objects, Methods and Attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 16

Copyright © Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. Any software coding and/or code lines/strings (“Code”) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.