欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

两种使用代码获得SAP CRM product sales status的办法 SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

程序员文章站 2022-06-13 17:18:23
...

Requirement: I would like to get Product sales status id via ABAP code. The test product id: 1467

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

In TJ02T, we know the status id is: I1050

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

Approach1: use function module CRM_STATUS_READ.

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

METHOD read_prod_sales_status.
    DATA(lv_guid) = get_guid_by_id( iv_prod_id ).
    CONSTANTS: gv_salesa TYPE comm_pr_frg_rod-fragment_type
     VALUE '37D58F1B772D53A4E10000009B38FA0B'.

    DATA: lv_objnr  TYPE comm_pr_frg_rod-status_object,
          lt_status TYPE STANDARD TABLE OF jstat.

    SELECT SINGLE status_object FROM comm_pr_frg_rod INTO lv_objnr
       WHERE product_guid = lv_guid AND fragment_type = gv_salesa.

    CHECK sy-subrc = 0.

    CALL FUNCTION 'CRM_STATUS_READ'
      EXPORTING
        objnr            = lv_objnr
      TABLES
        status           = rt_status
      EXCEPTIONS
        object_not_found = 1.
  ENDMETHOD.

Output:

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

Approach2: use BOL API

Method signature:

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

Source code:

METHOD get_prod_sales_status_via_bol.
    DATA:
      lo_collection    TYPE REF TO if_bol_entity_col,
      lv_view_name     TYPE crmt_view_name,
      lv_query_name    TYPE crmt_ext_obj_name,
      ls_parameter     TYPE genilt_query_parameters,
      lt_sel_parameter TYPE crmt_name_value_pair_tab,
      ls_sel_parameter LIKE LINE OF lt_sel_parameter.

    lv_query_name = 'ProdAdvancedSearchProducts'.
    ls_sel_parameter = VALUE #( name = 'PRODUCT_ID' value = iv_prod_id ).
    APPEND ls_sel_parameter TO lt_sel_parameter.

    DATA(lo_result) = so_core->query(
        iv_query_name               = lv_query_name
        it_query_params = lt_sel_parameter
        iv_view_name                = lv_view_name ).

    CHECK lo_result->size( ) = 1.
    DATA(lo_product) = lo_result->get_first( ).

    DATA(lo_dc) = lo_product->get_related_entity( 'ProductDistrChain' ).
    CHECK lo_dc IS NOT INITIAL.

    DATA(lo_salesa) = lo_dc->get_related_entity( 'ProductDcSalesa' ).

    CHECK lo_salesa IS NOT INITIAL.

    RV_STATUS = lo_Salesa->get_property_as_string( 'STATUS_OBJECT' ).

  ENDMETHOD.

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

Define a static attribute so_core and initialize it in class constructor:

method CLASS_CONSTRUCTOR.
     so_core = cl_crm_bol_core=>get_instance( ).
     so_core->load_component_set( 'PROD_ALL' ).
  endmethod.

Test result:

 

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP 

 

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

两种使用代码获得SAP CRM product sales status的办法
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院ABAP