SAP Query for getting hourly background job status

...Previous 

  1. Go to Code tab. In the DATA section, write the following code:
DATA : FLAG(1),
       FLAG1(1),
       FLAG2(1),
       status(15).
DATA: begin of gt_TBTCO occurs 0,
        JOBNAME   type TBTCO-JOBNAME,
        SDLSTRTDT type TBTCO-SDLSTRTDT,
        SDLSTRTTM type TBTCO-SDLSTRTTM,
        ENDTIME   type TBTCO-ENDTIME,
        STATUS    type TBTCO-STATUS.
DATA: end of gt_TBTCO.
DATA: begin of gt_TBTCO1 occurs 0,
        JOBNAME   type TBTCO-JOBNAME,
        SDLSTRTDT type TBTCO-SDLSTRTDT,
        SDLSTRTTM type TBTCO-SDLSTRTTM,
        ENDTIME   type TBTCO-ENDTIME,
        stat(15).
DATA: end of gt_TBTCO1.
DATA: begin of gt_TBTCO2 occurs 0,
        JOBNAME   type TBTCO-JOBNAME,
        SDLSTRTDT type TBTCO-SDLSTRTDT,
        SDLSTRTTM type TBTCO-SDLSTRTTM,
        ENDTIME  type TBTCO-ENDTIME,
        stat(15).
DATA: end of gt_TBTCO2.
DATA : gt_tbtco3 like gt_tbtco occurs 0 with header line.
DATA : gt_tbtco4 like gt_tbtco occurs 0 with header line.
d.	In the START-OF-SELECTION section, write the following code:
select JOBNAME
       SDLSTRTDT
       SDLSTRTTM
       ENDTIME
       STATUS
       from TBTCO
       into corresponding fields of table gt_tbtco3
       where jobname in s_jobnam
       and status = 'P'.
refresh gt_tbtco[].
clear   gt_tbtco[].
select JOBNAME
       SDLSTRTDT
       SDLSTRTTM
       ENDTIME
       STATUS
       from TBTCO
       into corresponding fields of table gt_tbtco
       where jobname   in s_jobnam
       and   SDLSTRTDT in s_strtdt.
check sy-subrc = 0.
sort gt_tbtco by JOBNAME SDLSTRTTM.
gt_tbtco4[] = gt_tbtco[].
delete gt_tbtco where ENDTIME < P_ENDTIM
and ( status = 'F' or status = 'A' ).
sort gt_tbtco by JOBNAME SDLSTRTTM.
Loop at gt_tbtco.
at new jobname.
flag = 'X'.
endat.
if flag = 'X'.
MOVE-CORRESPONDING gt_tbtco to gt_tbtco1.
if gt_tbtco-status = 'F' .
if ( gt_tbtco-SDLSTRTTM le P_ENDTIM ) .
gt_tbtco1-stat = 'Active'.
append gt_tbtco1.
clear  gt_tbtco1.
else.
gt_tbtco1-stat = 'Released'.
append gt_tbtco1.
clear  gt_tbtco1.
endif.
elseif gt_tbtco-status = 'F' and gt_tbtco-SDLSTRTTM ge P_ENDTIM.
gt_tbtco1-stat = 'Cancelled'.
append gt_tbtco1.
clear  gt_tbtco1.
else.
status = gt_tbtco-status.
case status.
when 'R'.
if ( gt_tbtco-SDLSTRTTM le P_ENDTIM ) .
gt_tbtco1-stat = 'Active'.
else.
gt_tbtco1-stat = 'Released'.
endif.
when 'Z'.
gt_tbtco1-stat = 'Suspended'.
when 'A'.
gt_tbtco1-stat = 'Cancelled'.
when 'P'.
gt_tbtco1-stat = 'Scheduled'.
when 'S'.
gt_tbtco1-stat = 'Released'.
when 'Y'.
gt_tbtco1-stat = 'Released'.
endcase.
append gt_tbtco1.
clear  gt_tbtco1.
endif.
endif.
CLEAR FLAG.
clear status.
endloop.
sort gt_tbtco1 by jobname.
sort gt_tbtco3 by jobname.
Loop at s_jobnam.
read table gt_tbtco1 with key jobname = s_jobnam-low.
if sy-subrc = 0.
flag1 = 'X'.
move-corresponding gt_tbtco1 to gt_tbtco2.
append gt_tbtco2.
clear  gt_tbtco2.
else.
read table gt_tbtco3 with key jobname = s_jobnam-low.
if sy-subrc = 0.
flag2 = 'X'.
move-corresponding gt_tbtco3 to gt_tbtco2.
gt_tbtco2-stat = 'Scheduled'.
append gt_tbtco2.
clear  gt_tbtco2.
else.
read table gt_tbtco4 with key jobname = s_jobnam-low.
if sy-subrc = 0.
flag2 = 'X'.
move-corresponding gt_tbtco4 to gt_tbtco2.
if gt_tbtco4-status = 'F'.
gt_tbtco2-stat = 'Finished'.
else.
gt_tbtco2-stat = 'Canceled'.
endif.
append gt_tbtco2.
clear  gt_tbtco2.
endif.
endif.
endif.
if flag1 <> 'X' and flag2 <> 'X'.
gt_tbtco2-jobname = s_jobnam-low.
gt_tbtco2-stat = 'Not Scheduled'.
append gt_tbtco2.
clear  gt_tbtco2.
endif.
clear : flag1,flag2.
endloop.
if not gt_tbtco2[] is Initial.
* Display List of Cases to be Cancelled
CALL FUNCTION 'RS_COMPLEX_OBJECT_EDIT'
  EXPORTING
    object_name                = 'RESULTS'
  changing
    object                     = GT_TBTCO2[]
 EXCEPTIONS
   OBJECT_NOT_SUPPORTED       = 1
   OTHERS                     = 2.
endif.
EXIT.

Click here to continue....

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image