Quantcast
Channel: SCN : Blog List - SAP CRM: Webclient UI - Framework
Viewing all articles
Browse latest Browse all 195

Implementation of a Custom Genil Model to Create Component in Web UI

$
0
0

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

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

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 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.

   DATA ls_button TYPE crmt_thtmlb_button.
   REFRESH gt_buttons.

   ls_button-id       = 'Create'.                            "#EC NOTEXT
   ls_button-text     = 'Create'.
   ls_button-on_click = 'Create'.                            "#EC NOTEXT
   ls_button-enabled  = abap_true.
   ls_button-type     = cl_thtmlb_util=>gc_icon_create.
   APPEND ls_button TO gt_buttons.


   ls_button-id       = 'Save'.                            "#EC NOTEXT
   ls_button-text     = 'Save'.
   ls_button-on_click = 'Save'.                            "#EC NOTEXT
   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 laod that bol object and a component set , you can use this code in Do_init_context

so that initially when you run crm_ui , it will initailizes 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.
       lr_core = cl_crm_bol_core=>get_instance( ).
       lr_core->start_up( 'ZCUST' ).
     CATCH cx_crm_genil_general_error.
       EXIT.
   ENDTRY.
   lr_fac = lr_core->get_entity_factory( 'Customer' ).
   lt_params = lr_fac->get_parameter_table( ).
   TRY.
       lr_ent = lr_fac->create( lt_params ).
       IF lr_ent IS BOUND.
         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 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.
     lr_core = cl_crm_bol_core=>get_instance( ).
   CHECK lr_core IS BOUND.
   lr_core->modify( ).
   lr_customer  ?= me->typed_context->customer->collection_wrapper->get_current( ).

   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.

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

   CHECK lr_trans->check_save_needed( ) EQ abap_true.
   CHECK lr_trans->check_save_possible( ) EQ abap_true.
   lv_success = lr_trans->save( ).

   IF lv_success = 'X'.
     lr_trans->commit( ).

     IF sy-subrc = 0.
       lv_commit = 'X'.
     ENDIF.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         wait = 'X'.
   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.

 

 

 

 

Regards,

Sumeet Gehlot

SAP CRM Practice.



Viewing all articles
Browse latest Browse all 195

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>