Code:
METHOD is_tp_running.
*
* include LSTPACON.
INCLUDE /tmwflow/transport_constants.
DATA lv_system TYPE tmssysnam.
DATA lv_domain TYPE tmsdomnam.
DATA lv_smsy_domain TYPE smsy_tmsdom.
DATA lv_flex_active TYPE flag.
DATA lt_requests TYPE /tmwflow/trordec_type.
DATA lt_tpstats TYPE tpstats.
DATA ls_sap_system TYPE smsy_system_sap.
DATA lv_long_sid TYPE sysysid.
DATA lv_short_sid TYPE sysysid.
DATA ls_track TYPE /tmwflow/ttrckec.
DATA lt_sys TYPE TABLE OF tmscsys.
DATA ls_tp_logtabs TYPE stms_tp_logtabs.
DATA ls_tp_logtab TYPE stms_tp_logtab.
DATA ls_tpstat TYPE tpstat.
DATA lv_request_id TYPE if_cts_transport_entity=>ty_id.
DATA lt_coll_id TYPE if_cts_transport_entity=>ty_ids.
DATA ls_result TYPE cl_cts_transport_factory=>ty_import_status.
DATA lt_results TYPE cl_cts_transport_factory=>ty_import_statuses.
DATA lt_coll TYPE if_cts_transport_collection=>ty_collections.
DATA lo_request TYPE REF TO if_cts_transport_request.
DATA lo_coll TYPE REF TO if_cts_transport_collection.
DATA lo_system TYPE REF TO if_cts_system.
DATA lo_system_cluster TYPE REF TO if_cts_system_collection.
FIELD-SYMBOLS:
<fs_request> TYPE /tmwflow/trordec,
<fs_tpstat> TYPE tpstat.
APPEND LINES OF it_requests_imp TO lt_requests.
APPEND LINES OF it_requests_nimp TO lt_requests.
SORT lt_requests BY trorder_number.
DELETE ADJACENT DUPLICATES FROM lt_requests COMPARING trorder_number.
"SMSY uses Long SID.
lv_long_sid = iv_logical_system-sysname.
CALL FUNCTION '/TMWFLOW/GET_SYSTEM_TMS_INFO'
EXPORTING
iv_sysname = lv_long_sid
* iv_refresh = ' '
IMPORTING
es_tmsdom = lv_smsy_domain
ev_tms_syssid = lv_short_sid
EXCEPTIONS
unknown_system = 1
get_tms_info_err = 2
OTHERS = 3.
IF sy-subrc <> 0.
ev_running = abap_true.
RETURN.
ENDIF.
lv_system = lv_short_sid.
lv_domain = lv_smsy_domain-tmsdomnam.
*--------------------------------------------------------------------*
* Use different api for flex enabled or not enabled project
lv_flex_active = /tmwflow/cl_transport_util=>is_change_man_flex_active(
iv_project_id = iv_solman_project ).
IF lv_flex_active = abap_true.
/tmwflow/cl_transport_util=>get_cluster_for_system(
EXPORTING
iv_system = lv_system
iv_client = iv_logical_system-client
iv_project = iv_solman_project
iv_role_type = ''
RECEIVING
rs_track = ls_track ).
TRY.
lo_system = cl_cts_landscape_factory=>get_system(
system_name = lv_system
domain_name = lv_domain
client = iv_logical_system-client ).
lo_system_cluster = cl_cts_landscape_factory=>get_system_collection(
system_collection_name = ls_track-transp_cluster
domain_name = ls_track-transp_domain ).
LOOP AT lt_requests ASSIGNING <fs_request>.
lv_request_id = <fs_request>-trorder_number.
lo_request ?= cl_cts_transport_factory=>get_transport_entity(
id = lv_request_id
source_system = lo_system ).
lt_coll = lo_request->get_collections( ).
LOOP AT lt_coll INTO lo_coll.
APPEND lo_coll->get_id( ) TO lt_coll_id.
ENDLOOP.
ENDLOOP.
SORT lt_coll_id.
DELETE ADJACENT DUPLICATES FROM lt_coll_id.
lt_results = cl_cts_transport_factory=>get_import_status(
entity_ids = lt_coll_id
system = lo_system_cluster ).
CATCH cx_cts_exception.
ev_running = abap_true.
RETURN.
ENDTRY.
LOOP AT lt_results INTO ls_result
WHERE status = cl_cts_transport_factory=>co_imp_status_import_running.
ev_running = abap_true.
RETURN.
ENDLOOP.
RETURN.
ENDIF.
CHECK lv_flex_active = abap_false.
*--------------------------------------------------------------------*
* only if domain link is configured, we can get TP status in TMS API.
* otherwise we do not check TP status and assume TP is running.
*
* we could enhance it when we have developed Remote API in managed
* system to judge TP status.
*--------------------------------------------------------------------*
* get TPSTAT entries, embed logic from 'TMS_IMU_FILTER_TPSTAT'
CALL FUNCTION 'TMS_MGR_READ_TP_LOGTAB'
EXPORTING
iv_system = lv_system
iv_domain = lv_domain
iv_read_tpstat = gc_x
iv_monitor = space
iv_verbose = space
IMPORTING
es_tp_logtabs = ls_tp_logtabs
EXCEPTIONS
OTHERS = 99.
IF sy-subrc <> 0.
ev_running = abap_true.
RETURN. " no check of TP status.
ENDIF.
LOOP AT ls_tp_logtabs INTO ls_tp_logtab.
LOOP AT ls_tp_logtab-tpstat INTO ls_tpstat.
*filter from export commands
CHECK ls_tpstat-command(1) <> 'E' AND
ls_tpstat-command+2(1) <> 'E'.
APPEND ls_tpstat TO lt_tpstats.
ENDLOOP.
ENDLOOP.
DELETE lt_tpstats WHERE command <> 'IMPORT'.
SORT lt_tpstats BY trkorr tarcli.
LOOP AT lt_requests ASSIGNING <fs_request>
WHERE status <> gc_import_finished OR
status <> gc_import_warning.
* there can be more than one entry
LOOP AT lt_tpstats TRANSPORTING NO FIELDS
WHERE trkorr = <fs_request>-trorder_number
AND ( tarcli = iv_logical_system-client OR
tarcli IS INITIAL ) "for 46C system we cannot get the client info
AND ( status = 'N' OR "gc_tp_stat_new or
status = 'R' ). "gc_tp_stat_running ).
ev_running = abap_true.
RETURN. "one is enough!
ENDLOOP.
ENDLOOP.
ENDMETHOD.