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

Creating a Custom Genil/Bol object Model

$
0
0

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 namly 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 2Registering 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.

 

pic1.png

 

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 .

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

Declare GT_CUSTOMER as a global attributes ZATTR_CUST_TAB ( Attribute 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.

   DATA : lv_guid TYPE crmt_object_guid.
   DATAlv_key TYPE zattr_cust_key.
   DATA : lv_success TYPE char1.

   fill_struct_from_nvp_tab( EXPORTING it_parameters = it_parameters
                             CHANGING  cs_parameter = lv_key ).

   CALL FUNCTION 'GUID_CREATE'
     IMPORTING
       ev_guid_16 = lv_guid.

   DATA : lv_count TYPE i VALUE 0.

   TYPES : BEGIN OF ty_cust,
          custno TYPE zcustno,
          END OF ty_cust.

   DATA :lit_cust TYPE TABLE OF ty_cust,
   wa TYPE ty_cust.
   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.

   CALL METHOD zcl_customer_api=>create_customer
     EXPORTING
       is_cust_key = lv_key
     IMPORTING
       rv_success  = lv_success.

   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.

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.

lv_data
-guid = is_cust_key-guid.
lv_data
-custno = is_cust_key-custno.

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.
"DATA lv_temp_att TYPE zbol_bp_master_attr.

lv_root
= iv_root_list->get_first( ).

lv_root
->get_key( IMPORTING es_key = lv_key ).

IF lv_root->check_attr_requested( ) = abap_true.

zcl_customer_api
=>get_customer( EXPORTING is_cust_key = lv_key
IMPORTING es_cust_attr = lv_cust_att ).

IF lv_cust_att IS NOT INITIAL.

lv_root
->set_attributes( lv_cust_att ).

lv_root
= iv_root_list->get_next( ).

ENDIF.
ENDIF.

 

 

METHOD GET_CUSTOMER.

  FIELD-SYMBOLS <data> LIKE LINE OF gt_customer.
*
IF is_cust_key IS NOT INITIAL.

READ TABLE gt_customer WITH KEY
guid
= is_cust_key-guid
custno
= is_cust_key-custno
ASSIGNING <data>.
ELSE.
IF sy-subrc <> 0.
RETURN.
ENDIF.
READ TABLE gt_customer WITH KEY new = 'C' ASSIGNING <data>.
ENDIF.
*
*
IF sy-subrc = 0.
**    IF <line>-new EQ 'C' OR <line>-new EQ 'M'.
MOVE-CORRESPONDING <data> TO es_cust_attr.
RETURN.
ENDIF.

ENDMETHOD.

 

 

 

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.

lv_root
= iv_root_list->get_first( ).

IF lv_root->get_delta_flag( ) IS NOT INITIAL.

CASE lv_root->get_name( ).
WHEN 'Customer'.
lv_props
= lv_root->get_attr_props_obj( ).

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

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~LOCK_OBJECTS

 

METHOD if_genil_appl_alternative_dsil~lock_objects.

DATA : lv_key  TYPE zattr_cust_key
.
FIELD-SYMBOLS <object> LIKE LINE OF ct_object_list.

IF iv_lock_mode = if_genil_appl_intlay=>lock_mode_exclusive.

LOOP AT ct_object_list ASSIGNING <object>.

IF <object>-object_name = '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_key ).
.
CATCH cx_crm_genil_general_error .
ENDTRY.

CALL METHOD zcl_customer_api=>buffer_customer
CHANGING
cs_attr
= lv_key.

IF lv_key IS INITIAL.
<object>
-success = 'X'.
ENDIF.

ENDIF.
ENDLOOP.
ENDIF.

ENDMETHOD.

 

 

METHOD buffer_customer.

DATA : ls_customer LIKE LINE OF gt_customer.

CALL FUNCTION 'ENQUEUE_EZMAST_CUST'
EXPORTING
mode_zmast_cust 
= 'E'
guid         
= cs_attr-guid
custno       
= cs_attr-custno

EXCEPTIONS
foreign_lock 
= 1
system_failure
= 2
OTHERS         = 3.
IF sy-subrc = 0.


SELECT * FROM zmast_cust INTO
CORRESPONDING
FIELDS OF TABLE gt_customer
WHERE guid = cs_attr-guid
AND  custno = cs_attr-custno.

IF sy-subrc IS NOT INITIAL.
" Key Do not exist in database
ls_customer
-guid = cs_attr-guid.
ls_customer
-custno = cs_attr-custno.
ls_customer
-new = 'C'.

APPEND ls_customer TO gt_customer.
ENDIF.
CLEAR cs_attr.
ELSE.

ENDIF.

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

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.

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(changing parameter) ZATTR_CUST_KEY.

 

 

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 'D'.
DELETE gt_customer WHERE
guid
= cs_key-guid AND
custno
= cs_key-custno.
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

 

 

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.

 

 

 

In my next blog '  http://scn.sap.com/community/crm/webclient-ui-framework/blog/2012/09/25/implementation-of-a-custom-genil-model-in-web-ui ' will use this Custom GenIL component set to create a New custom component with create and save the data

in database

 


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>