如何使用ABAP代码创建SAP Product Category

简介: 如何使用ABAP代码创建SAP Product Category

In ERP we can create new material type by copying from existing one using tcode OMS2:image.pngThis new type could be downloaded into CRM system via customizing download. A product category with prefix MAT_ will be automatically created.



image.png

image.pngAnd here below is source code to create new product category using MAT_ as parent category by ABAP code.METHOD replicate_category.

   CONSTANTS:

     BEGIN OF gc_application,

       sales      TYPE comt_application VALUE '01', "r3-produkthier

       purchasing TYPE comt_application VALUE '02', "r3 mat class

       product    TYPE comt_application VALUE '03', "r3 mat types

       config     TYPE comt_application VALUE '04',

       internet   TYPE comt_application VALUE '05',

     END OF gc_application.

   CONSTANTS:

     BEGIN OF gc_product_type,

       material  TYPE comt_product_type VALUE '01',

       service   TYPE comt_product_type VALUE '02',

       finance   TYPE comt_product_type VALUE '03',

       ip_prod   TYPE comt_product_type VALUE '04',

       warranty  TYPE comt_product_type VALUE '05',

       tradeitem TYPE comt_product_type VALUE '06',

       fs_prod   TYPE comt_product_type VALUE '07',

     END OF gc_product_type.

   rv_success = abap_false.

   DATA: lv_hierarchy_guid TYPE comt_hierarchy_guid,

         lv_parent_guid    TYPE comt_category_guid,

         lt_categoryt      TYPE comt_categoryt_tab.

* Prerequisite: the corresponding hierarchy is already downloaded from ERP

* Read the hierarchy which is assigned to application 03

* (product type material) in transaction COMM_PRAPPLCAT

   CALL FUNCTION 'COM_HIERARCHY_READ_WITH_APPL'

     EXPORTING

       iv_application    = gc_application-product

       iv_product_type   = gc_product_type-material

     IMPORTING

       ev_hierarchy_guid = lv_hierarchy_guid

     EXCEPTIONS

       not_found         = 1

       OTHERS            = 2.

   CHECK sy-subrc = 0.

   DATA(ls_cat_text) = VALUE comt_categoryt( langu = sy-langu category_text = iv_text

   text_upper_case = iv_text ).

   TRANSLATE ls_cat_text-text_upper_case TO UPPER CASE.

   APPEND ls_cat_text TO lt_categoryt.

   select single category_guid into lv_parent_guid FROM comm_category

      where category_id = 'MAT_'.

   CALL FUNCTION 'COM_PRODCAT_API_CREATE_CAT'

     EXPORTING

       iv_category_id           = iv_cat_id

       iv_hierarchy_guid        = lv_hierarchy_guid

       iv_parent_guid           = lv_parent_guid

       iv_product_type          = gc_product_type-material

       it_categoryt             = lt_categoryt

       iv_logsys                = iv_log_sys " 'QI3CLNT502'

       iv_non_assignable        = abap_false

     EXCEPTIONS

       hierarchy_not_maintained = 1

       wrong_call               = 2

       category_id_exists       = 3

       id_scheme_error          = 4

       error                    = 5

       OTHERS                   = 6.

   IF sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE 'X' NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     RETURN.

   ENDIF.

   CALL FUNCTION 'COM_PRODUCT_CATEGORY_SAVE_ALL'

     EXPORTING

       iv_update_task    = ' '

       iv_update_pme     = ' '

       iv_hierarchy_guid = lv_hierarchy_guid

     EXCEPTIONS

       internal_error    = 1

       OTHERS            = 2.

   ASSERT sy-subrc = 0.

   COMMIT WORK AND WAIT.

   rv_success = abap_true.

 ENDMETHOD.Method signature:image.png

How to use this code

Run method in SE24, specify new product category id via parameter iv_cat_id:image.pngExecute method, ensure ev_success equals to abap_true.image.pngOnce created, the category could be searched via tcode COMM_HIERARCHY:image.pngAnd the category could be used to create new product in WebUI:image.png

相关文章
|
5月前
|
存储 安全 数据库
什么是 SAP ABAP 数据库表的 Display Maintenance Allowed with Restrictions
什么是 SAP ABAP 数据库表的 Display Maintenance Allowed with Restrictions
|
5月前
|
监控 测试技术
SAP 电商云修改 Product Catalog Staged 版本数据后,同步到 online 版本的 UI 操作
SAP 电商云修改 Product Catalog Staged 版本数据后,同步到 online 版本的 UI 操作
|
5月前
|
安全 API 数据库
SAP ABAP OData 中 Function import 的概念介绍
SAP ABAP OData 中 Function import 的概念介绍
|
5月前
|
SQL 负载均衡 监控
SAP ABAP DBSQL_SQL_ERROR 错误
SAP ABAP DBSQL_SQL_ERROR 错误
|
5月前
|
前端开发 数据库 开发者
如何在 SEGW 事务码里为 SAP ABAP OData 服务实现 Function Import 试读版
如何在 SEGW 事务码里为 SAP ABAP OData 服务实现 Function Import 试读版
SAP ABAP OData 服务里需要指定 guid 类型的请求参数时,正确语法是什么?
SAP ABAP OData 服务里需要指定 guid 类型的请求参数时,正确语法是什么?
|
5月前
|
存储 监控 数据库
SAP 电商云 product catalog 从 staged 到 online 两个版本之间的同步
SAP 电商云 product catalog 从 staged 到 online 两个版本之间的同步
|
5月前
|
监控 安全 数据管理
SAP 电商云 Product catalog 的 staged 和 online 两种版本的设计理念
SAP 电商云 Product catalog 的 staged 和 online 两种版本的设计理念
|
5月前
|
SQL 监控 Oracle
SAP ABAP 系统错误 Return value of the database layer SQL dbsl rc 99
SAP ABAP 系统错误 Return value of the database layer SQL dbsl rc 99
|
5月前
|
存储 前端开发 Linux
在 SAP ABAP 系统里访问 FTP 服务器
在 SAP ABAP 系统里访问 FTP 服务器
下一篇
无影云桌面