Copy Jobs Program
Copy Jobs Program
Copy Jobs Program
INCLUDE lbtchdef.
DATA:
jobs TYPE TABLE OF tbtcjob,
new_jobs TYPE TABLE OF t_job,
is_btc_admin TYPE boolean VALUE abap_undefined.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN SKIP 1.
*----------------------------------------------------------------------*
* CLASS lcl_rep DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_rep DEFINITION FINAL.
PUBLIC SECTION.
*----------------------------------------------------------------------*
* CLASS lcl_rep IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_rep IMPLEMENTATION.
METHOD translate_status.
CASE iv_status.
WHEN 'A'.
rv_statusname = 'aborted'(081).
WHEN 'F'.
rv_statusname = 'finished'(082).
WHEN 'S'.
rv_statusname = 'relased'(080).
WHEN 'R'.
rv_statusname = 'active'(077).
WHEN 'P'.
rv_statusname = 'scheduled'(079).
WHEN 'Y'.
rv_statusname = 'ready'(078).
WHEN 'Z'.
rv_statusname = 'suspended'(748).
WHEN OTHERS.
rv_statusname = 'unkown'(749).
ENDCASE.
ENDMETHOD. "translate_status
INITIALIZATION.
text_079 = 'scheduled'(079).
text_080 = 'relased'(080).
text_081 = 'aborted'(081).
text_082 = 'finished'(082).
IF is_btc_admin = abap_undefined.
AUTHORITY-CHECK OBJECT 'S_BTCH_ADM'
ID 'BTCADMIN' FIELD btc_yes.
IF sy-subrc <> 0.
is_btc_admin = abap_false.
MESSAGE s212(wz).
ELSE.
is_btc_admin = abap_true.
ENDIF.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'TEST' AND is_btc_admin = abap_false.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = '1A'.
IF test = 'X'.
screen-input = '0'.
MODIFY SCREEN.
ELSE.
screen-input = '1'.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN ON dest.
START-OF-SELECTION.
PERFORM select_jobs.
IF lines( jobs ) > 0.
IF test IS INITIAL.
PERFORM connect.
ENDIF.
PERFORM copy_jobs.
PERFORM disconnect.
PERFORM show_jobs.
ENDIF.
*&--------------------------------------------------------------------*
*& Form select_jobs
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM select_jobs.
selection-jobname = names.
selection-username = user.
selection-from_date = frodate.
selection-from_time = frotime.
selection-to_date = todate.
selection-to_time = totime.
selection-prelim = prelim.
selection-schedul = schedul.
* selection-ready = ready.
* selection-running = running.
selection-finished = finished.
selection-aborted = aborted.
selection-eventid = event.
ENDFORM. "select_jobs
*&--------------------------------------------------------------------*
*& Form connect
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->P_DEST text
* -->P_RC text
*---------------------------------------------------------------------*
FORM connect.
IF sy-subrc <> 0.
MESSAGE e645 WITH rfc_msg.
ENDIF.
IF ret-type = 'E'.
PERFORM print_message USING ret-number
ret-message_v1 ret-message_v2 ret-message_v3 ret-message_v4
CHANGING txt.
MESSAGE e645 WITH txt.
ENDIF.
ENDFORM. "connect
*&--------------------------------------------------------------------*
*& Form copy_jobs
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM copy_jobs.
CLEAR new_jobs.
LOOP AT jobs INTO ls_job.
CLEAR new_job.
IF test IS INITIAL.
IF new_job-errmessage IS INITIAL.
ADD 1 TO stepno.
CLEAR priparkey.
IF ls_step-xpgpid IS INITIAL.
SELECT SINGLE priparkey FROM tbtcp INTO priparkey
WHERE jobname EQ ls_job-jobname AND
jobcount EQ ls_job-jobcount AND
stepcount EQ stepno.
CALL FUNCTION 'LOAD_PRINT_PARAMETERS'
EXPORTING
key = priparkey
IMPORTING
out_parameters = all_params
key_found = found
EXCEPTIONS
error_occured = 1
OTHERS = 2.
IF sy-subrc <> 0 OR found IS INITIAL.
MOVE-CORRESPONDING ls_step TO allpripar.
MOVE-CORRESPONDING ls_step TO allarcpar.
ELSE.
MOVE-CORRESPONDING all_params TO allpripar.
MOVE-CORRESPONDING all_params TO allarcpar.
ENDIF.
IF sy-subrc <> 0.
new_job-errmessage = rfc_msg.
ELSE.
IF ret-type = 'E'.
PERFORM print_message USING ret-number
ret-message_v1 ret-message_v2 ret-message_v3 ret-message_v4
CHANGING txt.
new_job-errmessage = txt.
ENDIF.
ENDIF.
IF new_job-errmessage IS INITIAL.
new_job-new_client = ls_jobhead-authckman.
IF ls_job-status = btc_released.
CLEAR new_header.
MOVE-CORRESPONDING new_job TO new_header.
mask-startcond = 'X'.
CLEAR mask-thost.
CLEAR mask-tserver.
CLEAR mask-tsrvgrp.
CLEAR mask-reciplnt.
DATA:
old_stdt_data TYPE tbtcjob,
stdt_data TYPE tbtcstrt.
ENDIF.
ENDLOOP.
ENDFORM. "copy_jobs
*&--------------------------------------------------------------------*
*& Form print_message
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->MSGID text
* -->ARG1 text
* -->ARG2 text
* -->ARG3 text
* -->ARG4 text
* -->MESSAGE text
*---------------------------------------------------------------------*
FORM print_message
USING
msgid TYPE bapiret2-number
arg1 TYPE bapiret2-message_v1
arg2 TYPE bapiret2-message_v1
arg3 TYPE bapiret2-message_v1
arg4 TYPE bapiret2-message_v1
CHANGING
message TYPE sxmimsgext.
DATA:
p_message TYPE sxmimsgraw.
p_message-msgclass = 'SAP-T100'.
CONCATENATE 'XM' msgid INTO p_message-msgid SEPARATED BY space.
p_message-msgarg1 = arg1.
p_message-argtype1 = 'C'.
p_message-msgarg2 = arg2.
p_message-argtype2 = 'C'.
p_message-msgarg3 = arg3.
p_message-argtype3 = 'C'.
p_message-msgarg4 = arg4.
p_message-argtype4 = 'C'.
ENDFORM. "print_message
*&---------------------------------------------------------------------*
*& Form SHOW_JOBS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM show_jobs .
DATA: gr_table TYPE REF TO cl_salv_table,
* lr_selections TYPE REF TO cl_salv_selections,
lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column_table.
DATA l_ltxt TYPE scrtext_l.
DATA l_mtxt TYPE scrtext_m.
DATA l_stxt TYPE scrtext_s.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = new_jobs ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
lr_columns = gr_table->get_columns( ).
lr_columns->set_optimize( abap_true ).
TRY.
lr_column ?= lr_columns->get_column( 'OLD_JOBCOUNT' ).
lr_column->set_short_text( l_stxt ).
l_mtxt = 'original jobcount'(001) ##TEXT_DIFF.
lr_column->set_medium_text( l_mtxt ).
l_ltxt = l_mtxt.
lr_column->set_long_text( l_ltxt ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column ?= lr_columns->get_column( 'NEW_JOBCOUNT' ).
lr_column->set_short_text( l_stxt ).
l_mtxt = 'new jobcount'(002) ##TEXT_DIFF.
lr_column->set_medium_text( l_mtxt ).
l_ltxt = l_mtxt.
lr_column->set_long_text( l_ltxt ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column ?= lr_columns->get_column( 'OLD_CLIENT' ).
lr_column->set_short_text( l_stxt ).
l_mtxt = 'original client'(017) ##TEXT_DIFF.
lr_column->set_medium_text( l_mtxt ).
l_ltxt = l_mtxt.
lr_column->set_long_text( l_ltxt ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column ?= lr_columns->get_column( 'NEW_CLIENT' ).
lr_column->set_short_text( l_stxt ).
l_mtxt = 'new client'(018) ##TEXT_DIFF.
lr_column->set_medium_text( l_mtxt ).
l_ltxt = l_mtxt.
lr_column->set_long_text( l_ltxt ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column ?= lr_columns->get_column( 'SDLSTRTDT' ).
lr_column->set_short_text( l_stxt ).
l_mtxt = 'Start date'(015) ##TEXT_DIFF.
lr_column->set_medium_text( l_mtxt ).
l_ltxt = l_mtxt.
lr_column->set_long_text( l_ltxt ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column ?= lr_columns->get_column( 'SDLSTRTTM' ).
lr_column->set_short_text( l_stxt ).
l_mtxt = 'Start time'(016) ##TEXT_DIFF.
lr_column->set_medium_text( l_mtxt ).
l_ltxt = l_mtxt.
lr_column->set_long_text( l_ltxt ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
gr_table->display( ).