9
Implementation of a Custom Genil Model to Create Component in Web UI Created a custom GenIL object model to create and save BOL objects. 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

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

  • Upload
    ranjith

  • View
    216

  • Download
    2

Embed Size (px)

DESCRIPTION

qwdw

Citation preview

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

Implementation of a Custom Genil Model to Create

Component in Web UI inShare

Created a custom GenIL object model to create and save BOL objects. 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

Page 2: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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.

Page 3: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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.

Page 4: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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.

Page 5: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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,

Page 6: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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

inDo_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" />

Page 7: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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.

Page 8: Implementation of a Custom Genil Model to Create Component 1 in Web UI

* 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( ).

Page 9: Implementation of a Custom Genil Model to Create Component 1 in Web UI

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.