Requirement:
I would like to get Product sales status id via ABAP code. The test product id: 1467
In TJ02T, we know the status id is: I1050
Approach1: use function module CRM_STATUS_READ.
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:
Approach2: use BOL API
Method signature:
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.
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:
要获取更多 Jerry 的原创文章,请关注公众号 ” 汪子熙 ”: