
REPORT zcopy_tr_objects.
TABLES:e071.
TYPES: BEGIN OF ty_output,
tr_no TYPE trkorr,
reason(60) TYPE c,
END OF ty_output.
**Internal Tables
DATA: tb_tr_object TYPE STANDARD TABLE OF ko200,
tb_output TYPE STANDARD TABLE OF ty_output.
**Workareas
DATA: wa_tr_object TYPE ko200,
wa_output TYPE ty_output,
gs_request TYPE trwbo_request.
**Workfields
DATA: wf_subrc TYPE sysubrc,
wf_title TYPE lvc_title.
**Objects
DATA:gr_alv TYPE REF TO cl_salv_table,
gr_columns TYPE REF TO cl_salv_columns_table,
obj_header TYPE REF TO cl_salv_form_layout_grid,
obj_label TYPE REF TO cl_salv_form_label,
wf_functions TYPE REF TO cl_salv_functions_list,
wf_column TYPE REF TO cl_salv_column_table.
CLEAR: tb_tr_object, tb_output,
wa_tr_object, wa_output, gs_request,
gr_alv, gr_columns, obj_header, obj_label,
wf_subrc, wf_title, wf_functions, wf_column.
**Selection Screen
SELECT-OPTIONS: s_trlist FOR e071-trkorr.
PARAMETERS: pa_trdst TYPE trkorr.
**Defining ranges for the selection screen
DATA: wa_trlist LIKE LINE OF s_trlist,
ra_trlist TYPE RANGE OF trkorr.
**DATA: e_t_msg TYPE rs_t_msg,
** e_request TYPE trkorr.
AT SELECTION-SCREEN.
IF s_trlist IS INITIAL.
MESSAGE 'Pleaes enter the TR/Tasks' TYPE 'E'.
ENDIF.
IF pa_trdst IS INITIAL.
MESSAGE 'The destination TR is mandatory' TYPE 'E'.
ENDIF.
**Place a special check here with popup confirming that
**the tasks have to be copied
START-OF-SELECTION.
CLEAR wa_trlist.
LOOP AT s_trlist INTO wa_trlist.
IF wa_trlist-low IS NOT INITIAL AND
wa_trlist-high IS NOT INITIAL.
DATA(wf_option) = 'BT'.
ELSE.
wf_option = 'EQ'.
ENDIF.
APPEND VALUE #( sign = 'I'
option = wf_option
low = wa_trlist-low
high = wa_trlist-high ) TO ra_trlist.
CLEAR wa_trlist.
ENDLOOP.
SELECT * FROM e071
INTO TABLE @DATA(tb_e071)
WHERE trkorr IN @ra_trlist.
IF sy-subrc IS INITIAL.
SORT tb_e071 BY trkorr.
DATA(tb_e071_temp) = tb_e071.
DELETE ADJACENT DUPLICATES FROM tb_e071_temp COMPARING trkorr.
ENDIF.
LOOP AT tb_e071_temp ASSIGNING FIELD-SYMBOL(<fs_e071_temp>).
CALL FUNCTION 'ENQUEUE_E_TRKORR'
EXPORTING
trkorr = <fs_e071_temp>-trkorr
EXCEPTIONS
foreign_lock = 1.
IF sy-subrc = 1.
CLEAR wa_output.
wa_output-tr_no = <fs_e071_temp>-trkorr.
CONCATENATE 'Request is currently being edited by' sy-uname INTO wa_output-reason
SEPARATED BY space.
APPEND wa_output TO tb_output.
CONTINUE.
ENDIF.
CLEAR: wa_tr_object,
tb_tr_object.
LOOP AT tb_e071 ASSIGNING FIELD-SYMBOL(<fs_e071>)
WHERE trkorr = <fs_e071_temp>-trkorr.
MOVE-CORRESPONDING <fs_e071> TO wa_tr_object.
APPEND wa_tr_object TO tb_tr_object.
CLEAR wa_tr_object.
ENDLOOP.
DELETE tb_tr_object WHERE pgmid = 'CORR'.
CLEAR gs_request.
gs_request-h-trkorr = <fs_e071_temp>-trkorr.
CALL FUNCTION 'TR_READ_REQUEST'
EXPORTING
iv_read_e070 = 'X'
iv_read_e07t = 'X'
iv_read_e070c = 'X'
iv_read_e070m = 'X'
iv_read_objs_keys = ' '
iv_read_attributes = ' '
CHANGING
cs_request = gs_request
EXCEPTIONS
error_occured = 1
OTHERS = 2.
IF sy-subrc <> 0.
CALL FUNCTION 'DEQUEUE_E_TRKORR'
EXPORTING
trkorr = <fs_e071_temp>-trkorr.
CLEAR wa_output.
wa_output-tr_no = <fs_e071_temp>-trkorr.
wa_output-reason = 'Request could not be read. Please check the TR status'.
APPEND wa_output TO tb_output.
CONTINUE.
ENDIF.
CALL FUNCTION 'TRINT_UNLOCK_REQUEST'
EXPORTING
iv_safe_mode = ' '
* iv_set_to_released = gs_setrel "if set, then this will release the task/TR given
* IMPORTING
* ev_cnt_removed_locks = lv_number "this will give the number of objects that the system has ulocked
CHANGING
cs_request = gs_request
EXCEPTIONS
db_access_error = 1
object_enqueues = 2
no_authority = 3
request_not_changeable = 4
OTHERS = 5.
IF sy-subrc <> 0.
CLEAR wa_output.
wa_output-tr_no = <fs_e071_temp>-trkorr.
wa_output-reason = 'Request could not be unlocked'.
APPEND wa_output TO tb_output.
CONTINUE.
ELSE.
CALL FUNCTION 'DEQUEUE_E_TRKORR'
EXPORTING
trkorr = <fs_e071_temp>-trkorr.
ENDIF.
**This FM will lock the objects
CALL FUNCTION 'RS_TR_WRITE_OBJECTS_TO_REQUEST'
EXPORTING
i_t_tr_object = tb_tr_object
i_request = pa_trdst
i_write_on_request = 'X'
IMPORTING
* e_t_msg = e_t_msg "this will log the messages in case of any error
e_subrc = wf_subrc.
"In case you do not pass any value in i_request, then system will ask
"for a new to be entered. That TR will be passed here.
* e_request = e_request.
IF wf_subrc IS NOT INITIAL.
CLEAR wa_output.
wa_output-tr_no = <fs_e071_temp>-trkorr.
wa_output-reason = 'Ojects of the Request could not be locked'.
APPEND wa_output TO tb_output.
CONTINUE.
ENDIF.
ENDLOOP.
END-OF-SELECTION.
IF tb_output IS INITIAL.
WRITE 'The TR/Tasks are successfully copied'.
ELSE.
*Call method to display the result
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = gr_alv
CHANGING t_table = tb_output ).
CATCH cx_salv_msg.
EXIT.
ENDTRY.
*Get Columns for the output table
gr_columns = gr_alv->get_columns( ).
*Changing the columns
* change_columns( im_alv = gr_alv ).
wf_functions = gr_alv->get_functions( ).
wf_functions->set_all( ).
CLEAR: wf_title.
wf_title = 'Task/TR whose objects could not be transferred to the destination TR'.
* Setting the top of page.
CREATE OBJECT obj_header.
obj_label = obj_header->create_label( row = 1 column = 1 ).
obj_label->set_text( wf_title ).
gr_alv->set_top_of_list( obj_label ).
** Set Column properties
TRY.
wf_column ?= gr_columns->get_column( 'TR_NO' ).
wf_column->set_output_length( 15 ).
wf_column->set_long_text( 'TR Number' ).
CATCH cx_salv_not_found.
EXIT.
ENDTRY.
TRY.
wf_column ?= gr_columns->get_column( 'REASON' ).
wf_column->set_output_length( 60 ).
wf_column->set_long_text( 'Reason' ).
CATCH cx_salv_not_found.
EXIT.
ENDTRY.
*Displaying the result
gr_alv->display( ).
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |