You are on page 1of 14

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

Applies to: SAP CRM 7.0. For more information, visit the Customer Relationship Management homepage. Summary A summary of creating Custom Genil/Bol components for Z-tables with relationship. We have extended the blog from this SDN Blog. http://wiki.sdn.sap.com/wiki/display/CRM/Extend+BOL+Model+BT+with+custom+table+type+relations hip Authors : Dhananjay Raskar and Kavindra Joshi Company: Fujitsu Consulting Created on: 14 September 2010 Authors Bio Dhananjay & Kavindra are SAP CRM consultant at Fujitsu Consulting India.

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

Table of Contents
Defining the Object Table Defining the Model Table Defining the Component Set/Component Defining the Zstructures and Ztables Order Table Order Structure Item Table Item Structure Shipment Table Shipment Structure

Creating your ZGenil Class , ZAPI class , Zorder class , ZItem Class , ZShipment class

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


1) Defining the Object Table

Dont change the name of the Objects as defined in the document. If you change the names of the objects, do change the same in the code of the classes that you would implement to fetch respective objects. Also if you have defined Ztables, then also define your Zstructures and use your custom classes to get the data for Orders , Items , Partners & Shipments. 2) Defining the Model Table

Dont change the name of the relations. If you want to change the name of the relationship , then do update the coding in your respective classes. 3)Defining the Component Set/Component Customizing Settings for defining Custom GENIL Object Use SPRO Tcode.

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

Select Customer Relationship Management

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


Select Generic Interaction Layer/Object layer

Execute Basic settings

Click on Ok Define Comp Name, Class Name Object Table Name and Model Table Name

Double Click on Component Set Definition

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

Define Comp Set for your Compo. Select Compo Set and double click on Component assignment

4) Defining the Zstructures and Ztables

Order Table

Order Table 1

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


Order Structure

Item Table

Item Structure

Shipment Table

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

Shipment Structure

5) Creating your ZGenil Class , ZAPI class , Zorder class , ZItem Class , ZShipment class Create a GENIL Class for the component. In my case I created ZKAVINDRA_GENIL_DEMO. As already explained , the GENIL class has to be inherited from CL_CRM_GENIL_ABSTR_COMPONENT.( I did the basic things so that I can have data in my Ztable.If you need to need to implement a full blooded scenario you need to implement all the methods of the interface as they would be needed by different operations) On the lines of these standard classes, Z classes needs to be Implemented for the following classes. "CL_CRM_GENIL_SAMPLE_COMP" -> Main GenIL handler class Above class must Implement IF_GENIL_APPL_INTLAY and IF_GENIL_APPL_MODEL or directly inherit from the class CL_CRM_GENIL_ABSTR_COMPONENT. Make sure that instead of calling the standard classes you are calling the Z classes for Order, Item, Partner and Shipment.

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


Update the method signatures and adjust the variables in the code, so that they point to Z structures of the respective entities for all the classes mentioned. "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 Following changes should be made to this class. Adjust the class constructor so that DATA_BUILD method is not called (Comment the code where it is called). Adjust the types with you Z Structures as shown below. TYPES : gtype_header_tab TYPE HASHED TABLE OF zdorder_struct WITH UNIQUE KEY g uid. TYPES : BEGIN OF gtype_item, header_guid TYPE crmt_genil_object_guid. INCLUDE TYPE zditem_kav AS attr. TYPES : END OF gtype_item. TYPES : gtype_item_tab TYPE SORTED TABLE OF gtype_item WITH UNIQUE KEY header _guid guid. TYPES : gtype_shipment_tab TYPE HASHED TABLE OF zdshipment_struct WITH UNIQUE KEY guid. " crmt_genil_shipment_attr WITH UNIQUE KEY guid. TYPES : BEGIN OF gtype_partner, header_guid TYPE crmt_genil_object_guid. INCLUDE TYPE ZDPARTNER_KAV_1 AS attr. " crmt_genil_partner_attr AS attr. TYPES : END OF gtype_partner, gtype_partner_tab TYPE SORTED TABLE OF gtype_partner WITH UNIQUE KEY header _guid dnumber function. In the DATA_LOAD method load data from you respective DB tables to you Class IT. In the DATA_PERSIST Method implement logic to save data to the respective DB tables.

Implement the following methods for the class ZCL_CRM_GENIL_SAMPLE_COMP (Your GENIL class ) a) METHOD if_genil_appl_model~get_model. *CALL METHOD SUPER->IF_GENIL_APPL_MODEL~GET_MODEL * RECEIVING * RT_RELATION_DET = * . SELECT * FROM zdcrms_gil_model INTO CORRESPONDING FIELDS OF TABLE rt_relation_det.

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

ENDMETHOD. b) METHOD if_genil_appl_model~get_object_props. *CALL METHOD SUPER->IF_GENIL_APPL_MODEL~GET_OBJECT_PROPS * RECEIVING * RT_OBJ_PROPS = * . DATA: ls_method TYPE crmt_genil_obj_method_def. FIELD-SYMBOLS: <line> TYPE crmt_obj_properties. SELECT * FROM zdcrms_gil_sobj INTO CORRESPONDING FIELDS OF TABLE rt_obj_pro ps. * insert methods READ TABLE rt_obj_props WITH KEY object_name = 'Order' ASSIGNING <line>. "#EC NO TEXT IF sy-subrc = 0. ls_method-method_name = 'createFollowUp'. "#EC NOTEXT ls_method-param_struct = ''. ls_method-return_type = 'Order'. "#EC NOTEXT APPEND ls_method TO <line>-methods. ls_method-method_name = 'renumberItems'. "#EC NOTEXT ls_method-param_struct = 'CRMT_GENIL_ITEM_RENUM_PARAM'. ls_method-return_type = 'OrderItem'. "#EC NOTEXT APPEND ls_method TO <line>-methods. ls_method-method_name = 'repeatInput'. "#EC NOTEXT ls_method-param_struct = 'BAPITLINE'. ls_method-return_type = 'TDLINE'. "#EC NOTEXT APPEND ls_method TO <line>-methods. ENDIF. ENDMETHOD. c) METHOD if_genil_appl_intlay~create_objects. *CALL METHOD SUPER->IF_GENIL_APPL_INTLAY~CREATE_OBJECTS * EXPORTING * IV_OBJECT_NAME = ** iv_number =1 * IT_PARAMETERS = * IV_ROOT_LIST = * . DATA: ls_parameters TYPE crmt_genil_order_create, lt_request_obj TYPE crmt_request_obj_tab.

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


FIELD-SYMBOLS: <line> TYPE crmt_name_value_pair, <value> TYPE data. * Here we create root objects. Since we have only one root object in * our example we would * not have to branch. However this should be a generic example! CASE iv_object_name. WHEN 'Order'. "#EC NOTEXT * fill parameter structure from name value pair table CALL METHOD fill_struct_from_nvp_tab EXPORTING it_parameters = it_parameters CHANGING cs_parameter = ls_parameters. * deligate zdcl_genil_sample_order=>create( iv_number = iv_number is_parameters = ls_parameters iv_root_list = iv_root_list ). * read the attributes me->if_genil_appl_intlay~get_objects( it_request_objects = lt_request_obj iv_root_list = iv_root_list ). ENDCASE. ENDMETHOD. d) METHOD if_genil_appl_intlay~get_objects. **TRY. *CALL METHOD SUPER->IF_GENIL_APPL_INTLAY~GET_OBJECTS * EXPORTING * IT_REQUEST_OBJECTS = * IV_ROOT_LIST = * . **ENDTRY. DATA: lv_object TYPE REF TO if_genil_container_object, lv_name TYPE crmt_ext_obj_name. * all entries in the root list have the same type/name -> take first lv_object = iv_root_list->get_first( ). * make sure we got an entry. CHECK lv_object IS BOUND.

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


* Note: the object from the root list must be either a root or access object. * Dependent objects will never be part of the root list. lv_name = lv_object->get_name( ). CASE lv_name. * in our example we can expect the root object 'Order' and the access object 'OrderItem'. WHEN 'Order'. "#EC NOTEXT zdcl_genil_sample_order=>read( it_request_objects = it_request_objects iv_root_list = iv_root_list ). WHEN 'OrderItem'. "#EC NOTEXT zdcl_genil_sample_item=>read( it_request_objects = it_request_objects iv_root_list = iv_root_list ). ENDCASE. ENDMETHOD. e) METHOD if_genil_appl_intlay~get_query_result. **TRY. *CALL METHOD SUPER->IF_GENIL_APPL_INTLAY~GET_QUERY_RESULT * EXPORTING * IV_QUERY_NAME = * IT_PARAMETERS = * IS_REQUEST_OBJECT = * IV_ROOT_LIST = * . **ENDTRY. DATA: lt_request_obj TYPE crmt_request_obj_tab, ls_parameters TYPE crmt_genil_order_search. * select the rigth query CASE iv_query_name. WHEN 'OrderQuery'. "#EC NOTEXT CALL METHOD fill_struct_from_nvp_tab EXPORTING it_parameters = it_parameters CHANGING cs_parameter = ls_parameters. CALL METHOD zdcl_genil_sample_order=>search EXPORTING is_parameters = ls_parameters is_request_object = is_request_object iv_root_list = iv_root_list. * Note: The request object restricts the attributes to read. * If their is no request object entry or the attributes table is empty

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


* * all attributes are requested! read the attributes and relation using the GET_OBJECTS method APPEND is_request_object TO lt_request_obj. me->if_genil_appl_intlay~get_objects( it_request_objects = lt_request_obj iv_root_list = iv_root_list ). WHEN 'OrderItemQuery'. CALL METHOD fill_struct_from_nvp_tab EXPORTING it_parameters = it_parameters CHANGING cs_parameter = ls_parameters. CALL METHOD zdcl_genil_sample_item=>search EXPORTING is_parameters = ls_parameters is_request_object = is_request_object iv_root_list = iv_root_list. * Note: The request object restricts the attributes to read. * If their is no request object entry or the attributes table is empty * all attributes are requested! * read the attributes and relation using the GET_OBJECTS method APPEND is_request_object TO lt_request_obj. me->if_genil_appl_intlay~get_objects( it_request_objects = lt_request_obj iv_root_list = iv_root_list ). WHEN 'OrderItemQuery2'. CALL METHOD fill_struct_from_nvp_tab EXPORTING it_parameters = it_parameters CHANGING cs_parameter = ls_parameters. CALL METHOD zdcl_genil_sample_item=>search2 EXPORTING is_parameters = ls_parameters is_request_object = is_request_object iv_root_list = iv_root_list. WHEN OTHERS. RETURN.

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


ENDCASE. ENDMETHOD. METHOD if_genil_appl_intlay~save_objects. *CALL METHOD SUPER->IF_GENIL_APPL_INTLAY~SAVE_OBJECTS * EXPORTING * IV_MSG_SERVICE_ACCESS = * CHANGING * CT_OBJECT_LIST = * . FIELD-SYMBOLS: <obj> TYPE crmt_obj_line. LOOP AT ct_object_list ASSIGNING <obj>. CASE <obj>-object_name. WHEN 'Order'. "#EC NOTEXT <obj>-success = zdcl_genil_sample_order=>save( <obj>-object_id ). ENDCASE. ENDLOOP. ENDMETHOD. These are some of the core methods that you would need for running basic scenarios such as order creation, order search etc..

f)

You might also like