Maybe you know the problem - QA queue is full of old requests, nobody knows which one is relevant (sometimes the programmer isn't even working for your company any more). The answer is transport of copies! This way, you can test your programs in qa system without filling the qa queue with requests - when your program is working, you release the original request and import it in production.
Educating programmers is the next step. But how about automation? SAP delivers BAdI CTS_REQUEST_CHECK with method CHECK_BEFORE_RELEASE - just implement it and you can do various checks before releasing requests. First you have to check the transport type - just use a case condition:
CASE type. WHEN 'K' OR 'W'.
This way, only workbench and customizing requests are taken in account - the BAdI ignores everything else including tasks.
Creating transport of copies
First, you need a popup to decide whether changes are final:
CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING titlebar = 'Final?' text_question = 'Are your developments final?' text_button_1 = 'Final'(001) text_button_2 = 'ToC'(002) IMPORTING answer = lv_answer EXCEPTIONS text_not_found = 1 OTHERS = 2.
To create a new request, you can use FM TR_INSERT_REQUEST_WITH_TASKS:
CALL FUNCTION 'TR_INSERT_REQUEST_WITH_TASKS' EXPORTING iv_type = 'T' iv_text = lv_new_text iv_owner = owner iv_target = tarsystem IMPORTING es_request_header = lv_request_header et_task_headers = lv_task_headers EXCEPTIONS insert_failed = 1 enqueue_failed = 2 OTHERS = 3.
T stands for transport of copies, I create a new description with "[TvK] <old text>" to see which transport was created by BAdI. owner and tarsystem is taken from original request. Next step is to copy all objects:
CALL FUNCTION 'TR_COPY_COMM' EXPORTING wi_dialog = abap_false wi_trkorr_from = request wi_trkorr_to = lv_request_header-trkorr wi_without_documentation = abap_false EXCEPTIONS db_access_error = 1 trkorr_from_not_exist = 2 trkorr_to_is_repair = 3 trkorr_to_locked = 4 trkorr_to_not_exist = 5 trkorr_to_released = 6 user_not_owner = 7 no_authorization = 8 wrong_client = 9 wrong_category = 10 object_not_patchable = 11 OTHERS = 12.
TR_COPY_COMM copies all objects in background.
Releasing and importing the created transport
Next step is to release your request, ignoring object locks:
CALL FUNCTION 'TRINT_RELEASE_REQUEST' EXPORTING iv_trkorr = lv_request_header-trkorr iv_dialog = ' ' iv_without_locking = 'X' IMPORTING es_request = lv_request et_deleted_tasks = lt_deleted_tasks et_messages = lt_messages EXCEPTIONS cts_initialization_failure = 1 enqueue_failed = 2 no_authorization = 3 invalid_request = 4 request_already_released = 5 repeat_too_early = 6 object_lock_error = 7 object_check_error = 8 docu_missing = 9 db_access_error = 10 action_aborted_by_user = 11 export_failed = 12 execute_objects_check = 13 release_in_bg_mode = 14 release_in_bg_mode_w_objchk = 15 error_in_export_methods = 16 object_lang_error = 17 OTHERS = 18.
Other standard FMs don't ignore object locks, so you need TRINT_RELEASE_REQUEST with the option iv_without_locking.
Since adding to the target buffer can take some time, I advise to do a loop:
DO 5 TIMES. CALL FUNCTION 'TRINT_GET_LOG_OVERVIEW' EXPORTING iv_request = lv_request_header-trkorr iv_with_transport_targets = 'X' IMPORTING et_log_overview = lt_log_overview. lv_check = 0. LOOP AT lt_log_overview INTO wa_log_overview WHERE sysnam = '<sys>' AND rc = 'W'. ENDLOOP. IF sy-subrc = 0. lv_check = 1. ENDIF. IF lv_check = 1. EXIT. ENDIF. WAIT UP TO 1 SECONDS. ENDDO.
When everything is fine, you can import the created request:
CALL FUNCTION 'TMS_MGR_IMPORT_TR_REQUEST' EXPORTING iv_system = 'Q01' iv_request = lv_request_header-trkorr iv_ignore_cvers = 'X' iv_monitor = ' ' iv_verbose = ' ' IMPORTING ev_tp_ret_code = lv_trretcode es_exception = wa_exception EXCEPTIONS read_config_failed = 1 table_of_requests_is_empty = 2 OTHERS = 3.
Done!