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

无法添加某个relationship给SAP CRM Product category的一个可能原因 SAPC4CCloudCDS viewABAP 

程序员文章站 2022-03-04 15:20:15
...

For example, I would like to test relationship type STRSET and then I plan to add it to product category 00001.

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

However, in available drop down list, I could not see relationship type STRSET. Why?

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

When debugging the backend logic to render relationship type drop down list entries, I found there is a check implemented by the function module below, to avoid a relationship is assigned more than once.

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

According to SAP help, a set type / relationship may be assigned to more than one category within a hierarchy, but to only one hierarchy for each product type. Therefore even if two categories are in different hierarchies but have the same product type, it is not possible to assign the set type / relationship to both categories. In my example, the check against my category 00001 belonging to hierarchy R3PRODHIER fails ( assign_not_allowed ).

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

The question is, how to find other categories in different hierarchy other than R3PRODHIER, which are already assigned with STRSET? In order to make life easier, I write the following utility method to detect such collision: Method input: relationship type name, here it is STRSET:

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

Output is a table with line type category id, hierarchy id and product type the category is assigned to.

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

By using this method, I know in current system, in another product hierarchy R3PRODSTYP, there are already three categories with relationship type STRSET assigned:

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

As a result I have several approaches: I can remove the relationship STRSET from category ZALTID, after that it will be possible again for me to add STRSET to category 00001. If there is already product created based on category ZALTID, it will not be possible to remove relationship from ZALTID, then I have to consider to directly add category ZALTID or its children category to my product. The utility method signature:

 

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP 

 

type TT_USAGE used:

types:
    BEGIN OF ty_usage,
       cat_id TYPE comm_category-category_id,
       hier_id TYPE comm_hierarchy-hierarchy_id,
       prod_type TYPE comm_product-product_type,
        END OF ty_usage .
  types:
    tt_usage TYPE STANDARD TABLE OF ty_usage WITH key cat_id hier_id .
Method source code:
  METHOD rel_type_usage_check.
    DATA: lt_prcat_il_rel TYPE comt_prcat_il_rel_tab,
          ls_prcat        LIKE LINE OF lt_prcat_il_rel,
          ls_category     TYPE comt_category,
          ls_prcattype        TYPE comt_prcat,
          lv_hie_id       TYPE comm_hierarchy-hierarchy_id.

    CALL FUNCTION 'COM_PRCAT_IL_REL_READ_WITH_IL'
      EXPORTING
        iv_il_reltype   = iv_rel
        iv_il_direction = 'S'
      IMPORTING
        et_prcat_il_rel = lt_prcat_il_rel
      EXCEPTIONS
        not_found       = 1
        wrong_call      = 2
        OTHERS          = 3.
    CHECK sy-subrc = 0.

    LOOP AT lt_prcat_il_rel INTO ls_prcat.
      CALL FUNCTION 'COM_CATEGORY_READ'
        EXPORTING
          iv_category_guid = ls_prcat-category_guid
        IMPORTING
          es_category      = ls_category
        EXCEPTIONS
          wrong_call       = 1
          not_found        = 2
          error            = 3.
      CHECK sy-subrc = 0.
      SELECT SINGLE hierarchy_id INTO lv_hie_id FROM comm_hierarchy
         WHERE hierarchy_guid = ls_category-hierarchy_guid.
      CHECK sy-subrc = 0.
      CALL FUNCTION 'COM_PRCAT_READ'
        EXPORTING
          iv_category_guid = ls_category-category_guid
        IMPORTING
          es_prcat         = ls_prcattype
        EXCEPTIONS
          wrong_call       = 1
          not_found        = 2
          OTHERS           = 3.
      APPEND INITIAL LINE TO rt_usage ASSIGNING FIELD-SYMBOL(<result>).

      <result> = value #( cat_id = ls_category-category_id hier_id = lv_hie_id
      prod_type = ls_prcattype-product_type  ).
    ENDLOOP.

  ENDMETHOD.

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

无法添加某个relationship给SAP CRM Product category的一个可能原因
            
    
    
        SAPC4CCloudCDS viewABAP