Sunday, February 6, 2011

SAP Query for getting hourly background job status

This SAP query is designed to get the hourly background job status updates, which are running in production.

Step 1: Create user group.

a. Using t-code SQ03, create one user group ZPROD_BEJ (Jayanta Bej's User Group).

b. Assign user ids to this user group.

Step 2: Create infoset.

  1. Using t-code SQ02, create one infoset BATCH_JOBLIST_REPORT with the direct read from the table TBTCO and including key field only.

  1. Add two selection criterion S_JOBNAM (Job Name) & S_STRTDT (Start Date) and one parameter P_ENDTIM (Time) in the Selections tab.

Details: S_JOBNAM.

Details: S_STRTDT.

Details: P_ENDTIM.


  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.

Generate the infoset and then attach it to the user group ZPROD_BEJ.

Step 3: Create the query.

Using t-code SQ01, create one query BATCH_JOBLIST for the infoset BATCH_JOBLIST_REPORT.

Step 4: Execute the query from SQ01 with proper variant for the list of background jobs whose hourly status needs to be found out.

Select the variant. Suppose we want to find out the background status at 2 PM for the below list of jobs:

PROC_CHGPNTRS_ENERGYCARE
PROCESS_CP_ACTIVITY
PROCESS_CP_CONTACT
PROCESS_CP_CONTRACT
PROCESS_CP_SALESORDER
PROCESS_IDOC_IN_ACTIVITY
PROCESS_IDOC_IN_ADDRSYNCH
PROCESS_IDOC_IN_BPCAMERGE
PROCESS_IDOC_IN_OAMUPDATE
PROCESS_IDOC_IN_PARTNRUPD
PROCESS_IDOC_IN_PREPAY
PROCESS_IDOC_IN_SALESORDR
PROCESS_IDOC_OUT_ACTIVITIES
PROCESS_IDOC_OUT_AQSND0055
PROCESS_IDOC_OUT_CONTACTS
PROCESS_IDOC_OUT_CONTRACT
PROCESS_IDOC_OUT_OBJSD0064
PROCESS_IDOC_OUT_SOSTATUS
PROCESS_CP_FILES
PROCESS_IDOC_OUT_FILES
SWWERRE
SWEQSRV
SWWDHEX
ZUBC_DELETE_WORKITEMS
ZZ_IDOC_DISPATCH
Z_APP_LOG_DEL_DAILY
ZUBC_DELETE_IDOCS
EMMA_AUTOPROC_SB61
ZUUBI_REPLACEMENT_BILLING_01
ZUBC_DELETE_APP_LOGS
SAP_ARCH_RETHIST
SAP_ARCH_PAYLOTS
SAP_ARCH_RETLOTS
SAP_APURG_MDR1

Put all these job names in the select option for job name. In the variant, the date should be equal to current date and time should be current time and should be done as follows:

Now selecting the variant JOBLIST (JOB LIST STATUS), execute the query.

Now we execute the query. The following report will be displayed.

This is the status update of all the listed background jobs for the hour 14 i.e. 2 PM.


No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites