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

Applies to:
SAP CRM 6.0. For more information, visit the Customer Relationship Management homepage.

A walkthrough, explaining the steps for creating a custom GenIL/BOL model for handling your Z-tables bound by relationships. Author: Arun Prakash Karuppanan

Company: Accenture Created on: 24 February 2010

Author Bio
Arun Prakash Karuppanan is an application developer in SAP-CRM. He is currently employed with Accenture Services Private Ltd.


SDN - | BPX - | BOC - | UAC - 1 Custom GenIL/BOL Model for Z-tables Bound by Relationships Table of Contents Introduction | BPX ............................................................. 6 Making our Model known to the system ... 12 SAP COMMUNITY NETWORK © 2010 SAP AG SDN ..............................................................sdn......................... 3 Identifying relationships and cardinality: | BOC ............................................................................................................................................................................................................. 11 Disclaimer and Liability Notice ............................... 5 Check table relationships: 3 Identifying Tables Needed: ........... 3 Creating the sample Model ................................................................................................. 3 Create tables: 5 Implementing the GenIL class: .............................................................................................................................................................................. 9 Handling Non-Root objects in model ........................... 5 Identifying BOL business objects: 2 10 Related Content | UAC ........................................

You probably know that each of the Model has its own implementation class aka GenIL handler class.0. This is what you see under "Model" in the runtime repository of the BSP component. In fact. ZPARTNER for storing Order Partners.Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships Introduction SAP has provided many "Models" to take care of all requirements under various business Reuse and enhancements are a pain. In case of single tables without relationships. identify the relationships between these tables. Meaning. Why not leverage on their expertise? You might have seen how wizards in the component workbench and BOL programming make developing user interfaces easy when using Model Identifying Tables Needed: In this model we have a header object "Order".. and Part A getting destroyed means that part B is also destroyed. you might get off easily. Now. there is a WIKI entry showing you how to create a model for simple objects (Wiki Entry).This is a strong association. You might also have to use the table data in some standard application screens. Campaign etc. So. C . Marketing.boc. Part A uses part B in it. You might have to develop user interfaces. but Part A getting destroyed does not necessarily mean that part B should be reusability of your code etc. Want to do it the better way? When it comes to taking care of business data while allowing the end user to play around with the interface. Part A uses part B in | UAC . ZITEM for storing Order Items. SAP knows its business and the architecture is a tried and tested one.Composition .sdn. Cardinality can be of four types.n Now. But how about a set of tables bound by relationships? In BSP | BPX . you have to worry about data consistency and integrity. A . we need four database 3 .1 B . For example. Meaning. you might have come across some requirements that require you to take care of some custom tables.Aggregation .uac. Do you want the same convenience and reusability? The solution is to create your own Model. I'm sure this needs no explanation. SAP COMMUNITY NETWORK © 2010 SAP AG SDN .. Once we get through that. This information can be found in the IMG path "customer relationship management->crm cross-application components->generic interaction layer/object layer->basic settings".com | BOC . I'm not going to create a model from scratch.An association is simply any sort of relationship between two tables. application performance.This is a weak "has a" relationship. I will provide you with a walkthrough based on the simplest model implementation sample available in the package 'CRM_GENIL_SAMPLE'. Creating the sample Model Creating a Model require you to understand some relational database concepts.bpx. a crude approach in this scenario is to use value nodes and call the maintenance logic directly in the getter-setter/event handlers directly.n C-1 D . For this walkthrough. Each Item has exactly one "Shipping Data" entry. ZORDER for storing Orders. we will look at how to create the implementation class. Identifying relationships and cardinality: Relationships can be of three types: A . B .Association . Performance(buffering) is crucial when you deal with tables with huge amount of transaction data. Each Order can have a single "Partner" entry and multiple "Item" entries. Sales.0. write the table maintenance logic etc. ZSHIPMENT for storing Item shipment data.1.

Each line in ZPARTNER table must refer to an entry in but000 table and not more than ZPARTNER----------------------->BUT000 1 BusinessPartnerRel 1 This is an association relationship as the operations on ZPARTNER table does not have any effect on the SAP COMMUNITY NETWORK © 2010 SAP AG SDN . our ZPARTNER table has a relationship with the standard master table but000. Let's give the relationship a name "OrderItemShipmentData". the cardinality is as follows. when creating You will see more of this below.sdn. Let's name the relationship "OrderItemRel" ZORDER------------------>ZITEM 1 OrderItemRel 0.n This is an aggregating relationship as the primary key of the ZITEM table is not part of any foreign key relationship with ZORDER table. Let's name this relationship "BusinessPartnerRel".com | BOC . ZITEM----------------------->ZSHIPMENT 1 OrderItemShipmentRel 1 This is a composite relationship as the primary key of the ZHIPMENT table is supplied by ZITEM. By our business rules. an entry in table ZORDER can have zero to multiple entries in table ZPARTNER referring to it through a foreign key.  Apart from these relationships. But each entry in table ZPARTNER must refer to one entry in table ZORDER and only one.. each item line must have exactly one shipment line. So the relation ship cardinality is ZORDER----------------------->ZPARTNER 1 OrderPartnerRel | UAC Each shipment line must refer to an item line and not more than one. Let's give this relationship a name "OrderPartnerRel". You will see more of this below. when creating tables.  ZITEM has a relationship with | BPX .com 4 . The cardinality is as follows.  The exact same rule applies for the relationship between the tables ZORDER and ZITEM. According to our business rule.n This is an aggregating relationship as the primary key of the ZPARTNER table is not part of any foreign key relationship with ZORDER table.boc..Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships  ZORDER has a relationship with ZPARTNER. So.

bpx.uac. you will face difficulties specifying primary keys and foreign key relationships. | BOC . we can proceed creating the tables with required fields and check table relations as follows. you may use the same type in BOL also.. The necessary fields are available in the structures shown below. create the same fields as found in the structure. the runtime structure types are different for some During runtime in the BOL layer. A BOL object may refer to a table line or query object or view object or query result object etc. HEADER_GUID type CRMT_GENIL_OBJECT_GUID. types: end of GTYPE_ITEM. The different kinds of business objects are specified below. not all fields of the table are required for manipulation. include type CRMT_GENIL_PARTNER_ATTR as ATTR. HEADER_GUID type CRMT_GENIL_OBJECT_GUID. create structures for accessing entity data in BOL at runtime (CL_CRM_BOL_ENTITY->CONTAINER_PROXY->DATA_REF). Once you have created the tables. Thus. A B C D E F G Root Object Access Object Dependent Object Search Object Search Result Object View Object Dynamic Search Object SAP COMMUNITY NETWORK © 2010 SAP AG SDN . For those tables. whose structure differs from the BOL runtime field structure.Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships Create tables: Now that we have identified the relationships. CRMT_GENIL_PARTNER_ATTR ZSHIPMENT Check table relationships: CRMT_GENIL_SHIPMENT_ATTR CRMT_GENIL_SHIPMENT_ATTR 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 | UAC include type CRMT_GENIL_ITEM_ATTR as BOL structure type CRMT_GENIL_ORDER_ATTR CRMT_GENIL_ORDER_ATTR ZPARTNER types: begin of GTYPE_PARTNER. the table fields and the fields available at runtime in BOL layer might be | BPX . Table ZORDER ZITEM Table Structure Type CRMT_GENIL_ORDER_ATTR types: begin of GTYPE_ITEM. I have specified the type in ABAP syntax. If this bothers you. Do not directly append these structures to the table. In the SAP sample. types: end of 5 . Otherwise.

that must persist throughout the session. This class should inherit the interfaces IF_GENIL_APPL_INTLAY and IF_GENIL_APPL_MODEL or directly inherit from the class CL_CRM_GENIL_ABSTR_COMPONENT. we would think that OrderItem is a dependent There‟s one other reason which you will see at the end of this document. Check out the Model “SAMPLE” in transaction „GENIL_MODEL_BROWSER‟. It's time you opened the class “CL_CRM_GENIL_SAMPLE_COMP" in class viewer. It depends on OrderItem object for meaningful existence. you use the Z or your customer name it's time to implement the GenIL class.  OrderPartner  OrderQuery  OrderItemQuery  AdvOrderHquery  AdvOrderQuery ->Dependent We will look at how the implementation has been done. you may find that all the other classes have only static methods and attributes.  OrderItemShipmentData ->Dependent object. whose attributes cannot be determined solely from the ID of this business object. the methods can be called directly using the "=>" operator. separate classes have been created for handling each of the objects. we have the following business objects. See access object below. "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 | BOC . This is to ensure that no conflict arises with standard BOL objects when various component sets are loaded in the user environment. Implementing the GenIL class: Now. The returned results may also directly correspond to root/access entities Dynamic Search Object: Advanced query Objects In our model.boc. only or together with the ID of the superior access 6 . but instead.Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships Root Object: This is a special access object.bpx. Dependent Object: A dependent object is a special type of business object. Search Object: These are query objects. It depends on Order object for meaningful existence.sdn.uac. that is at the top of the hierarchy.  Order -> Root object  OrderItem ->Access object. remember that the shipment line refers to the item line and not the order line. Access Object: This is an object that can be accessed independently. make sure that unlike in this example. So. This is a must for the API class as it holds the BOL buffers (look at the attributes of this class). It has an ID that can be used to determine both the attributes of the access object itself and those of its dependent objects. There‟s also the coding convenience. A base API class which manages the BOL buffer and does all the base API functions. SAP COMMUNITY NETWORK © 2010 SAP AG SDN .com | BPX . Search Result Object: These are query results. ideally. But. For sake of readability and maintainability. without requiring information from other objects. ->Search Object ->Search Object ->Dynamic Search Object ->Dynamic Search Objects Important Note: While giving names to your BOL objects. OrderItem must exist as an access object for the sake of shipment | UAC .

These methods can be executed at runtime using CL_CRM_BOL_ENTITY->EXECUTE or EXECUTE2 depending on the parameters accepted by the method. So.Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships BOL buffers(attributes) in the API class HEADER_TAB ---> Buffer for "Order" entity ITEM_TAB ---> Buffer for "OrderItem" entity SHIPMENT_TAB--> Buffer for "OrderItemShipmentData" entity PARTNER_TAB---> Buffer for "Orderpartner" entity One important note is that in this sample model. Key_struct .com | BOC .sap. etc. SAP COMMUNITY NETWORK © 2010 SAP AG SDN .sap. no database tables are used. For demo purposes. IF_GENIL_APPL_MODEL~GET_MODEL Supplies information on relationship.sdn. whatever operations have been done on the buffer tables(*_DB).com | UAC . initial values for these are filled using the method "DATA_BUILD".com 7 ..boc. called in the CONSTRUCTOR method.bpx.uac. All the attributes that end with _DB serve to simulate database tables. These initial entries are for simulating database entries. should be done on database tables instead. HEADER_TAB_DB ------> ZORDER ITEM_TAB_DB---------> ZITEM SHIPMENT_TAB_DB-----> ZSHIPMENT PARTNER_TAB_DB------> ZPARTNER I will give a short explanation as to what each method IF_GENIL_APPL_MODEL~GET_OBJECT_PROPS Supplies information on individual BOL objects.BOL attribute structure Create_struct .Structure for creation of root objects Root_Object . Object_name – Name of BOL object Object_Kind .The Header object of the BOL object You can also specify methods linked to BOL objects. Look at the attributes of the class | BPX .Whether this is a root object or access cardinality between objects.Key fields of the object Attr_struct .

etc.. cl_crm_bol_entity_factory->create( ) IF_GENIL_APPL_INTLAY~DELETE_OBJECTS -Called for deletion of root objects IF_GENIL_APPL_INTLAY~EXECUTE_OBJECT_METHOD2 -Handlers for the methods you specified in 'GET_OBJECT_PROPS'.boc.sdn. Processing is required depending on what object has been changed and what the delta change IF_GENIL_APPL_INTLAY~GET_VIEW IF_GENIL_APPL_INTLAY~INIT_OBJECTS -Reset BOL buffer for the root objects. IF_GENIL_APPL_INTLAY~MODIFY_OBJECTS -Modify root object/relations. SAP COMMUNITY NETWORK © 2010 SAP AG SDN . When you create/delete/modify a related 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 | BPX .Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships IF_GENIL_APPL_MODEL~GET_DQUERY_ATTR_OPTIONS .bpx.uac. IF_GENIL_APPL_INTLAY~CREATE_OBJECTS -Called for creating root objects only. Dependent objects are read only if a relationship is requested via cl_crm_bol_entity->get_related_entity( ).Supplies dynamic search operators for each search field IF_GENIL_APPL_INTLAY~CHECK_OBJECTS_BEFORE_SAVE . You can change the success flag in the returning data to prevent a save. this registers as a delta change in that object and a change in root | BOC .Gets called by IF_BOL_TRANSACTION_CONTEXT~CHECK_SAVE_POSSIBLE. 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. Called by IF_BOL_TRANSACTION_CONTEXT->REVERT() IF_GENIL_APPL_INTLAY~LOCK_OBJECTS -Database locks('ENQUEUE_*) for root objects. Note: When you modify attribute values of a root object. usually for page titles(OTR). cl_crm_bol_entity->delete( ) IF_GENIL_APPL_INTLAY~EXECUTE_OBJECT_METHOD -Handlers for the methods you specified in 'GET_OBJECT_PROPS'.com 8 . it is registered as a change in root | UAC .

IF_GENIL_APPL_INTLAY~SAVE_OBJECTS -Save Root and dependent objects to database Making our Model known to the system you can leave those fields | BOC . SAP COMMUNITY NETWORK © 2010 SAP AG SDN . Called during CL_CRM_BOL_CORE->RESET( ).sap. Specify name and implementation class here.sdn. You have to create a component | UAC . we must make it known in the IMG. that we are done with the GenIL class implementation. go to IMG path "customer relationship management->crm cross-application components->generic interaction layer/object layer->basic settings".Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships IF_GENIL_APPL_INTLAY~ON_AFTER_COMMIT -Something to do after a database commit. Since we are supplying model and object details in our implementation class.. Usually release database 9 . Launch transaction SPRO.uac. Save your entry.boc. Choose a name for your component in the Z or customer name space. The screenshot highlights the sample Model. IF_GENIL_APPL_INTLAY~RESET -Reset whole BOL | BPX . 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..

sap. Do test your models using the transactions GENIL_MODEL_BROWSER and GENIL_BOL_BROWSER. This corresponds to the “Model” which you see in the runtime repository of a BSP component.boc. Again make sure that this is in the Z or customer name space. If you are wondering why the Create method for shipment data has been left empty. this is the reason. A component set is a place holder for components. The rest of the object handler classes must implement the interface IF_GENIL_SAMPLE_ABSTR or inherit from class CL_CRM_GENIL_SAMPLE_ABSTR.bpx. all the components will be loaded and be available in your environment Handling Non-Root objects in model When creating a model. Look at the class CL_CRM_GENIL_SAMPLE_COMP_NEW and the other relevant classes to see how the implementation has been | BOC .com | UAC . 10 .sap. the object handler class for root object must implement the interfaces IF_GENIL_SAMPLE_ABSTR and IF_GENIL_SAMPLE_ABSTR_ROOT or inherit from the class we can have non-root objects that do not have GUIDs(own or borrowed) as part of their key. Have fun modeling! SAP COMMUNITY NETWORK © 2010 SAP AG SDN .com | BPX . include the desired components into the component set.sdn.Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships You can include any existing component into this component set. create a Component Set. When you initialize a component set using CL_CRM_BOL_CORE->STARTUP( „<model_name>‟ ).uac. For this kind of Model. | BPX .Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships 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 the Customer Relationship Management | BOC SAP COMMUNITY NETWORK © 2010 SAP AG SDN .com | UAC .com 11 .

uac. SAP will not be held liable for any damages caused by using or misusing the information. including any liability resulting from incompatibility between the content within this document and the materials and services offered by or seek to hold. SAP responsible or liable with respect to the content of this You agree that you will not hold. Changes made based on this information are not supported and can be overwritten during an upgrade. and anyone using these methods does so at his/her own risk.Creating Custom GenIL/BOL Model for Z-tables Bound by Relationships 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. code or methods suggested in this | BPX .com | BOC . 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. SAP COMMUNITY NETWORK © 2010 SAP AG SDN .com | UAC .com 12 .