乐趣区

关于sap:使用-ABAP-代码删除指定-SAP-CRM-系统里-Opportunity-订单的文本

REPORT znote_delete_tool.

PARAMETERS: id   TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '2025',
            type TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'OPSM',
            lan  TYPE stxh-tdospras OBLIGATORY DEFAULT 'E',
            tdid TYPE stxh-tdid OBLIGATORY DEFAULT 'A002'.


TYPES: text_line(cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength)  TYPE c.

DATA: lv_char32   TYPE char32, " CRMD_ORDERADM_H-guid,
      lv_id       LIKE id,
      lv_guid     TYPE crmd_orderadm_h-guid.

DATA: ls_return               TYPE STANDARD TABLE OF bapiret2.
DATA: lt_lines TYPE STANDARD TABLE OF tline,
      ls_line  LIKE LINE OF lt_lines.
DATA: lt_objects_to_save          TYPE crmt_object_guid_tab.
DATA: lt_objects_not_saved        TYPE crmt_object_guid_tab.
DATA: lt_saved_objects            TYPE crmt_return_objects.

lv_id = id.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = lv_id
  IMPORTING
    output = lv_id.

SELECT SINGLE guid FROM crmd_orderadm_h INTO lv_guid WHERE object_id = id AND process_type = type.
IF sy-subrc <> 0.
  WRITE: / 'No opportunity found' COLOR COL_GROUP.
  RETURN.
ENDIF.

DATA: lt_text         TYPE crmt_text_comt,
      ls_text         LIKE LINE OF lt_text,
      ls_input_fields TYPE crmt_input_field,
      lv_logical_key  TYPE crmt_logical_key,
      ls_field_names  TYPE crmt_input_field_names.
DATA: lt_input_field_names TYPE crmt_input_field_names_tab,
      ls_input_field_name  LIKE LINE OF lt_input_field_names.
DATA: lt_input_fields             TYPE crmt_input_field_tab.

ls_text-ref_handle  = '0000000000'.
ls_text-ref_guid = lv_guid.
ls_text-ref_kind = 'A'.
ls_text-text_object = cl_crm_odata_oppt_constant=>gc_oppt_notes_tdobject.
ls_text-mode = 'D'.
ls_text-tdid = tdid.
ls_text-tdspras = lan.
ls_line-tdformat = '*'.
APPEND ls_line TO ls_text-lines.

APPEND ls_text TO lt_text.

CLEAR ls_input_fields.
ls_input_fields-ref_guid = lv_guid.
ls_input_fields-ref_kind = 'A'.
ls_input_fields-objectname = 'TEXTS'.
CONCATENATE ls_text-tdid ls_text-tdspras INTO lv_logical_key.
ls_input_fields-logical_key = lv_logical_key.     " use handle or guid ?
CLEAR ls_input_fields-field_names.
ls_input_field_name-fieldname = 'LINES'.
APPEND ls_input_field_name TO ls_input_fields-field_names.

INSERT ls_input_fields INTO TABLE lt_input_fields.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'
  EXPORTING
    it_text           = lt_text
  CHANGING
    ct_input_fields   = lt_input_fields
  EXCEPTIONS
    error_occurred    = 1
    document_locked   = 2
    no_change_allowed = 3
    no_authority      = 4.
IF sy-subrc <> 0 .
  WRITE: / 'text modify failed:' COLOR COL_NEGATIVE, sy-subrc COLOR COL_TOTAL.
  RETURN.
ENDIF.

APPEND lv_guid TO lt_objects_to_save.
CALL FUNCTION 'CRM_ORDER_SAVE'
  EXPORTING
    it_objects_to_save   = lt_objects_to_save
    iv_update_task_local = abap_true
  IMPORTING
    et_saved_objects     = lt_saved_objects
    et_objects_not_saved = lt_objects_not_saved
  EXCEPTIONS
    document_not_saved   = 1
    OTHERS               = 2.

IF sy-subrc EQ 0 AND lt_saved_objects IS NOT INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = abap_true.
  WRITE: / 'text changed successfully' COLOR COL_NEGATIVE.
ELSE.
  WRITE: / 'text changed failed' COLOR COL_POSITIVE.
ENDIF.

BREAK-POINT.

这段 SAP ABAP 代码的作用是批改 CRM 订单的文本。该程序蕴含了以下性能:

  1. 定义输出参数 idtypelantdid,别离示意 CRM 订单的对象 ID、解决类型、语言和文本 ID。
  2. 定义类型 text_line 示意文本行。
  3. 定义变量 lv_char32lv_idlv_guid 别离示意长度为 32 的字符、对象 ID 和对象 GUID。定义变量 ls_return 示意返回的音讯。
  4. 定义表类型 lt_lines 示意文本行,定义变量 ls_linelt_lines 的行类型。
  5. 定义表类型 lt_objects_to_savelt_objects_not_savedlt_saved_objects,别离示意待保留的对象、未保留的对象和保留胜利的对象。
  6. 将输出的 id 转换为字符类型。
  7. crmd_orderadm_h 表中查问指定的 CRM 订单,并获取其 GUID。
  8. 定义变量 lt_text 示意文本内容,变量 ls_text 示意文本行。
  9. 将文本行的属性赋值并增加到文本表中。
  10. 定义变量 ls_input_fields 示意输出字段,变量 lv_logical_key 示意逻辑键,变量 ls_field_names 示意字段名。将这些变量赋值后增加到输出字段表中。
  11. 调用函数模块 CRM_ORDER_MAINTAIN,向 CRM 订单中增加文本内容。
  12. 将批改后的对象 GUID 增加到待保留对象表 lt_objects_to_save 中。
  13. 调用函数模块 CRM_ORDER_SAVE,保留批改后的 CRM 订单。
  14. 判断保留是否胜利,如果胜利则调用函数模块 BAPI_TRANSACTION_COMMIT 提交事务。
  15. 设置断点以便调试。

总体来说,这段代码的作用是批改指定 CRM 订单的文本内容,并保留批改后的后果。

退出移动版