custom genil bol for z-tables with relationships.pdf

Upload: krishanu-dutta

Post on 10-Feb-2018

259 views

Category:

Documents


8 download

TRANSCRIPT

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    1/12

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 1

    Creating Custom GenIL/BOL Modelfor Z-tables Bound byRelationships

    Applies to:

    SAP CRM 6.0. For more information, visit theCustomer Relationship Management homepage.

    Summary

    A walkthrough, explaining the steps for creating a custom GenIL/BOL model for handling your Z-tablesbound by relationships.

    Author: Arun Prakash Karuppanan

    Company: AccentureCreated on: 24 February 2010

    Author Bio

    Arun Prakash Karuppanan is an application developer in SAP-CRM. He is currently employed withAccenture Services Private Ltd.

    https://www.sdn.sap.com/irj/sdn/bpx-crmhttps://www.sdn.sap.com/irj/sdn/bpx-crmhttps://www.sdn.sap.com/irj/sdn/bpx-crmhttps://www.sdn.sap.com/irj/sdn/bpx-crm
  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    2/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 2

    Table of Contents

    Introduction ......................................................................................................................................................... 3Creating the sample Model ................................................................................................................................. 3

    Identifying Tables Needed: ............................................................................................................................. 3Identifying relationships and cardinality: ......................................................................................................... 3Create tables: .................................................................................................................................................. 5

    Check table relationships: ............................................................................................................................................ 5Identifying BOL business objects: ................................................................................................................... 5Implementing the GenIL class: ....................................................................................................................... 6Making our Model known to the system.......................................................................................................... 9Handling Non-Root objects in model ............................................................................................................ 10

    Related Content ................................................................................................................................................ 11Disclaimer and Liability Notice .......................................................................................................................... 12

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    3/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 3

    Introduction

    SAP has provided many "Models" to take care of all requirements under various business scenarios. Forexample, Sales, Marketing, Campaign etc., This is what you see under "Model" in the runtime repository ofthe BSP component. You probably know that each of the Model has its own implementation class aka GenILhandler class. This information can be found in the IMG path "custom er re la t ionship management->crmcros s-appl ication com pon ents->generic interaction layer/object layer->basic sett ings".

    Now, you might have come across some requirements that require you to take care of some custom tables.You might have to develop user interfaces, write the table maintenance logic etc. You might also have to use

    the table data in some standard application screens. In case of single tables without relationships, you mightget off easily. In fact, there is a WIKI entry showing you how to create a model for simple objects (WikiEntry). But how about a set of tables bound by relationships?

    In BSP development, a crude approach in this scenario is to use value nodes and call the maintenance logicdirectly in the getter-setter/event handlers directly. Reuse and enhancements are a pain. Want to do it thebetter way? When it comes to taking care of business data while allowing the end user to play around withthe interface, you have to worry about data consistency and integrity, application performance, reusability ofyour code etc., Performance(buffering) is crucial when you deal with tables with huge amount of transactiondata. SAP knows its business and the architecture is a tried and tested one. Why not leverage on theirexpertise? You might have seen how wizards in the component workbench and BOL programming makedeveloping user interfaces easy when using Model Nodes. Do you want the same convenience andreusability? The solution is to create your own Model.

    Creating the sample Model

    Creating a Model require you to understand some relational database concepts. Once we get through that,we will look at how to create the implementation class. For this walkthrough, I'm not going to create a modelfrom scratch. I will provide you with a walkthrough based on the simplest model implementation sampleavailable in the package 'CRM_GENIL_SAMPLE'.

    Identifying Tables Needed:

    In this model we have a header object "Order". Each Order can have a single "Partner" entry and multiple"Item" entries. Each Item has exactly one "Shipping Data" entry. So, we need four database tables.

    ZORDER for storing Orders.

    ZPARTNER for storing Order Partners.ZITEM for storing Order Items.

    ZSHIPMENT for storing Item shipment data.

    Identifying relationships and cardinality:

    Relationships can be of three types:

    A - Association - An association is simply any sort of relationship between two tables.

    B - Composition - This is a strong association. Meaning, Part A uses part B in it, and Part A gettingdestroyed means that part B is also destroyed.

    C - Aggregation - This is a weak "has a" relationship. Meaning, Part A uses part B in it, but Part A gettingdestroyed does not necessarily mean that part B should be destroyed.

    Cardinality can be of four types. I'm sure this needs no explanation.

    A - 0..1

    B - 0..n

    C - 1

    D - 1..n

    Now, identify the relationships between these tables.

    http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1
  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    4/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 4

    ZORDER has a relationship with ZPARTNER. According to our business rule, an entry in tableZORDER can have zero to multiple entries in table ZPARTNER referring to it through a foreign key.But each entry in table ZPARTNER must refer to one entry in table ZORDER and only one. Let'sgive this relationship a name "OrderPartnerRel". So the relation ship cardinality is

    ZORDER----------------------->ZPARTNER1 OrderPartnerRel 0..n

    This is an aggregat ingrelationship as the primary key of the ZPARTNER table is not part of any foreignkey relationship with ZORDER table.

    The exact same rule applies for the relationship between the tables ZORDER and ZITEM. Let'sname the relationship "OrderItemRel"

    ZORDER------------------>ZITEM1 OrderItemRel 0..n

    This is an aggregat ingrelationship as the primary key of the ZITEM table is not part of any foreign keyrelationship with ZORDER table. You will see more of this below, when creating tables.

    ZITEM has a relationship with ZSHIPMENT. By our business rules, each item line must have exactlyone shipment line. Each shipment line must refer to an item line and not more than one. Let's givethe relationship a name "OrderItemShipmentData". So, the cardinality is as follows.

    ZITEM----------------------->ZSHIPMENT1 OrderItemShipmentRel 1

    This is a compos i terelationship as the primary key of the ZHIPMENT table is supplied by ZITEM. You will seemore of this below, when creating tables.

    Apart from these relationships, our ZPARTNER table has a relationship with the standard mastertable but000. Each line in ZPARTNER table must refer to an entry in but000 table and not morethan one. Let's name this relationship "BusinessPartnerRel". The cardinality is as follows.

    ZPARTNER----------------------->BUT0001 BusinessPartnerRel 1

    This is an associat ionrelationship as the operations on ZPARTNER table does not have any effect on the

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    5/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 5

    Create tables:

    Now that we have identified the relationships, we can proceed creating the tables with required fields andcheck table relations as follows.

    The necessary fields are available in the structures shown below. Do not directly append these structures tothe table. Rather, create the same fields as found in the structure. Otherwise, you will face difficultiesspecifying primary keys and foreign key relationships. Once you have created the tables, create structuresfor accessing entity data in BOL at runtime (CL_CRM_BOL_ENTITY->CONTAINER_PROXY->DATA_REF).During runtime in the BOL layer, not all fields of the table are required for manipulation. Thus, the table fields

    and the fields available at runtime in BOL layer might be different. If this bothers you, you may use the sametype in BOL also. In the SAP sample, the runtime structure types are different for some objects. For thosetables, whose structure differs from the BOL runtime field structure, I have specified the type in ABAP syntax.

    Table Table Structure Type BOL structure type

    ZORDER CRMT_GENIL_ORDER_ATTR CRMT_GENIL_ORDER_ATTR

    ZITEM types: begin of GTYPE_ITEM,

    HEADER_GUID type CRMT_GENIL_OBJECT_GUID.include type CRMT_GENIL_ITEM_ATTR as ATTR.

    types: end of GTYPE_ITEM,

    CRMT_GENIL_ORDER_ATTR

    ZPARTNER types: begin of GTYPE_PARTNER,

    HEADER_GUID type CRMT_GENIL_OBJECT_GUID.include type CRMT_GENIL_PARTNER_ATTR as ATTR.

    types: end of GTYPE_PARTNER,

    CRMT_GENIL_PARTNER_ATTR

    ZSHIPMENT CRMT_GENIL_SHIPMENT_ATTR CRMT_GENIL_SHIPMENT_ATTR

    Check table relationships:

    ZITEM-HEADER_GUID ----> ZORDER-GUID

    ZPARTNER-HEADER_GUID ----> ZORDER-GUID

    ZSHIPMENT-GUID ----> ZITEM-GUID

    ZPARTNER-NUMBER ----> BUT000-PARTNER

    Identifying BOL business objects:

    Now it's time to identify the BOL objects for our model. A BOL object may refer to a table line or query objector view object or query result object etc., The different kinds of business objects are specified below.

    A Root Object

    B Access Object

    C Dependent Object

    D Search Object

    E Search Result Object

    F View Object

    G Dynamic Search Object

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    6/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 6

    Root Object :This is a special access object, that is at the top of the hierarchy. See access object below.Access Object :This is an object that can be accessed independently, without requiring information from other objects. It

    has an ID that can be used to determine both the attributes of the access object itself and those of its dependentobjects.

    Dependent Object :A dependent object is a special type of business object, whose attributes cannot be determinedsolely from the ID of this business object, but instead, only or together with the ID of the superior access object.

    Search Object :These are query objects.Search Result Object :These are query results. The returned results may also directly correspond to root/access

    entitiesDynamic Search Object :Advanced query Objects

    In our model, we have the following business objects.

    Order -> Root object

    OrderItem ->Access object. Now, ideally, we would think that OrderItem is adependent object. But, remember that the shipment line refers to the item line and not the orderline. So, OrderItem must exist as an access object for the sake of shipment data.

    OrderItemShipmentData ->Dependent object. It depends on OrderItem object for meaningfulexistence.

    OrderPartner ->Dependent object. It depends on Order object for meaningful existence.

    OrderQuery ->Search Object OrderItemQuery ->Search Object

    AdvOrderHquery ->Dynamic Search Object

    AdvOrderQuery ->Dynamic Search Objects

    Important Note: While giving names to your BOL objects, make sure that unlike in this example, you use the Z oryour customer name space. This is to ensure that no conflict arises with standard BOL objects when variouscomponent sets are loaded in the user environment. Check out the Model SAMPLE in transactionGENIL_MODEL_BROWSER.

    Implementing the GenIL class:

    Now, it's time to implement the GenIL class. This class should inherit the interfacesIF_GENIL_APPL_INTLAY and IF_GENIL_APPL_MODEL or directly inherit from the classCL_CRM_GENIL_ABSTR_COMPONENT. It's time you opened the classCL_CRM_GENIL_SAMPLE_COMP" in class viewer. We will look at how the implementation has beendone. For sake of readability and maintainability, separate classes have been created for handling each ofthe objects. Theres one other reason which you will see at the end of this document. A base API class whichmanages the BOL buffer and does all the base API functions.

    "CL_CRM_GENIL_SAMPLE_COMP" -> Main GenIL handler class"CL_GENIL_SAMPLE_ORDER" -> Contains methods for manipulating Order object"CL_GENIL_SAMPLE_ITEM" -> Contains methods for manipulating item object"CL_GENIL_SAMPLE_PARTNER" -> Contains methods for manipulating partner object"CL_GENIL_SAMPLE_SHIPMENT" -> Contains methods for manipulating Shipment object

    "CL_CRM_GENIL_SAMPLE_API" -> Methods for low level API

    Except for the main GenIL class, you may find that all the other classes have only static methods andattributes. This is a must for the API class as it holds the BOL buffers (look at the attributes of this class), thatmust persist throughout the session. Theres also the coding convenience, the methods can be calleddirectly using the "=>" operator.

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    7/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 7

    BOL buffers(attributes) in the API classHEADER_TAB ---> Buffer for "Order" entityITEM_TAB ---> Buffer for "OrderItem" entitySHIPMENT_TAB--> Buffer for "OrderItemShipmentData" entityPARTNER_TAB---> Buffer for "Orderpartner" entity

    One important note is that in this sample model, no database tables are used. Look at the attributes of the classCL_CRM_GENIL_SAMPLE_API. All the attributes that end with _DB serve to simulate database tables. For demopurposes, initial values for these are filled using the method "DATA_BUILD", called in the CONSTRUCTORmethod. These initial entries are for simulating database entries. So, whatever operations have been done on thebuffer tables(*_DB), should be done on database tables instead.

    HEADER_TAB_DB ------> ZORDERITEM_TAB_DB---------> ZITEMSHIPMENT_TAB_DB-----> ZSHIPMENTPARTNER_TAB_DB------> ZPARTNER

    I will give a short explanation as to what each method does.

    IF_GENIL_APPL_MODEL~GET_MODEL

    Supplies information on relationship, cardinality between objects.

    IF_GENIL_APPL_MODEL~GET_OBJECT_PROPS

    Supplies information on individual BOL objects.

    Object_name Name of BOL objectObject_Kind - Whether this is a root object or access object, etc.,Key_struct - Key fields of the object

    Attr_struct - BOL attribute structureCreate_struct - Structure for creation of root objects

    Root_Object - The Header object of the BOL objectYou can also specify methods linked to BOL objects. These methods can be executed at runtime using

    CL_CRM_BOL_ENTITY->EXECUTE or EXECUTE2 depending on the parameters accepted by the method.

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    8/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 8

    IF_GENIL_APPL_MODEL~GET_DQUERY_ATTR_OPTIONS

    - Supplies dynamic search operators for each search field

    IF_GENIL_APPL_INTLAY~CHECK_OBJECTS_BEFORE_SAVE

    - Gets called by IF_BOL_TRANSACTION_CONTEXT~CHECK_SAVE_POSSIBLE. You can changethe success flag in the returning data to prevent a save.

    IF_GENIL_APPL_INTLAY~CREATE_OBJECTS

    -Called for creating root objects only.cl_crm_bol_entity_factory->create( )

    IF_GENIL_APPL_INTLAY~DELETE_OBJECTS

    -Called for deletion of root objects only.

    cl_crm_bol_entity->delete( )

    IF_GENIL_APPL_INTLAY~EXECUTE_OBJECT_METHOD

    -Handlers for the methods you specified in 'GET_OBJECT_PROPS'.

    IF_GENIL_APPL_INTLAY~EXECUTE_OBJECT_METHOD2

    -Handlers for the methods you specified in 'GET_OBJECT_PROPS'.

    IF_GENIL_APPL_INTLAY~GET_DYNAMIC_QUERY_RESULT

    -Process advanced search queries

    IF_GENIL_APPL_INTLAY~GET_OBJECTS

    -Read attribute values of root and access objects. Dependent objects are read only if a relationshipis requested via cl_crm_bol_entity->get_related_entity( ).

    IF_GENIL_APPL_INTLAY~GET_QUERY_RESULT

    -Simple query processing

    IF_GENIL_APPL_INTLAY~GET_ROOT_PATH

    Returns Keys of the root object for the passed BOL objects

    IF_GENIL_APPL_INTLAY~GET_TEXT

    Supplies text information, usually for page titles(OTR), etc.,

    IF_GENIL_APPL_INTLAY~GET_VIEW

    IF_GENIL_APPL_INTLAY~INIT_OBJECTS

    -Reset BOL buffer for the root objects.

    Called by IF_BOL_TRANSACTION_CONTEXT->REVERT()

    IF_GENIL_APPL_INTLAY~LOCK_OBJECTS

    -Database locks('ENQUEUE_*) for root objects.

    IF_GENIL_APPL_INTLAY~MODIFY_OBJECTS

    -Modify root object/relations.

    Note: When you modify attribute values of a root object, it is registered as a change in root object.When you create/delete/modify a related object, this registers as a delta change in that object and a change in root

    object. Processing is required depending on what object has been changed and what the delta change is.

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    9/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 9

    IF_GENIL_APPL_INTLAY~ON_AFTER_COMMIT

    -Something to do after a database commit. Usually release database locks...

    IF_GENIL_APPL_INTLAY~ON_AFTER_ROLLBACK

    -What to do in case of a roll back? Clear buffer entries related to rolled back root object...

    IF_GENIL_APPL_INTLAY~RESET

    -Reset whole BOL buffer. Called during CL_CRM_BOL_CORE->RESET( ).

    IF_GENIL_APPL_INTLAY~SAVE_OBJECTS

    -Save Root and dependent objects to database

    Making our Model known to the system

    Now, that we are done with the GenIL class implementation, we must make it known in the IMG.

    Launch transaction SPRO, go to IMG path "custom er re lat ionship management->crm cross-appl icat ioncom pon ents->generic interaction layer/object layer->basic sett ings". You have to create a componentfirst. Choose a name for your component in the Z or customer name space. Specify name andimplementation class here. Since we are supplying model and object details in our implementation class, youcan leave those fields empty. Save your entry. The screenshot highlights the sample Model.

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    10/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 10

    Next, create a Component Set. This corresponds to the Model which you see in the runtime repository of aBSP component. A component set is a place holder for components. You can include any existingcomponent into this component set. Again make sure that this is in the Z or customer name space. Now,include the desired components into the component set. Do test your models using the transactionsGENIL_MODEL_BROWSER and GENIL_BOL_BROWSER.

    When you initialize a component set using CL_CRM_BOL_CORE->STARTUP( ), all thecomponents will be loaded and be available in your environment

    Handling Non-Root objects in modelWhen creating a model, we can have non-root objects that do not have GUIDs(own or borrowed) as

    part of their key. For this kind of Model, the object handler class for root object must implement the interfacesIF_GENIL_SAMPLE_ABSTR and IF_GENIL_SAMPLE_ABSTR_ROOT or inherit from the classCL_CRM_GENIL_SAMPLE_ABSTR_ROOT. The rest of the object handler classes must implement theinterface IF_GENIL_SAMPLE_ABSTR or inherit from class CL_CRM_GENIL_SAMPLE_ABSTR.

    Look at the class CL_CRM_GENIL_SAMPLE_COMP_NEW and the other relevant classes to seehow the implementation has been done. If you are wondering why the Create method for shipment data hasbeen left empty, this is the reason. Have fun modeling!

  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    11/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 11

    Related Content

    Wiki - Creating Z-BOL for simple objects

    BOL/GENIL architecture for CRM IC Web Client

    Extending CRM core components to build enhanced IC Web Client business applications

    Extend BOL Model BT with custom table type relationship

    For more information, visit theCustomer Relationship Management homepage.

    http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6158http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6178http://wiki.sdn.sap.com/wiki/display/CRM/Extend+BOL+Model+BT+with+custom+table+type+relationshiphttps://www.sdn.sap.com/irj/sdn/bpx-crmhttps://www.sdn.sap.com/irj/sdn/bpx-crmhttps://www.sdn.sap.com/irj/sdn/bpx-crmhttps://www.sdn.sap.com/irj/sdn/bpx-crmhttp://wiki.sdn.sap.com/wiki/display/CRM/Extend+BOL+Model+BT+with+custom+table+type+relationshiphttp://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6178http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6158http://wiki.sdn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1
  • 7/22/2019 Custom GenIL BOL for Z-tables with Relationships.pdf

    12/12

    Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    Disclaimer and Liability Notice

    This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is notsupported 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 orcode sample, including any liability resulting from incompatibility between the content within this document and the materials andservices offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of thisdocument.