Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Link to Content's target Space :

CRM Wiki

Applies to:

CRM 7.0

Summary

A summary of creating Custom Genil Bol components for Z-tables with relationship. We have extended the blog from this SDN Blog.Arun's Blog

Author(s):  

   
Company:     Fujitsu Consulting India 
Created on:    14 Nov 2011
Author(s) Bio
Dhananjay & Kavindra are SAP CRM consultant at Fujitsu Consulting India.

Table of Contents

Introduction

As Arun had explained in his blog Arun's Blog , the scenario comprehensively we are not going to discuss that. Here what we have attempted is to extend the scenario provided by him so that we use  custom Genil classes , order classes , item classes, shipment and API classes. Also we have designed our component such that data is now persisted in our own tables. The sample coding for Genil class has been provided so that it is ready reference for the beginners. The Order Classes, Item classes & Sample APIs classes could be done easily and how to do it has been explained in the document.

This blog would help out beginners to understand the Genil creation from a coding point of view. Also to run the scenario you would need basic understanding how to execute the scenario using GENIL_BOL_BROWSER. 

Steps to Follow 

Defining the Object Table

Don’t 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.

Object_Table.jpg

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.

Defining the  Model Table

Don’t 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.

Model_Table.jpg

Defining the Component Set & Component

Customizing Settings for defining Custom GENIL Object

Use SPRO->Customer Relationship Management->Generic Interaction Layer/Object layer->Basic settings.

Define Comp Name, Class Name Object Table Name and Model Table Name 

Double Click on Component Set Definition 

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

Defining the Zstructures and Ztables

Object_Table.jpg

Order_DDIC_Struct.jpg

Item_DDIC_Table.jpg

ITEM_DDIC_Struct.jpg

Shipment_DDIC_Table.jpg

Shipment_DDIC_Struct.jpg

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

Create a GENIL Class for the component. In my case I created ZCL_CRM_GENIL_SAMPLE_COMP. 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.

 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 the Z class created for CL_CRM_GENIL_SAMPLE_API .

  1. Adjust the class constructor so that DATA_BUILD method is not called (Comment the code where it is called).
  2. Adjust the types with you Z Structures as shown below.
  3. In the DATA_LOAD method load data from you respective DB tables to you Class IT.
  4. In the DATA_PERSIST Method implement logic to save data to the respective DB tables.

 
Code Changes 

This change should be made in the custom CL_CRM_GENIL_SAMPLE_API class.
TYPES : gtype_header_tab TYPE HASHED TABLE OF zdorder_struct WITH UNIQUKEY guid
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
TYPES : gtype_header_tab TYPE HASHED TABLE OF zdorder_struct WITH UNIQUE KEY guid.
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 U
NIQUE 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 att
r.
TYPES : END OF gtype_partner,
gtype_partner_tab TYPE SORTED TABLE OF gtype_partner WITH UNIQUE KE
Y header_guid dnumber function.
header_guid guid.
TYPES : gtype_shipment_tab TYPE HASHED TABLE OF zdshipment_struct WITH U
NIQUE 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 att
r.
TYPES : END OF gtype_partner,
gtype_partner_tab TYPE SORTED TABLE OF gtype_partner WITH UNIQUE KE
Y header_guid dnumber function.






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.
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.
Creating Custom Genil/BOL Model for Z-tables Bound by Relationships
SELECT * FROM zdcrms_gil_sobj INTO CORRESPONDING FIELDS OF TABLE rt
_obj_props.
* insert methods
READ TABLE rt_obj_props WITH KEY object_name = 'Order' ASSIGNING <line>. "
#EC NOTEXT
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.
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
Creating Custom Genil/BOL Model for Z-tables Bound by Relationships
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.
* 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
Creating Custom Genil/BOL Model for Z-tables Bound by Relationships
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
* 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
Creating Custom Genil/BOL Model for Z-tables Bound by Relationships
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.
ENDCASE.
ENDMETHOD.
f) 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 =
* .
Creating Custom Genil/BOL Model for Z-tables Bound by Relationships
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.











Related Content

Please include at least three references to SDN documents or web pages.

http://wiki.sdn.sap.com/wiki/display/CRM/Extend+BOL+Model+BT+with+custom+table+type+relations
hipArun's Blog
Reference 2
Reference 3

Useful Information

If you are new to CRM and looking for information on custom genil objects creation with relationships , this blog will provide a detailed explanation and code snippets to get started.