二维码

[其他] CRM 创建自定义的Genil/Bol object Model

Twilight发表于 2016-02-16 10:24Twilight 最后回复于 2016-02-16 10:24 [复制链接] 6291 0

使用接口:IF_GENIL_APPL_MODEL,创建动态模型。

1、SE24 创建类:ZCL_CUSTOMER_MODEL
Genil 1.jpg
添加继承类:CL_WCF_GENIL_ABSTR_COMPONENT,保存激活

2、SM34  注册Genil  component
Genil 2.jpg
输入CRMVC_GIL_APPDEF ,维护数据
Genil 3.jpg
定义 Component和 Component Set,然后将 Component分配到 Component Set中
Genil 4.jpg
Genil 5.jpg

3、se11 创建Table:ZMAST_CUST
Genil 6.jpg

4、创建Genil Business Objects相关对象
Genil 7.jpg
Key Structure of Customer Data

Genil 8.jpg
Attribute structure of a Customer Data

Genil 9.jpg
Genil 10.jpg
Table Type of Attribute Structure

5、创建表ZMAST_CUST锁
Genil 11.jpg

6、T-code:GENIL_MODEL_BROWSER,输入组件ZCUST
Genil 12.jpg

7、创建Root Objects:Customer


输入Key Structure Name , Attribute structure name and Create structure name
Genil 13.jpg

Genil 14.jpg
调整BOL对表字段的属性状态:可编辑

8、se24:ZCL_CUSTOMER_API
Genil 15.jpg

CREATE_CUSTOMER
Genil 16.jpg
  1. METHOD create_customer.

  2.   DATA : lv_data LIKE LINE OF gt_customer.

  3. *  First step is to Lock a Customer.

  4.   CALL FUNCTION 'ENQUEUE_EZMAST_CUST'
  5.     EXPORTING
  6.       mode_zmast_cust = 'E'
  7.     EXCEPTIONS
  8.       foreign_lock    = 1
  9.       system_failure  = 2
  10.       OTHERS          = 3.
  11.   IF sy-subrc <> 0.
  12. * Implement suitable error handling here
  13.   ENDIF.

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

  15.   lv_data-guid = is_cust_key-guid.
  16.   lv_data-custno = is_cust_key-custno.
  17.   lv_data-new = 'C'.

  18.   APPEND lv_data TO gt_customer.

  19.   rv_success = 'X'.

  20. ENDMETHOD.
复制代码

SAVE_CUSTOMER
Genil 17.jpg
  1. METHOD save_customer.

  2.   DATA : wa_cust TYPE zmast_cust.
  3.   DATA : lv_success TYPE abap_bool.

  4.   FIELD-SYMBOLS: <customer_attr_n> LIKE LINE OF gt_customer.

  5.   lv_success = 'X'.

  6.   READ TABLE gt_customer ASSIGNING <customer_attr_n> WITH
  7.              KEY guid = cs_key-guid
  8.                  custno = cs_key-custno.

  9.   CHECK sy-subrc = 0.

  10.   CASE <customer_attr_n>-new.
  11.     WHEN 'C' OR 'M'.
  12.       MOVE-CORRESPONDING <customer_attr_n> TO wa_cust.
  13.       MODIFY zmast_cust FROM wa_cust.

  14.     WHEN OTHERS.
  15.   ENDCASE.

  16.   CALL FUNCTION 'DEQUEUE_EZMAST_CUST'
  17.     EXPORTING
  18.       mode_zmast_cust = 'E'
  19.       guid            = cs_key-guid
  20.       custno          = cs_key-custno.

  21.   CLEAR cs_key.

  22. ENDMETHOD.
复制代码

GET_CUSTOMER Genil 18.jpg
  1. METHOD get_customer.

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

  5. * Try to read from Buffer.
  6.     READ TABLE gt_customer WITH KEY
  7.                guid = is_cust_key-guid
  8.                custno = is_cust_key-custno
  9.                ASSIGNING <data>.
  10.   ELSE.
  11.     READ TABLE gt_customer WITH KEY new = 'C' ASSIGNING <data>.

  12.     IF sy-subrc <> 0.
  13.       RETURN.
  14.     ENDIF.
  15.   ENDIF.

  16.   IF sy-subrc = 0.
  17.     IF <data>-new EQ 'C' OR <data>-new EQ 'M'.
  18.       MOVE-CORRESPONDING <data> TO es_cust_attr.
  19.       RETURN.
  20.     ENDIF.
  21.   ENDIF.

  22. ENDMETHOD.
复制代码

CHANGE_CUSTOMER
Genil 19.jpg
  1. METHOD change_customer.
  2.   FIELD-SYMBOLS : <line> TYPE zattr_cust,
  3.                            <old>  TYPE simple,
  4.                            <new>  TYPE simple,
  5.                            <name> TYPE name_komp.

  6.   READ TABLE gt_customer WITH KEY
  7.              guid = is_cust_attr-guid
  8.              custno = is_cust_attr-custno ASSIGNING <line> .

  9.   CHECK sy-subrc IS INITIAL.

  10.   LOOP AT it_names ASSIGNING <name>.
  11.     ASSIGN COMPONENT <name> OF STRUCTURE <line> TO <old>.
  12.     CHECK sy-subrc = 0.
  13.     ASSIGN COMPONENT <name> OF STRUCTURE is_cust_attr TO <new>.

  14.     CHECK sy-subrc = 0.
  15.     <old> = <new>.
  16.   ENDLOOP.
  17.   <line>-new = 'M'.
  18.   rv_success ='X'.
  19. ENDMETHOD.
复制代码


9、se24:ZCL_CUSTOMER_MODEL Genil 20.jpg
  1. METHOD if_genil_appl_intlay~create_objects.
  2.   TYPES : BEGIN OF ty_cust,
  3.              custno TYPE zcustno,
  4.           END OF ty_cust.

  5.   DATA : lv_guid    TYPE crmt_object_guid.
  6.   DATA : lv_key     TYPE zattr_cust_key.
  7.   DATA : lv_success TYPE char1.
  8.   DATA : lit_cust   TYPE TABLE OF ty_cust.
  9.   DATA : wa         TYPE ty_cust.
  10.   DATA : lv_count   TYPE i VALUE 0.

  11. * Fill structure based on Name Value Pairs Table.

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

  14. * Creating a Guid.
  15.   CALL FUNCTION 'GUID_CREATE'
  16.     IMPORTING
  17.       ev_guid_16 = lv_guid.

  18. * Custom Logic to create a New Customer Number.

  19.   SELECT custno FROM zmast_cust INTO TABLE lit_cust.

  20.   SORT lit_cust DESCENDING.

  21.   IF lit_cust IS NOT INITIAL.
  22.     LOOP AT lit_cust INTO wa.
  23.       lv_count = wa-custno + 1.
  24.       EXIT.
  25.     ENDLOOP.
  26.   ELSE.
  27.     lv_count = 1.
  28.   ENDIF.

  29.   lv_key-guid   = lv_guid.
  30.   lv_key-custno = lv_count.

  31. * API Class fills the the global attribute.

  32.   CALL METHOD zcl_customer_api=>create_customer
  33.     EXPORTING
  34.       is_cust_key = lv_key
  35.     IMPORTING
  36.       rv_success  = lv_success.

  37. * Add the object to Data Container - Root Object List Interface

  38.   IF lv_success IS NOT INITIAL.

  39.     iv_root_list->add_object( iv_object_name = iv_object_name
  40.                                is_object_key = lv_key ).
  41.   ENDIF.

  42. ENDMETHOD.
复制代码
  1. METHOD if_genil_appl_intlay~get_objects.

  2.   DATA lv_root        TYPE REF TO if_genil_cont_root_object.
  3.   DATA lv_key         TYPE zattr_cust_key.
  4.   DATA lv_cust_att  TYPE zattr_cust.

  5. * Get the first object of data container.

  6.   lv_root = iv_root_list->get_first( ).

  7.   lv_root->get_key( IMPORTING es_key = lv_key ).

  8. * Check if attributes are read after Create

  9.   IF lv_root->check_attr_requested( ) = abap_true.

  10. * Custom API class to get the customer attributes.

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

  13. * Return the objects only if it exists
  14.     IF lv_cust_att IS NOT INITIAL.

  15. * Set the attributes in container
  16.       lv_root->set_attributes( lv_cust_att ).

  17. * Get the next object of data container.

  18.       lv_root = iv_root_list->get_next( ).

  19.     ENDIF.
  20.   ENDIF.

  21. ENDMETHOD.
复制代码
  1. METHOD if_genil_appl_intlay~modify_objects.

  2.   DATA : lv_cust_attr TYPE zattr_cust,
  3.            lv_root      TYPE REF TO if_genil_container_object,
  4.            lv_changed_objects TYPE  crmt_genil_obj_instance,
  5.            lv_props     TYPE REF TO if_genil_obj_attr_properties,
  6.            lt_changed_attr TYPE  crmt_attr_name_tab,
  7.            lv_cust_key  TYPE zattr_cust_key,
  8.            lv_success   TYPE abap_bool.

  9.   DATA : lv_change TYPE crmt_genil_attr_property.

  10.   CHECK iv_root_list IS BOUND.

  11. * Get the first object from Container.

  12.   lv_root = iv_root_list->get_first( ).

  13.   IF lv_root->get_delta_flag( ) IS NOT INITIAL.

  14. * Get name of the object.

  15.     CASE lv_root->get_name( ).

  16.       WHEN 'Customer'.

  17. * Returns an Property Object for Object Attributes.

  18.         lv_props = lv_root->get_attr_props_obj( ).

  19. * Returns a Table of All Names with Specified Property.

  20.         CALL METHOD lv_props->get_name_tab_4_property
  21.           EXPORTING
  22.             iv_property = if_genil_obj_attr_properties=>modified
  23.           IMPORTING
  24.             et_names    = lt_changed_attr.


  25.         lv_root->get_key( IMPORTING es_key = lv_cust_key ).
  26.         lv_root->get_attributes( IMPORTING es_attributes = lv_cust_attr ).

  27.         MOVE-CORRESPONDING lv_cust_key TO lv_cust_attr.


  28.         CALL METHOD zcl_customer_api=>change_customer
  29.           EXPORTING
  30.             is_cust_attr = lv_cust_attr
  31.             it_names     = lt_changed_attr
  32.           IMPORTING
  33.             rv_success   = lv_success.

  34.         IF lv_success IS NOT INITIAL.

  35.           lv_changed_objects-object_name = 'Customer'.
  36.           lv_changed_objects-object_id = cl_crm_genil_container_tools=>build_object_id( lv_cust_key ).

  37. *    Add into Object Table with Object Type and ID.

  38.           APPEND lv_changed_objects TO et_changed_objects.

  39.         ENDIF.

  40.       WHEN OTHERS.
  41.     ENDCASE.
  42.   ENDIF.

  43. ENDMETHOD.
复制代码
  1. METHOD if_genil_appl_alternative_dsil~save_objects.

  2.   DATA lv_cust_key TYPE zattr_cust_key.

  3.   FIELD-SYMBOLS <object> TYPE crmt_genil_obj_inst_line.

  4.   LOOP AT ct_object_list ASSIGNING <object>.

  5. * Check for Object Instance.

  6.     CASE <object>-object_name.
  7.       WHEN 'Customer'.
  8.         TRY.
  9.             CALL METHOD cl_crm_genil_container_tools=>get_key_from_object_id(
  10.               EXPORTING
  11.                 iv_object_name = <object>-object_name
  12.                 iv_object_id   = <object>-object_id
  13.               IMPORTING
  14.                 es_key         = lv_cust_key ).
  15.             .
  16.           CATCH cx_crm_genil_general_error .
  17.         ENDTRY.

  18. * Custom API to Save the customer data.

  19.         CALL METHOD zcl_customer_api=>save_customer
  20.           CHANGING
  21.             cs_key = lv_cust_key.
  22.         IF lv_cust_key IS INITIAL.
  23.           <object>-success = abap_true.
  24.         ENDIF.
  25.     ENDCASE.
  26.   ENDLOOP.

  27. ENDMETHOD.                    "if_genil_appl_alternative_dsil~save_objects
复制代码

9、T-code:genil_bol_browser
Create  New Root Object
Genil 21.jpg
double click, Create Object
Genil 22.jpg
输入数据,保存

10、se11:ZMAST_CUST查看数据
Genil 23.jpg

回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表