如何使用代码给product创建distribution chain

Created by Jerry Wang, last modified on Jul 16, 2014

下列report能给指定的product创建3个用户输入的distribution chain:

如何使用代码给product创建distribution chain

执行完report后UI检查结果如下:

如何使用代码给product创建distribution chain

detail page:

如何使用代码给product创建distribution chain


source code如下:


REPORT prod_create_distr_chain.

PARAMETERS: id TYPE comm_product-product_id OBLIGATORY DEFAULT 'R15'.

SELECTION-SCREEN BEGIN OF BLOCK b1

 WITH FRAME TITLE txt1.

 PARAMETERS: sa_org1 type string OBLIGATORY DEFAULT 'O 50001213',

           dc1 type string OBLIGATORY DEFAULT '01',

           shotxt1 type string OBLIGATORY DEFAULT 'Inbox Test',

           satxt1 type string OBLIGATORY DEFAULT 'IC Inbox Test',

           dctxt1 type string OBLIGATORY DEFAULT 'Distribution channel 01',

           dcid1 type string OBLIGATORY DEFAULT 'O 50001213 / 01',

           long1 type string OBLIGATORY DEFAULT 'Sales Organization Inbox Test , Distrib.Channel 01'.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2

 WITH FRAME TITLE txt2.

 PARAMETERS: sa_org2 type string OBLIGATORY DEFAULT 'O 50001194',

           dc2 type string OBLIGATORY DEFAULT '02',

           shotxt2 type string OBLIGATORY DEFAULT 'Labs',

           satxt2 type string OBLIGATORY DEFAULT 'SAP Labs SH',

           dctxt2 type string OBLIGATORY DEFAULT 'for test',

           dcid2 type string OBLIGATORY DEFAULT 'O 50001194 / 02',

           long2 type string OBLIGATORY DEFAULT 'Sales Organization Labs , Distrib.Channel 02'.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3

 WITH FRAME TITLE txt3.

 PARAMETERS: sa_org3 type string OBLIGATORY DEFAULT 'O 50004509',

           dc3 type string OBLIGATORY DEFAULT '30',

           shotxt3 type string OBLIGATORY DEFAULT 'Crm-sales',

           satxt3 type string OBLIGATORY DEFAULT 'Crm-sales',

           dctxt3 type string OBLIGATORY DEFAULT '',

           dcid3 type string OBLIGATORY DEFAULT 'O 50004509 / 30',

           long3 type string OBLIGATORY DEFAULT 'Sales Organization Crm-sales , Distrib.Channel 30'.

SELECTION-SCREEN END OF BLOCK b3.

INITIALIZATION.

   txt1 = 'Distribution chain1'.

   txt2 = 'Distribution chain2'.

   txt3 = 'Distribution chain3'.

START-OF-SELECTION.

DATA(product) = cl_crm_prod_internal_tool=>get_prod_by_id( id ).

DATA: lv_index TYPE int4 VALUE 1.

DATA(lo_dist_chain) = product->get_related_entities( iv_relation_name = 'ProductDistrChain' ).

IF lo_dist_chain->size( ) > 0.

 WRITE: / 'Current product already has distribution chain maintained.' COLOR COL_NEGATIVE.

 RETURN.

ENDIF.

* 1

DATA(lo_chain_single) = product->create_related_entity( iv_relation_name = 'ProductDistrChain'

iv_child_name = 'ProdDistrChain' ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SALES_ORG' iv_value = sa_org1 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DISTR_CHAN' iv_value = dc1 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SHORT_DESC' iv_value = shotxt1 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SALES_DESC' iv_value = satxt1 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DISTR_DESC' iv_value = dctxt1 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DSTRBCHAIN_ID' iv_value = dcid1 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DESCRIPTION' iv_value = long1 ).

*2

lo_chain_single = product->create_related_entity( iv_relation_name = 'ProductDistrChain'

iv_child_name = 'ProdDistrChain' ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SALES_ORG' iv_value = sa_org2 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DISTR_CHAN' iv_value = dc2 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SHORT_DESC' iv_value = shotxt2 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SALES_DESC' iv_value = satxt2 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DISTR_DESC' iv_value = dctxt2 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DSTRBCHAIN_ID' iv_value = dcid2 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DESCRIPTION' iv_value = long2 ).

lo_chain_single = product->create_related_entity( iv_relation_name = 'ProductDistrChain'

iv_child_name = 'ProdDistrChain' ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SALES_ORG' iv_value = sa_org3 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DISTR_CHAN' iv_value = dc3 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SHORT_DESC' iv_value = shotxt3 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'SALES_DESC' iv_value = satxt3 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DISTR_DESC' iv_value = dctxt3 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DSTRBCHAIN_ID' iv_value = dcid3 ).

lo_chain_single->set_property_as_string( iv_attr_name = 'DESCRIPTION' iv_value = long3 ).

DATA(lv_saved) = cl_crm_prod_internal_tool=>save_transaction( ).

WRITE: / 'saved successfully?' , lv_saved COLOR COL_TOTAL.

class CL_CRM_PROD_INTERNAL_TOOL definition

 public

 final

 create public .

public section.

 class-methods CLASS_CONSTRUCTOR .

 class-methods GET_PROD_BY_ID

   importing

     !IV_PRODUCT_ID type COMM_PRODUCT-PRODUCT_ID

   returning

     value(RO_BOL) type ref to CL_CRM_BOL_ENTITY .

 class-methods SAVE_TRANSACTION

   returning

     value(RV_SUCCESS) type ABAP_BOOL .

protected section.

private section.

 class-data SO_BOL_CORE type ref to CL_CRM_BOL_CORE .

ENDCLASS.

CLASS CL_CRM_PROD_INTERNAL_TOOL IMPLEMENTATION.

* ---------------------------------------------------------------------------------------+

* | Static Public Method CL_CRM_PROD_INTERNAL_TOOL=>CLASS_CONSTRUCTOR

* +-------------------------------------------------------------------------------------------------+

* +--------------------------------------------------------------------------------------

 method CLASS_CONSTRUCTOR.

   so_bol_core = cl_crm_bol_core=>get_instance( ).

   so_bol_core->load_component_set( 'PROD_ALL' ).

 endmethod.

* ---------------------------------------------------------------------------------------+

* | Static Public Method CL_CRM_PROD_INTERNAL_TOOL=>GET_PROD_BY_ID

* +-------------------------------------------------------------------------------------------------+

* | [--->] IV_PRODUCT_ID                  TYPE        COMM_PRODUCT-PRODUCT_ID

* | [<-()] RO_BOL                         TYPE REF TO CL_CRM_BOL_ENTITY

* +--------------------------------------------------------------------------------------

 METHOD get_prod_by_id.

   DATA:

     lo_collection      TYPE REF TO if_bol_entity_col,

     lo_root_entity     TYPE REF TO cl_crm_bol_entity,

     lv_view_name       TYPE crmt_view_name,

     lv_query_name      TYPE crmt_ext_obj_name,

     lt_query_parameter TYPE crmt_name_value_pair_tab,

     ls_query_parameter LIKE LINE OF lt_query_parameter,

     lv_size            TYPE i.

   ls_query_parameter-name = 'PRODUCT_ID'.

   ls_query_parameter-value = iv_product_id.

   APPEND ls_query_parameter TO lt_query_parameter.

   ls_query_parameter-name = 'MAX_ROWS'.

   ls_query_parameter-value = 1.

   APPEND ls_query_parameter TO lt_query_parameter.

   lv_query_name = 'ProdAdvancedSearchProducts'.

   lo_collection = so_bol_core->query(

       iv_query_name               = lv_query_name

       it_query_params             = lt_query_parameter

       iv_view_name                = lv_view_name ).

   ASSERT lo_collection IS NOT INITIAL.

   ASSERT lo_collection->size( ) = 1.

   ro_bol = lo_collection->get_current( ).

 ENDMETHOD.

* ---------------------------------------------------------------------------------------+

* | Static Public Method CL_CRM_PROD_INTERNAL_TOOL=>SAVE_TRANSACTION

* +-------------------------------------------------------------------------------------------------+

* | [<-()] RV_SUCCESS                     TYPE        ABAP_BOOL

* +--------------------------------------------------------------------------------------

 method SAVE_TRANSACTION.

   so_bol_core->modify( ).

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

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

      rv_success = abap_true.

   ELSE.

      lo_transaction->rollback( ).

   ENDIF.

 endmethod.

ENDCLASS.


上一篇:android ContentProvider使用详解


下一篇:Android(安卓) U8800 长按 搜索键、返回键 锁屏或解锁的设置方法