天天看點

IBASE component deletion

Created by Jerry Wang, last modified on Oct 18, 2014

在使用FM CRM_IBASE_COMP_DELETE删除一個IBASE component時(使用下列report 測試),

IBASE component deletion

通過ST05 trace能發現component deletion不包含實體的Database 删除動作,僅僅是把相關的IBASE資料的valid to time stamp設定成deletion時的time stamp。

IBASE component deletion

删除後在tcode IB52裡無法再找到component 110059:

IBASE component deletion

隻有在tcode IB53裡将valid on的時間設定成deletion之前的時間,

IBASE component deletion

才能看到被删除的component 資訊:

IBASE component deletion

PARAMETERS: txt TYPE char40 OBLIGATORY DEFAULT 'description test',

            eid TYPE char30 OBLIGATORY DEFAULT 'PROGRAM',

            oid TYPE comm_product-product_id OBLIGATORY DEFAULT 'CHILDOB8',

            fam TYPE comm_product-object_family OBLIGATORY DEFAULT '0401',

            cat TYPE comt_category_id OBLIGATORY DEFAULT 'OBJ_0401'.

DATA: lt_param        TYPE crmt_name_value_pair_tab,

      ls_param        TYPE crmt_name_value_pair,

      lr_core         TYPE REF TO cl_crm_bol_core,

      ls_object       TYPE comm_product,

      lr_root         TYPE REF TO if_bol_entity_col,

      ls_comp_det     TYPE ibap_comp2,

      ls_comp_det_upd TYPE ibap_comp3,

      entity          TYPE REF TO cl_crm_bol_entity.

CHECK zcl_object_generator=>create_object( iv_id = oid iv_family = fam iv_catid = cat ) = abap_true.

ls_param-name  = cl_crm_ibase_il_constant=>createparam.

ls_param-value = '01'.

APPEND ls_param TO lt_param.

lr_core = cl_crm_bol_core=>get_instance( ).

lr_core->load_component_set('IBASE_ONLY').

CALL METHOD lr_core->root_create

  EXPORTING

    iv_object_name  = cl_crm_ibase_il_constant=>root_object

    iv_create_param = lt_param

    iv_number       = 1

  RECEIVING

    rv_result       = lr_root.

CHECK lr_root IS BOUND.

entity ?= lr_root->get_current( ).

CHECK entity IS BOUND.

IF entity->lock( ) = abap_true.

  entity->switch_to_change_mode( ).

ENDIF.

entity->set_property_as_string( iv_attr_name = 'DESCR' iv_value = CONV #( txt ) ).

entity->set_property_as_string( iv_attr_name = 'EXTID' iv_value = CONV #( eid ) ).

lr_core->modify( ).

DATA(lv_ibase_id) = entity->get_property_as_string( 'IBASE' ).

DATA(component) = entity->create_related_entity( 'FirstLevelComponent' ).

CHECK component IS NOT INITIAL.

DATA(obj_comp) = component->create_related_entity( 'IBCompObj').

CHECK obj_comp IS NOT INITIAL.

obj_comp->set_property_as_string( iv_attr_name = 'OBJECT_ID' iv_value = CONV #( oid ) ).

SELECT SINGLE * INTO ls_object FROM comm_product WHERE product_id = oid.

ASSERT sy-subrc = 0.

obj_comp->set_property_as_string( iv_attr_name = 'OBJECT_GUID' iv_value = CONV #( ls_object-product_guid ) ).

obj_comp->set_property_as_string( iv_attr_name = 'OBJECT_FAMILY' iv_value = CONV #( ls_object-product_guid ) ).

obj_comp->set_property_as_string( iv_attr_name = 'DESCR_EXT' iv_value = 'Jerry12345' ).

DATA(lo_message_container) = entity->get_message_container( ).

CALL METHOD lo_message_container->get_messages

    iv_message_type = if_genil_message_container=>mt_all

  IMPORTING

    et_messages     = DATA(lt_msg1).

LOOP AT lt_msg1 ASSIGNING FIELD-SYMBOL(<msg1>).

  WRITE:/ <msg1>-message COLOR COL_NEGATIVE.

ENDLOOP.

CHECK lt_msg1 IS INITIAL.

DATA(lo_transaction) = lr_core->get_transaction( ).

DATA(lv_changed) = lo_transaction->check_save_needed( ).

CHECK lv_changed EQ abap_true.

DATA: ls_header    TYPE ibap_head1,

      lt_struc_tab TYPE ibap_struc1_tab,

      ls_comp      TYPE ibap_dat1.

ls_header-ibase = lv_ibase_id.

CALL FUNCTION 'CRM_IBASE_GET_DETAIL'

    i_ibase_head      = ls_header

    e_struc_ibase_tab = lt_struc_tab

  EXCEPTIONS

    not_specified     = 1

    doesnt_exist      = 2

    no_authority      = 3.

CHECK sy-subrc = 0.

READ TABLE lt_struc_tab ASSIGNING FIELD-SYMBOL(<line>) INDEX 1.

ls_comp-instance = <line>-instance.

CALL FUNCTION 'CRM_IBASE_COMP_GET_DETAIL'

    i_comp           = ls_comp

    i_date           = sy-datlo

    i_time           = sy-timlo

    iv_do_auth_check = 'X'

    e_comp_det       = ls_comp_det

    not_specified    = 1

    doesnt_exist     = 2

    no_authority     = 3

    OTHERS           = 4.

MOVE-CORRESPONDING ls_comp_det TO ls_comp_det_upd.

ls_comp_det_upd-deviceid    = '1'.

ls_comp_det_upd-descr       = '2'.

CALL FUNCTION 'CRM_IBASE_COMP_CHANGE'

    i_comp              = ls_comp

    i_comp_det          = ls_comp_det_upd

    data_not_consistent = 1

    ibase_locked        = 2

    not_succesful       = 3

    no_authority        = 4

    OTHERS              = 5.

DATA(lv_success) = lo_transaction->save( ).

DATA(lo_glb_msg_cont) = lr_core->get_global_message_cont( ).

CALL METHOD lo_glb_msg_cont->if_genil_message_container~get_messages

    et_messages     = DATA(lt_msg).

LOOP AT lt_msg ASSIGNING FIELD-SYMBOL(<msg>).

  WRITE:/ <msg>-message.

IF lv_success = abap_true.

  lo_transaction->commit( ).

  WRITE:/ 'IBASE Created Successfully: ', lv_ibase_id COLOR COL_NEGATIVE.

ELSE.

  lo_transaction->rollback( ).

CALL FUNCTION 'CRM_IBASE_COMP_DELETE'

    no_authority        = 4.

CALL FUNCTION 'CRM_IBASE_SAVE'.

COMMIT WORK AND WAIT.

IF sy-subrc = 2.

  WRITE: / 'Component does not exist:' , ls_comp-instance COLOR COL_NEGATIVE.

  WRITE: / 'Detail returned:' , ls_comp_det-instance COLOR COL_POSITIVE.

繼續閱讀