IPM: 使用代码删除Acquisition contract上的IP Product

115 阅读2分钟

Created by Jerry Wang, last modified on Mar 27, 2014

report执行之前的Acquisition contract有10个IP Product:
image

执行report之后到UI检查,所有的IP product都移除了:
image

report source code 如下:

REPORT  zunassign_ip.
PARAMETERS:
            order TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '5600000010'.

DATA: lo_core                TYPE REF TO cl_crm_bol_core,
      lo_collection          TYPE REF TO if_bol_entity_col,
      lv_query_name          TYPE crmt_ext_obj_name,
      lt_selection_parameter TYPE genilt_selection_parameter_tab,
      ls_selection_parameter TYPE genilt_selection_parameter,
      lv_item_guid type crmt_object_guid,
      lr_del_handler type ref to cl_crm_ipm_item_delete_handler,
      lv_delete    type crmt_boolean,
      lv_count     type i value 0,
      ls_query_parameters    TYPE genilt_query_parameters.

ls_selection_parameter-attr_name = 'OBJECTID'.
ls_selection_parameter-option =  'EQ'.
ls_selection_parameter-sign = 'I'.
ls_selection_parameter-low =  order.
APPEND ls_selection_parameter TO lt_selection_parameter.

ls_query_parameters-max_hits = 1.
lv_query_name = 'BTAdvQueryAUI'.

lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->load_component_set( 'BT' ).
lo_core->load_component_set( 'IPMRM' ).
lo_collection = lo_core->dquery(
        iv_query_name               = lv_query_name
        it_selection_parameters     = lt_selection_parameter
        is_query_parameters         = ls_query_parameters ).

DATA(lo_contract) = lo_collection->get_current( ).
CHECK lo_contract IS NOT INITIAL.
DATA: lr_item_handler TYPE REF TO cl_crm_ipm_item_handler.
CREATE OBJECT lr_item_handler EXPORTING iv_header_bol_entity = lo_contract.

DATA(ips) = lr_item_handler->get_ips( ).
DATA(ip_instance) = ips->get_first( ).

WHILE ip_instance IS NOT INITIAL.

  IF ip_instance->lock( ) = abap_false.
     ip_instance = ips->get_next( ).
     CONTINUE.
  ENDIF.

  ip_instance->GET_PROPERTY_AS_VALUE( EXPORTING iv_attr_name = 'GUID' IMPORTING ev_result = lv_item_guid ).

  CALL FUNCTION 'CRM_IPM_ITEM_IP_DELETE_CHK'
      EXPORTING
        IV_OBJECT_GUID = lv_item_guid
        IV_HEADER_GUID = lv_item_guid
      IMPORTING
        EV_DELETE      = lv_delete.

  IF lv_delete = abap_false.
     ip_instance = ips->get_next( ).
     CONTINUE.
  ENDIf.

  DATA(ip_handler) = cl_crm_ipm_item_handler_provid=>get_instance( ip_instance ).

  create object lr_del_handler
        exporting
          ir_item_handler = ip_handler.
  data lr_col type ref to if_bol_bo_col.
  create object lr_col type cl_crm_bol_bo_col.
  lr_col->add( ip_instance ).

  lr_del_handler->delete_ips( lr_col ).

  ADD 1 TO lv_count.

  ip_instance = ips->get_next( ).
ENDWHILE.

lo_core->modify( ).

DATA(lo_transaction) = lo_core->get_transaction( ).
CHECK lo_transaction->check_save_possible( ) = abap_true.

CHECK lo_transaction->save( ) = abap_true.

lo_transaction->commit( ).

WRITE: / 'Successfully Unassigned IP number: ', lv_count.

使用代码将IP product assign到指定的Acquisition contract

Created by Jerry Wang, last modified on Mar 19, 2014

执行report,指定需要assign的IP product ID 和需要assign的Acquisition contract:
clipboard1

执行成功后去UI查看:
clipboard2
发现指定的IP product已经成功被assign:
clipboard3

report 的source code如下:

PARAMETERS: prod  type comm_product-product_id OBLIGATORY,
            order TYPE CRMD_ORDERADM_H-object_id.

DATA: lo_core                TYPE REF TO cl_crm_bol_core,
      lo_collection          TYPE REF TO if_bol_entity_col,
      lv_query_name          TYPE crmt_ext_obj_name,
      lt_selection_parameter TYPE genilt_selection_parameter_tab,
      ls_selection_parameter TYPE genilt_selection_parameter,
      ls_query_parameters    TYPE genilt_query_parameters.

ls_selection_parameter-attr_name = 'OBJECTID'.
ls_selection_parameter-option =  'EQ'.
ls_selection_parameter-sign = 'I'.
ls_selection_parameter-low =  order.
APPEND ls_selection_parameter TO lt_selection_parameter.

ls_query_parameters-max_hits = 1.
lv_query_name = 'BTAdvQueryAUI'.

lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->load_component_set( 'BT' ).

lo_collection = lo_core->dquery(
        iv_query_name               = lv_query_name
        it_selection_parameters     = lt_selection_parameter
        is_query_parameters         = ls_query_parameters ).


DATA(lo_contract) = lo_collection->get_current( ).
CHECK lo_contract IS NOT INITIAL.
DATA(locked) = lo_contract->lock( ).

CHECK locked  = 'X'.

DATA(lr_item_handler)  = cl_crm_ipm_item_handler_provid=>get_instance( lo_contract ).
ASSERT lr_item_handler IS NOT INITIAL.


lv_query_name = 'ProdAdvSearchRgProducts'.
CLEAR: lt_selection_parameter.
ls_selection_parameter-attr_name = 'PRODUCT_ID'.
ls_selection_parameter-option =  'EQ'.
ls_selection_parameter-sign = 'I'.
ls_selection_parameter-low =  prod.
APPEND ls_selection_parameter TO lt_selection_parameter.
lo_core->load_component_set( 'PROD_ALL' ).

lo_collection = lo_core->dquery(
    iv_query_name               = lv_query_name
    it_selection_parameters     = lt_selection_parameter
    is_query_parameters         = ls_query_parameters ).


DATA(lo_product) = lo_collection->get_current( ).
ASSERT lo_product IS NOT INITIAL.
DATA(result) = lr_item_handler->create_ip( lo_product ).
ASSERT result IS NOT INITIAL.

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

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

CHECK lv_changed EQ abap_true.
DATA(lv_success) = lo_transaction->save( ).
IF lv_success = abap_true.
  lo_transaction->commit( ).
  WRITE:/ 'IP Assigned Successfully'.
ELSE.
  lo_transaction->rollback( ).
  WRITE: / 'IP Assigned failed'.
ENDIF.

使用代码批量生成IP product

Created by Jerry Wang on Mar 18, 2014

下列代码可以将UI上批量生成IP Product的功能自动化:
clipboard1

执行report, 指定template IP product ID和待生成的IP product number:
image

执行report后打印出成功生成的IP product ID:
clipboard3

report source code如下:

REPORT  zgenerate_ip.

PARAMETERS: prod TYPE comm_product-product_id OBLIGATORY DEFAULT 'MEETMYFRIENDTOM',
            num  TYPE i.

DATA: lo_core                TYPE REF TO cl_crm_bol_core,
      lo_collection          TYPE REF TO if_bol_entity_col,
      lv_query_name          TYPE crmt_ext_obj_name,
      lt_reltype_filter      TYPE comt_il_reltype_tab,
      lv_product_id          TYPE comm_product-product_id,
      lt_selection_parameter TYPE genilt_selection_parameter_tab,
      ls_selection_parameter TYPE genilt_selection_parameter,
      ls_query_parameters    TYPE genilt_query_parameters.

lv_query_name = 'ProdAdvSearchRgProducts'.
CLEAR: lt_selection_parameter.
ls_selection_parameter-attr_name = 'PRODUCT_ID'.
ls_selection_parameter-option =  'EQ'.
ls_selection_parameter-sign = 'I'.
ls_selection_parameter-low =  prod.
APPEND ls_selection_parameter TO lt_selection_parameter.
lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->load_component_set( 'PROD_ALL' ).

lo_collection = lo_core->dquery(
    iv_query_name               = lv_query_name
    it_selection_parameters     = lt_selection_parameter
    is_query_parameters         = ls_query_parameters ).


DATA(lo_product) = lo_collection->get_current( ).
ASSERT lo_product IS NOT INITIAL.

DO num TIMES.
  CALL METHOD cl_crm_ipm_ip_copy=>set_mass_gen_mode( lt_reltype_filter ).
  DATA(lr_col) = lo_product->execute( iv_method_name = 'COPY_PRODUCT' ). "#EC NOTEXT

  ASSERT lr_col IS NOT INITIAL.

  DATA(lo_first) = lr_col->get_first( ).

  WHILE lo_first IS NOT INITIAL.
    lv_product_id = lo_first->get_property_as_string( 'PRODUCT_ID' ).
    WRITE: / 'Generated IP Product ID: ' , lv_product_id.
    lo_first = lr_col->get_next( ).
  ENDWHILE.
ENDDO.

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

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

CHECK lv_changed EQ abap_true.
DATA(lv_success) = lo_transaction->save( ).
IF lv_success = abap_true.
  lo_transaction->commit( ).
  WRITE:/ 'IP Generated Successfully'.
ELSE.
  lo_transaction->rollback( ).
  WRITE: / 'IP Generated failed'.
ENDIF.