Created by Jerry Wang, last modified on Jan 06, 2015
执行report,输入如下参数:
A代表 text determination procedure 取customizing里第一个change type为A的entry:
执行完毕后打印成功创建text message:
可到UI上查看成功创建的text:
source code如下:
REPORT ztool_text_create. PARAMETERS: id TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '1767', type TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'ROPP', change TYPE char1 OBLIGATORY DEFAULT 'A', content TYPE string OBLIGATORY LOWER CASE DEFAULT 'test'. DATA: lt_guid_list TYPE crmt_bsp_objectkey_tab. DATA: lt_objects_to_save TYPE crmt_object_guid_tab. DATA: lt_objects_not_saved TYPE crmt_object_guid_tab. TYPES: text_line(cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength) TYPE c. DATA: lt_text_table TYPE TABLE OF text_line. DATA: ls_text TYPE crmt_text_com. DATA: lt_text TYPE crmt_text_comt. DATA: ls_log_key_text_int TYPE crmst_text_log_int_key. DATA: ls_input_fields TYPE crmt_input_field. DATA: lv_logical_key TYPE crmt_logical_key. DATA: ls_field_names TYPE crmt_input_field_names. DATA: lv_note TYPE string. DATA: lt_orderadmh TYPE crmt_orderadm_h_comt. DATA: lt_input_fields TYPE crmt_input_field_tab. DATA: ls_input_field TYPE crmt_input_field. DATA: lt_input_field_names TYPE crmt_input_field_names_tab. DATA: ls_input_field_names TYPE crmt_input_field_names. DATA: lr_busi_exception TYPE REF TO /iwbep/cx_mgw_busi_exception. DATA: lt_saved_objects TYPE crmt_return_objects. DATA: lv_tdid TYPE tdid. DATA: ls_notes TYPE crmt_odata_oppt_notes. DATA: lv_temp TYPE CHAR3. CONSTANTS: BEGIN OF cs_change_type, display type char1 VALUE 'C', log TYPE char1 value 'P', paste TYPE char1 value 'A', END OF cs_change_type. INITIALIZATION. lv_temp = cs_change_type. FORM get_guid USING iv_id LIKE id iv_type LIKE type CHANGING cv_guid TYPE crmd_orderadm_h-guid. SELECT SINGLE guid FROM crmd_orderadm_h INTO cv_guid WHERE object_id = iv_id AND process_type = iv_type. ENDFORM. FORM get_text_determine_id USING iv_process_type TYPE crmt_process_type iv_change TYPE char1 CHANGING cv_id TYPE tdid. DATA: lv_text_procedure TYPE comt_text_det_procedure. DATA: lt_text TYPE STANDARD TABLE OF comc_text_pd. DATA: ls_text TYPE comc_text_pd. SELECT SINGLE text_procedure INTO lv_text_procedure FROM crmc_proc_type WHERE process_type = iv_process_type AND object_type = cl_crm_odata_oppt_constant=>gc_oppt_bus_object. CHECK sy-subrc EQ 0. SELECT object textprocedure textid seqno changeable INTO CORRESPONDING FIELDS OF TABLE lt_text FROM comc_text_pd WHERE object = cl_crm_odata_oppt_constant=>gc_oppt_notes_tdobject AND textprocedure = lv_text_procedure AND changeable = iv_change. CHECK sy-subrc EQ 0. SORT lt_text BY seqno. READ TABLE lt_text INTO ls_text INDEX 1. IF sy-subrc EQ 0. cv_id = ls_text-textid. ENDIF. ENDFORM. START-OF-SELECTION. IF NOT ( change CA lv_temp ). WRITE:/ 'Invalid change type: ', change COLOR COL_NEGATIVE. RETURN. ENDIF. PERFORM get_guid USING id type CHANGING ls_notes-header_guid. PERFORM get_text_determine_id USING type change CHANGING lv_tdid. ls_notes-content = content. APPEND ls_notes-header_guid TO lt_objects_to_save. APPEND ls_notes-header_guid TO lt_guid_list. CLEAR lt_input_field_names. ls_input_field_names-fieldname = 'LINES'. APPEND ls_input_field_names TO lt_input_field_names. CLEAR ls_input_field_names. ls_input_field_names-fieldname = 'TDFORM'. APPEND ls_input_field_names TO lt_input_field_names. CLEAR ls_input_field_names. ls_input_field_names-fieldname = 'TDID'. APPEND ls_input_field_names TO lt_input_field_names. CLEAR ls_input_field_names. ls_input_field_names-fieldname = 'TDSPRAS'. APPEND ls_input_field_names TO lt_input_field_names. CLEAR ls_input_field_names. ls_input_field_names-fieldname = 'TDSTYLE'. APPEND ls_input_field_names TO lt_input_field_names. CLEAR ls_input_field_names. ls_text-ref_handle = '0000000000'. ls_text-ref_guid = ls_notes-header_guid. ls_text-ref_kind = 'A'. ls_text-tdid = lv_tdid. ls_text-tdspras = sy-langu. ls_text-mode = 'A'. lv_note = ls_notes-content. DO. APPEND lv_note TO lt_text_table[]. SHIFT lv_note BY cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength PLACES LEFT. IF ( lv_note IS INITIAL ). EXIT. ENDIF. ENDDO. CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT' EXPORTING language = sy-langu * LF = ' ' TABLES text_stream = lt_text_table itf_text = ls_text-lines. CLEAR ls_input_fields. ls_input_fields-ref_guid = ls_notes-header_guid. ls_input_fields-ref_kind = 'A'. ls_input_fields-objectname = 'TEXTS'. ls_log_key_text_int-tdid = ls_text-tdid. ls_log_key_text_int-tdspras = ls_text-tdspras. lv_logical_key = ls_log_key_text_int. ls_input_fields-logical_key = lv_logical_key. CLEAR ls_input_fields-field_names. APPEND LINES OF lt_input_field_names TO ls_input_fields-field_names. INSERT ls_input_fields INTO TABLE lt_input_fields. APPEND ls_text TO lt_text. CLEAR ls_text. CALL FUNCTION 'CRM_ORDER_MAINTAIN' EXPORTING it_text = lt_text CHANGING ct_orderadm_h = lt_orderadmh ct_input_fields = lt_input_fields EXCEPTIONS error_occurred = 1 document_locked = 2 no_change_allowed = 3 no_authority = 4 OTHERS = 5. ASSERT sy-subrc EQ 0. 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. ASSERT sy-subrc EQ 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true. WRITE: / 'Text created successfully'.