0% found this document useful (0 votes)
212 views

2.0 - Creating A Custom GenilBol Object Model

The document discusses steps to define and implement a custom GenIL model in SAP CRM. It involves creating a GenIL class that inherits from the base GenIL component class. The class implements methods to create, retrieve, and modify customer objects using a custom API class and database table. The model is registered using transaction codes and can then be used to manage customer data dynamically in the SAP CRM web client.

Uploaded by

Diego
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views

2.0 - Creating A Custom GenilBol Object Model

The document discusses steps to define and implement a custom GenIL model in SAP CRM. It involves creating a GenIL class that inherits from the base GenIL component class. The class implements methods to create, retrieve, and modify customer objects using a custom API class and database table. The model is registered using transaction codes and can then be used to manage customer data dynamically in the SAP CRM web client.

Uploaded by

Diego
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Criando um GenIL BOL “Z” e implementando em um componente também “Z”.

Referências:

1- STEP 01 - Creating GenIL Bol


http://scn.sap.com/community/crm/webclient-ui-framework/blog/2012/08/06/
creating-a-genilbol-object-model

2- STEP 02 - Implementation of a Custom GenIL Model to Create Component in Web UI


http://scn.sap.com/community/crm/webclient-ui-framework/blog/2012/09/25/
implementation-of-a-custom-genil-model-in-web-ui

3- Outros Links de apoio


https://wiki.scn.sap.com/wiki/display/CRM/Create+a+Z+BOL+Object+Part+1

https://wiki.scn.sap.com/wiki/display/CRM/
Extend+BOL+Model+BT+with+custom+table+type+relationship?
original_fqdn=wiki.sdn.sap.com

http://saptechnical.com/Tutorials/CRM/WEBUI/Index.htm

https://archive.sap.com/discussions/thread/3353104

http://blog.acorel.nl/2013/07/adding-custom-assignment-block-on-sap.html

https://wiki.scn.sap.com/wiki/display/CRM/CRM+Web+Client+UI+Framework?
original_fqdn=wiki.sdn.sap.com

4- asas

STEP 01 - Defining and Creating a Genil Model :

You could define and implement dynamic models using IF_GENIL_APPL_MODEL


Interface.

Use GENIL_MODEL_EDITOR or GENIL_MODEL_BROWSER  to create static models,


As Genil component class extends default implementation of
IF_GENIL_APPLMODEL_PERSISTENCY namely
CL_WCF_GENIL_ABSTR_COMPONENT.

Step 1 : Go to Transaction SE24 or SE80, Create a new abap Custom Genil Class

              ZCL_CUSTOMER_MODEL

As this class use statically defined model we inherit from


CL_WCF_GENIL_ABSTR_COMPONENT.
     

Save and activate  the class.

Step 2:  Registering of Genil  component is done using Transaction SM34  ,

Enter View Cluster name as CRMVC_GIL_APPDEF or we can use maintaince view


CRMV_GIL_COMP

Click maintain button.

    

Maintain the entries for Component Definition, Component Set Definition and
Component Assignment.
    

       

      

Step 3: Create a new Master Table name as ZMAST_CUST using transaction


SE11.
      

Creating a Genil Business Objects.

Key Structure of Customer Data.

     

Attribute structure of a Customer Data


       

Table Type of Attribute Structure.

     
     

Create a Lock object of master table ZMAST_CUST.

      

Step 4 :  Go to Transaction GENIL_MODEL_BROWSER,

Give component name as ZCUST .

a. a.) Click on Change button and Right Click on Root Objects -> Give Object
Name as Customer
      

Add Key Structure Name , Attribute structure name and Create structure name .

And check web service enabled.

Keep Attribute Structure Property -in Changeable mode , So that while creating a
object you can see a list of fields in Change mode in Object Browser .
Step 5 :  Open a custom genil class ZCL_CUSTOMER_MODEL and redefine all this
metohods as shown below.

Create a new custom class  name as ZCL_CUSTOMER_API which will  to hold the
API methods to retrieve data from database.

ZATTR_CUST_TAB ( Attribute
Declare GT_CUSTOMER as a global attributes
Structure of Customer ) of ZCL_CUSTOMER_API
    

Here’s the coding Starts to create a new root object

IF_GENIL_APPL_INTLAY~CREATE_OBJECTS

METHOD if_genil_appl_intlay~create_objects.

   TYPES : BEGIN OF ty_cust,


              custno TYPE zcustno,
              END OF ty_cust.

   DATA : lv_guid    TYPE crmt_object_guid.


   DATA : lv_key     TYPE zattr_cust_key.
   DATA : lv_success TYPE char1.
   DATA : lit_cust   TYPE TABLE OF ty_cust.
   DATA : wa         TYPE ty_cust.
   DATA : lv_count   TYPE i VALUE 0.

* Fill structure based on Name Value Pairs Table.

   fill_struct_from_nvp_tab( EXPORTING it_parameters = it_parameters


                             CHANGING  cs_parameter = lv_key ).

* Creating a Guid.
   CALL FUNCTION ‘GUID_CREATE’
     IMPORTING
       ev_guid_16 = lv_guid.

* Custom Logic to create a New Customer Number.

   SELECT custno FROM zmast_cust INTO TABLE lit_cust.

   SORT lit_cust DESCENDING.

   IF lit_cust IS NOT INITIAL.


     LOOP AT lit_cust INTO wa.
       lv_count = wa–custno + 1.
       EXIT.
     ENDLOOP.
   ELSE.
     lv_count = 1.
   ENDIF.

   lv_key–guid   = lv_guid.
   lv_key–custno = lv_count.

* API Class fills the the global attribute.

   CALL METHOD zcl_customer_api=>create_customer


     EXPORTING
       is_cust_key = lv_key
     IMPORTING
       rv_success  = lv_success.

* Add the object to Data Container – Root Object List Interface

   IF lv_success IS NOT INITIAL.

     iv_root_list->add_object( iv_object_name = iv_object_name


                                is_object_key = lv_key ).
   ENDIF.

ENDMETHOD.

METHOD CREATE_CUSTOMER.

   DATA : lv_data like line OF gt_customer.

*  First step is to Lock a Customer.

   CALL FUNCTION ‘ENQUEUE_EZMAST_CUST’


     EXPORTING
       mode_zmast_cust = ‘E’
         EXCEPTIONS
       foreign_lock    = 1
       system_failure  = 2
       OTHERS          = 3.
   IF sy–subrc <> 0.
* Implement suitable error handling here
   ENDIF.

* Writing to Buffer values passed by parameters and setting Flag C.

   lv_data–guid = is_cust_key–guid.
   lv_data–custno = is_cust_key–custno.
   lv_data–new = ‘C’.

append lv_data to gt_customer.

rv_success = ‘X’.

ENDMETHOD.

IF_GENIL_APPL_INTLAY~GET_OBJECTS.

METHOD if_genil_appl_intlay~get_objects.

   DATA lv_root        TYPE REF TO if_genil_cont_root_object.


   DATA lv_key         TYPE zattr_cust_key.
   DATA lv_cust_att  TYPE zattr_cust.

* Get the first object of data container.

   lv_root = iv_root_list->get_first( ).

   lv_root->get_key( IMPORTING es_key = lv_key ).

* Check if attributes are read after Create

   IF lv_root->check_attr_requested( ) = abap_true.

* Custom API class to get the customer attributes.

     zcl_customer_api=>get_customer( EXPORTING is_cust_key = lv_key


                                                    IMPORTING es_cust_attr = lv_cust_att ).

* Return the objects only if it exists


     IF lv_cust_att IS NOT INITIAL.

* Set the attributes in container


       lv_root->set_attributes( lv_cust_att ).

* Get the next object of data container.


       lv_root = iv_root_list->get_next( ).

     ENDIF.
   ENDIF.

ENDMETHOD.

METHOD get_customer.

   FIELD-SYMBOLS <data> LIKE LINE OF gt_customer.


*
   IF is_cust_key IS NOT INITIAL.

* Try to read from Buffer.


     READ TABLE gt_customer WITH KEY
                guid = is_cust_key–guid
                custno = is_cust_key–custno
                ASSIGNING <data>.
   ELSE.
     READ TABLE gt_customer WITH KEY new = ‘C’ ASSIGNING <data>.

     IF sy–subrc <> 0.


       RETURN.
     ENDIF.
   ENDIF.

   IF sy–subrc = 0.
     IF <data>–new EQ ‘C’ OR <data>–new EQ ‘M’.
       MOVE-CORRESPONDING <data> TO es_cust_attr.
       RETURN.
     ENDIF.
   ENDIF.

ENDMETHOD.

IF_GENIL_APPL_INTLAY~MODIFY_OBJECTS

METHOD if_genil_appl_intlay~modify_objects.

   DATA : lv_cust_attr TYPE zattr_cust,


          lv_root      TYPE REF TO if_genil_container_object,
          lv_changed_objects TYPE  crmt_genil_obj_instance,
          lv_props     TYPE REF TO if_genil_obj_attr_properties,
          lt_changed_attr TYPE  crmt_attr_name_tab,
          lv_cust_key  TYPE zattr_cust_key,
          lv_success   TYPE abap_bool.

   DATA : lv_change TYPE crmt_genil_attr_property.

   CHECK iv_root_list IS BOUND.

* Get the first object from Container.

   lv_root = iv_root_list->get_first( ).

   IF lv_root->get_delta_flag( ) IS NOT INITIAL.

* Get name of the object.

     CASE lv_root->get_name( ).

       WHEN ‘Customer’.

* Returns an Property Object for Object Attributes.

         lv_props = lv_root->get_attr_props_obj( ).

* Returns a Table of All Names with Specified Property.

         CALL METHOD lv_props->get_name_tab_4_property


           EXPORTING
             iv_property = if_genil_obj_attr_properties=>modified
           IMPORTING
             et_names    = lt_changed_attr.

         lv_root->get_key( IMPORTING es_key = lv_cust_key ).


         lv_root->get_attributes( IMPORTING es_attributes = lv_cust_attr ).

         MOVE-CORRESPONDING lv_cust_key TO lv_cust_attr.

         CALL METHOD zcl_customer_api=>change_customer


           EXPORTING
             is_cust_attr = lv_cust_attr
             it_names     = lt_changed_attr
           IMPORTING
             rv_success   = lv_success.

         IF lv_success IS NOT INITIAL.


           lv_changed_objects–object_name = ‘Customer’.
           lv_changed_objects–object_id =
cl_crm_genil_container_tools=>build_object_id( lv_cust_key ).

*    Add into Object Table with Object Type and ID.

           APPEND lv_changed_objects TO et_changed_objects.

         ENDIF.

       WHEN OTHERS.


     ENDCASE.
   ENDIF.

ENDMETHOD.

METHOD change_customer.

   FIELD-SYMBOLS : <line> TYPE zattr_cust,


                           <old>  TYPE simple,
                           <new>  TYPE simple,
                           <name> TYPE name_komp.

   READ TABLE gt_customer WITH KEY


              guid = is_cust_attr–guid
              custno = is_cust_attr–custno ASSIGNING <line> .

   CHECK sy–subrc IS INITIAL.

   LOOP AT it_names ASSIGNING <name>.


     ASSIGN COMPONENT <name> OF STRUCTURE <line> TO <old>.
     CHECK sy–subrc = 0.
     ASSIGN COMPONENT <name> OF STRUCTURE is_cust_attr TO <new>.

     CHECK sy–subrc = 0.


     <old> = <new>.
   ENDLOOP.
   <line>–new = ‘M’.
   rv_success =‘X’.
ENDMETHOD.

IF_GENIL_APPL_ALTERNATIVE_DSIL~SAVE_OBJECTS

METHOD if_genil_appl_alternative_dsil~save_objects.

   DATA lv_cust_key TYPE zattr_cust_key.

   FIELD-SYMBOLS <object> TYPE crmt_genil_obj_inst_line.

   LOOP AT ct_object_list ASSIGNING <object>.

* Check for Object Instance.

     CASE <object>–object_name.


       WHEN ‘Customer’.
         TRY.
             CALL METHOD cl_crm_genil_container_tools=>get_key_from_object_id(
               EXPORTING
                 iv_object_name = <object>–object_name
                 iv_object_id   = <object>–object_id
               IMPORTING
                 es_key         = lv_cust_key ).
             .
           CATCH cx_crm_genil_general_error .
         ENDTRY.

* Custom API to Save the customer data.

         CALL METHOD zcl_customer_api=>save_customer


           CHANGING
             cs_key = lv_cust_key.
         IF lv_cust_key IS INITIAL.
           <object>–success = abap_true.
         ENDIF.
     ENDCASE.
   ENDLOOP.

ENDMETHOD.

Define CS_KEY TYPE ZATTR_CUST_KEY as parameter of Save


Customer.

METHOD SAVE_CUSTOMER.

   DATA : wa_cust TYPE zmast_cust.


   DATA : lv_success TYPE abap_bool.
   FIELD-SYMBOLS: <customer_attr_n> LIKE LINE OF gt_customer.

   lv_success = ‘X’.

   READ TABLE gt_customer ASSIGNING <customer_attr_n> WITH


              KEY guid = cs_key–guid
                  custno = cs_key–custno.

   CHECK sy–subrc = 0.

   CASE <customer_attr_n>–new.
     WHEN ‘C’ OR ‘M’.
       MOVE-CORRESPONDING <customer_attr_n> TO wa_cust.
       MODIFY zmast_cust FROM wa_cust.

     WHEN OTHERS.


   ENDCASE.

   CALL FUNCTION ‘DEQUEUE_EZMAST_CUST’


     EXPORTING
       mode_zmast_cust = ‘E’
       guid            = cs_key–guid
       custno          = cs_key–custno.

   CLEAR cs_key.

ENDMETHOD.                    “SAVECUSTOMER

Coding Part is Done to create genil implementation class.

STEP 6 : go to transaction genil_bol_browser -> Click on Create a New Root


Object

Select the root object as Customer double click it.

Enter the parameters value  Custno  –

you can add you own custom logic to default set the value of the attributes

Click on Create Object


    

Here Guid and Custno is in display mode , while remaining atrributes are in
changeable mode – Enter the values of the Attributes.

Click on Save Button.

      
and Check the database table ZMAST_CUST.

    

STEP 02 - Implementation of a Custom Genil Model to Create


Component in Web UI:

I created a custom GenIL object model to create and save bol


objects. In this blog I am going to use that custom GenIL component
to create and save the data in database.

1.> Open a Transaction BSP_WD_CMPWB .

2.> Enter Component name as ZCUST_CMP and click on create

3.> Right Click on Model -> Add Model


4.>  Add Component Set name as  ZCSET_CUST which you had
created while creating Genil Model.

5.>  You can see the Component Structure Browser , expanding


Model will show your

      Root Object Customer , Key Structure , Attribute Structure. 


6.> Create a Custom Controller named as ZCuCo so that later on you
can navigate or pass the data between views.
 

7.>  Add Customer as a Model Node and a BOL entity -> Click on
Next till Complete.

8.>  Double click on custom controller , you can see list of attributes
of a context node you added.

9.>  Right Click on View and Create Over View Page name as
OverViewPage .

10.>  Create a New View using Create -> Define Name as


CreateCustomer.

11.> Add Model Node and BOL entity as Customer and Bind it with
Custom Controller.
12.> Select a View Type form View as required and Click on
Complete.
13.> Click on Configuration Tab and Add the Available fields.

14.>  Here you can change the field Properties using Hold down
ALT+Field.
15.>  Next Step is assignment of View to OverViewPage.
16.>  then Assign OverViewPage to Windows

17.>   Next Step is about to add View to Display assignment blocks of


OverViewPage.

18.> Click on Test Button.

19.> Here the fields are not bounded , to achieve this  a custom bol
objects and created a custom genil class,

then first you have to laod that bol object and a component set , you can use this
code in Do_init_context method

so that initially when you run crm_ui , it will initailizes the  component set and bol
objects.

Instead of Initialization in Do_init_context , Lets create a button


Create (to Load bol Objects) and

and Save to update in database (ZMast_Cust).

20.> Declare a global attribute GT_BUTTONS in a implementation


class.
21.> Click on Page Attributes and add the following code for BSP
Page.

     <%@page language=”abap” %>

     <%@extension name=”chtmlb” prefix=”chtmlb” %>

     <%@extension name=”thtmlb” prefix=”thtmlb” %>


     <%@extension name=”uhtmlb” prefix=”uhtmlb” %>
     <%
      DATA lv_xml TYPE string.
      lv_xml = controller->configuration_descr->get_config_data( ). 
%>
      <chtmlb:config xml  = “<%= lv_xml %>”
      mode = “RUNTIME” />
      <uhtmlb:toolbar id              = “Toolbar”
       buttons         = “<%= controller->gt_buttons %>”
       maxButtonNumber = “3” />

22.> Redefine Do_init_context method and add the code to trigger


events on button.

DATA : lr_entity TYPE REF TO cl_crm_bol_entity,


          lv_collection TYPE REF TO if_bol_bo_col.

* Define Buttons

   DATA ls_button TYPE crmt_thtmlb_button.


   REFRESH gt_buttons.

   ls_button–id       = ‘Create’.                          
   ls_button–text     = ‘Create’.
   ls_button–on_click = ‘Create’.                         
   ls_button–enabled  = abap_true.
   ls_button–type     = cl_thtmlb_util=>gc_icon_create.
   APPEND ls_button TO gt_buttons.
   ls_button–id       = ‘Save’.                           
   ls_button–text     = ‘Save’.
   ls_button–on_click = ‘Save’.                        

   ls_button–enabled  = abap_true.
   ls_button–type     = cl_thtmlb_util=>gc_icon_save.
   APPEND ls_button TO gt_buttons.

ENDMETHOD.

23.> Here the fields are not bounded ,to achieve this  a custom bol
objects and created a

custom genil class, then first you have to load that bol object and a component
set , you

can also use this code in Do_init_context so that initially when you run crm_ui , it
will initializes

the component set and bol objects.

METHOD eh_oncreate.

   DATA : lr_entity       TYPE REF TO cl_crm_bol_entity, 

             lv_collection  TYPE REF TO if_bol_bo_col.

                                     
   DATA : lr_core        TYPE REF TO cl_crm_bol_core,
             lr_fac          TYPE REF TO cl_crm_bol_entity_factory,
             lt_params     TYPE        crmt_name_value_pair_tab,
             ls_params     TYPE        crmt_name_value_pair,
             lr_ent          TYPE REF TO cl_crm_bol_entity.

   TRY.

* Try to Get the instance of Root Object Customer

       lr_core = cl_crm_bol_core=>get_instance( ).


       lr_core->start_up( ‘ZCUST’ ).
     CATCH cx_crm_genil_general_error.
       EXIT.
   ENDTRY.

* Get Entity factory of Customer


        lr_fac = lr_core->get_entity_factory( ‘Customer’ ).
        lt_params = lr_fac->get_parameter_table( ).    
           TRY.

* Create table structure


           lr_ent = lr_fac->create( lt_params ).
           IF lr_ent IS BOUND.

* Add Parameters
             me->typed_context->customer->collection_wrapper->add(
iv_entity = lr_ent ).
             CHECK lr_ent->lock( ) = abap_true.
           ENDIF.
   CATCH cx_crm_genil_model_error.
   EXIT.
   CATCH cx_sy_ref_is_initial.
   ENDTRY.
 
ENDMETHOD.

24.> Method to save data into database using Save button.

METHOD eh_onsave.

   DATA : lr_customer       TYPE REF TO cl_crm_bol_entity,


             lr_core              TYPE REF TO cl_crm_bol_core,
             lr_trans             TYPE REF TO if_bol_transaction_context,
             lv_success           TYPE abap_bool,
             lv_commit            TYPE char1,
             ls_customer           TYPE zattr_cust,
             lr_msg_service       TYPE REF TO cl_bsp_wd_message_service.

   DATA : lv_custno TYPE zcustno.

* Get the root object Instance


          lr_core = cl_crm_bol_core=>get_instance( ).
       CHECK lr_core IS BOUND.
       lr_core->modify( ).

*  Get the data of  the current instance.

   lr_customer  ?= me->typed_context->customer-
>collection_wrapper->get_current( ).

*  Get the Customer Number using get property as value


   CALL METHOD lr_customer-
>if_bol_bo_property_access~get_property_as_value
     EXPORTING
       iv_attr_name = ‘CUSTNO’
     IMPORTING
       ev_result    = lv_custno.

   ls_customer–custno = lv_custno.

   CHECK lr_customer IS BOUND.

   CALL METHOD lr_customer-


>if_bol_bo_property_access~get_properties
     IMPORTING
       es_attributes = ls_customer.

* Get Transaction of the current entity.

   lr_trans ?= lr_customer->get_transaction( ).
   CHECK lr_trans IS BOUND.
   CHECK lr_trans->check_save_possible( ) EQ abap_true.

   lv_success = lr_trans->save( ).

   IF lv_success = ‘X’.
     lr_trans->commit( ).
   ELSE.
     lr_trans->rollback( ).
   ENDIF.
ENDMETHOD.

25.> Open UI and Test the component -> Click on Create then Enter
the details

       -> Click on Save.


26.> Check The Entry in a Database Table.

You might also like