In my project I need to create new service request by code with its subject data filled.
As a result I need to figure out how to fill the required data by calling function module CRM_ORDER_MAINTAIN. I share my code here in case you have the same requirement.
First of all you should already have a well-maintained Categorization Schema in Service Operation Work center:
In Application Areas assignment block, this schema must have corresponding combination of Transaction type and Catalog Category maintained.
In my example above,“Service Request / Defect Locations/Object Parts”just represents the following customizing:
Just specify the schema ID and category ID you would like to fill for the created Service Request:
We only need to specify a single category ID in our code, and all its parent node in the schema tree could automatically be filled as expected by WebUI.
Source code:
REPORT order_create_subject.
PARAMETERS: asp_id TYPE crmt_srv_subject_com-asp_id OBLIGATORY DEFAULT 'WJ_SOFTWARE',
cat_id TYPE crmt_srv_subject_com-cat_id OBLIGATORY DEFAULT 'CA_13',
cat_type TYPE crmt_srv_subject_com-katalog_type OBLIGATORY DEFAULT 'D'.
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,
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_saved LIKE LINE OF lt_saved,
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 = asp_id.
ls_subject-katalog_type = cat_type.
ls_subject-cat_id = cat_id.
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.
要获取更多 Jerry 的原创文章,请关注公众号 ” 汪子熙 ”: