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

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

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

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

image.png

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

image.png

detail page:

image.png


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.


相关文章
【错误记录】Tinker 热修复示例运行报错 ( Execution failed for task ‘:app:tinkerProcessD‘ . tinkerId is not set!!! )
【错误记录】Tinker 热修复示例运行报错 ( Execution failed for task ‘:app:tinkerProcessD‘ . tinkerId is not set!!! )
300 0
【错误记录】Tinker 热修复示例运行报错 ( Execution failed for task ‘:app:tinkerProcessD‘ . tinkerId is not set!!! )
|
3月前
|
XML 缓存 API
【Azure API 管理】使用APIM进行XML内容读取时遇见的诡异错误 Expression evaluation failed. Object reference not set to an instance of an object.
【Azure API 管理】使用APIM进行XML内容读取时遇见的诡异错误 Expression evaluation failed. Object reference not set to an instance of an object.
|
3月前
LangChain 构建问题之定义extract_local_group_size工具如何解决
LangChain 构建问题之定义extract_local_group_size工具如何解决
17 0
SAP QM 执行事务代码QP01,系统报错 -Material type FOOD is not defined for task list type Q-
SAP QM 执行事务代码QP01,系统报错 -Material type FOOD is not defined for task list type Q-
SAP QM 执行事务代码QP01,系统报错 -Material type FOOD is not defined for task list type Q-
在S4 key user tool里创建Custom Logic的后台实现
在S4 key user tool里创建Custom Logic的后台实现
114 0
在S4 key user tool里创建Custom Logic的后台实现
SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
How to render S4 Code List extension field into CRM WebUI product search view
This question is asked by Wade. Suppose I have created one extension field in S4 with type CodeList which contains all possible queue type supported by JDK. This extension field must be exposed to CRM Product Search WebUI. POC is done in X3C/504:
How to render S4 Code List extension field into CRM WebUI product search view
How to put S4 extension field to CRM WebUI search view in the design time
How to put S4 extension field to CRM WebUI search view in the design time
116 0
How to put S4 extension field to CRM WebUI search view in the design time
ABAP 数据结构激活时的错误消息 - combination reference table field XXX does not exist
ABAP 数据结构激活时的错误消息 - combination reference table field XXX does not exist
ABAP 数据结构激活时的错误消息 - combination reference table field XXX does not exist
SAP CRM Product simple search的启用步骤
SAP CRM Product simple search的启用步骤
127 0
SAP CRM Product simple search的启用步骤