使用代码创建SAP CRM服务请求文档的subject测试数据

简介:

Carsten要求所有创建的Service Request的测试数据必须都维护好Subject:

如何用CRM_ORDER_MAINTAIN维护这个field?
First have a look at how SERVICE_OS is filled by CRM_ORDER_MAINTAIN when choosing one value from drop down list:

I have to figure out where this two REF_GUID come from so that I can do the same thing in my code.






Answer for first guid: CL_CRM_CATEGORY_RUN_BTIL~GET_OSSET_GUID

Answer for second guid:


Test code:

REPORT zcreate_subject.
DATA: lt_input_fields     TYPE  crmt_input_field_tab,
      ls_input_field      LIKE LINE OF lt_input_fields,
      ls_field_name       LIKE LINE OF ls_input_field-field_names,
      lv_guid             TYPE guid_16,
      lt_orderadm_h_com   TYPE crmt_orderadm_h_comt,
      ls_orderadm_h_com   LIKE LINE OF lt_orderadm_h_com,
      ls_com_structure    TYPE string,
      lv_selection_needed TYPE  crmt_boolean,
      lt_save             TYPE crmt_object_guid_tab,
      lt_saved            TYPE crmt_return_objects,
      lt_service_os       TYPE crmt_srv_osset_comt,
      ls_service_os       TYPE LINE OF crmt_srv_osset_comt,
      lt_osset            TYPE crmt_srv_osset_comt1,
      ls_osset            TYPE LINE OF crmt_srv_osset_comt1,
      ls_read_oss         TYPE crmt_srv_osset_wrk,
      ls_saved            LIKE LINE OF lt_saved,
      lt_subject          TYPE crmt_srv_subject_comt,
      ls_subject          TYPE LINE OF crmt_srv_subject_comt.

START-OF-SELECTION.
  CALL FUNCTION 'GUID_CREATE'
    IMPORTING
      ev_guid_16 = lv_guid.

  PERFORM call_order_maintain.
  PERFORM call_order_save.

FORM prepare_service_os.
  ls_service_os = VALUE #( ref_guid = lv_guid ref_kind = 'A' ).
  ls_osset-profile_type = 'A'.

  CALL FUNCTION 'CRM_GUID_CREATE'
    IMPORTING
      ev_guid = ls_osset-ref_guid.

  CALL FUNCTION 'CRM_GUID_CREATE'
    IMPORTING
      ev_guid = ls_subject-ref_guid.

  ls_subject-asp_id = 'YBP_SERVICE'.
  ls_subject-katalog_type = 'D'.
  ls_subject-cat_id = 'CA_7'.
  ls_subject-mode = 'A'.
  APPEND ls_subject TO ls_osset-subject.
  APPEND ls_osset TO lt_osset.
  APPEND LINES OF lt_osset TO ls_service_os-osset.
  APPEND ls_service_os TO lt_service_os.

  CLEAR: ls_input_field.

  ls_input_field-ref_guid = lv_guid.
  ls_input_field-ref_kind = 'A'.
  ls_input_field-objectname = 'SERVICE_OS'.

  ls_field_name-fieldname = 'ASP_ID'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'CAT_ID'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'CODE'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'CODEGRUPPE'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'KATALOGART'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'MODE'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'REF_GUID'.
  APPEND ls_field_name TO ls_input_field-field_names.
  APPEND ls_input_field TO lt_input_fields.

ENDFORM.

FORM call_order_maintain.
  CLEAR: ls_orderadm_h_com, ls_input_field, lt_input_fields.
  ls_orderadm_h_com-guid = lv_guid.
  ls_orderadm_h_com-description = 'created by code on:' && sy-timlo.
  ls_orderadm_h_com-process_type = 'SRVR'.
  ls_orderadm_h_com-mode = 'A'.

  APPEND ls_orderadm_h_com TO lt_orderadm_h_com.
  ls_input_field-ref_guid = lv_guid.
  ls_input_field-ref_kind = 'A'.
  ls_input_field-objectname = 'ORDERADM_H'.
  ls_field_name-fieldname = 'DESCRIPTION'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'MODE'.
  APPEND ls_field_name TO ls_input_field-field_names.
  ls_field_name-fieldname = 'PROCESS_TYPE'.
  APPEND ls_field_name TO ls_input_field-field_names.

  APPEND ls_input_field TO lt_input_fields.

  PERFORM prepare_service_os.

  CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
      it_service_os   = lt_service_os
    CHANGING
      ct_orderadm_h   = lt_orderadm_h_com
      ct_input_fields = lt_input_fields
    EXCEPTIONS
      OTHERS          = 99.

  IF sy-subrc = 0.
    WRITE:/ 'Order maintain function is done successfully.'.
  ENDIF.
ENDFORM.

FORM call_order_save.
  INSERT lv_guid INTO TABLE lt_save.

  CALL FUNCTION 'CRM_ORDER_SAVE'
    EXPORTING
      it_objects_to_save   = lt_save
      iv_update_task_local = abap_true
      iv_no_bdoc_send      = abap_true
    IMPORTING
      et_saved_objects     = lt_saved
    EXCEPTIONS
      document_not_saved   = 1.
  IF sy-subrc <> 0.
    WRITE: / 'Service Request created failed'.
  ELSE.
    READ TABLE lt_saved INTO ls_saved INDEX 1.
    WRITE: / 'Service Request created successfully, id: ' , ls_saved-object_id.
  ENDIF.
  COMMIT WORK AND WAIT.
ENDFORM.

本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

相关文章
|
1月前
|
人工智能 搜索推荐 Serverless
使用金庸的著作,来测试阿里通义千问最新开放的长文档处理功能
使用金庸的著作,来测试阿里通义千问最新开放的长文档处理功能
88 7
使用金庸的著作,来测试阿里通义千问最新开放的长文档处理功能
|
1月前
|
存储
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
21 0
|
2天前
SAP CLIENT 数据配置文件的导出/导入
SAP CLIENT 数据配置文件的导出/导入
|
1月前
|
数据库
SAP CRM产品主数据无法根据产品描述字段进行搜索的原因
SAP CRM产品主数据无法根据产品描述字段进行搜索的原因
17 5
|
1月前
|
Web App开发 开发者 存储
介绍一个 webp 格式转 png 格式的软件:XNConvert
介绍一个 webp 格式转 png 格式的软件:XNConvert
30 6
介绍一个 webp 格式转 png 格式的软件:XNConvert
|
1月前
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
16 1
什么是 SAP ABAP 里的 Subscreen
|
2月前
|
前端开发 搜索推荐 开发者
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
32 0
|
2月前
|
JavaScript 前端开发 开发者
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
17 0
|
2月前
|
Web App开发 数据采集 前端开发
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
20 0
|
2月前
|
XML 存储 数据格式
SAP UI5 控件 customData 属性的应用介绍
SAP UI5 控件 customData 属性的应用介绍
35 0