Skip to end of metadata
Go to start of metadata

Author: Andrea Olivieri
Supported Releases: SAP ECC 6.0
Submitted: 20 September 2010

Code is presented in below pages:

  1. Job Steps Analysis - Get Report Name & Variant Name from periodic Scheduled Jobs
  2. Save Variant Data
  3. Variant Catalog Creation

General Flow and Pre-requisites

During a spin-off project of an Italian company in the automotive industry, the customer asked me to identify all the programs variants (of scheduled jobs) containing a defined value of company code ( i.e 'A001') in the selection screen.

In previous upgrade projects, basically for target release 4.70, I used a specific ASU tool, the restore variant tool,which allowed me to use the old variants again in the new release.

So I asked myself why should I have to implement a program from scratch if there is a standard one out there that does everything I need ?

So starting from the ASU variant restore tool, I cloned the source code of the following standard programs:

  • RASUVCAT: Creates a catalog of all variants
  • RASUVSAV: Storage of variant information

Since the goal is to identify job's variants containing the value A001 of the company code, I divided the process in the following operational steps:

  1. Get the program name and variant name from batch jobs
  2. Create Variant Catalog (For the specified program names)
  3. Save the variant Data (only parameters of type BUKRS)

Requirements

Function Groups ASU2,ASU4 as well as the DDIC Tables TASUVCAT, TASUVEXT, TASUVSVD and TASUNSVO should exist in the system

How It Works

1 - Job Steps analysis (Optional)

I focused exclusively on programs scheduled as periodic jobs, so I implemented an additional ABAP program which reads the job definitions of all jobs with the following states:

  • Scheduled
  • Released
  • Finished


After that, from the related steps, gets the following information:

  • Job name,
  • Program name,
  • Variant name
  • Package.

The output is a raw list.
Copy and paste the column program name from the output list in the selection screen parameter Report(s) of the Variant Catalog Creation program. The snippet of the job steps analysis program could be found here.

2 - Variant Catalog Creation (Mandatory)

Due to performance reasons, first of all you have to create the variant catalog; it's better to restrict the selection to certain reports. is filled .

As result, after the program update run, the TASUVCAT table.

The variant catalog program works in "Delta Mode"; this means that only the variants that were not taken into account during the previous run are cataloged again. The snippet could be found here.

3 - Save Variant Data

Starting from the variant catalog, the current variant data and attributes are stored in both tables TASUVSVD and TASUVSVO.
The TASUVSVD table contains the variant data and TASUVSVO contains the technical field descriptions (TVARV variables, protected fields, and so on).
The program saves only the values of the parameters related to a data element with domain bukrs. The program checks following condition:

(...)
* Get active Data Elemnts for Domain BUKRS
select rollname from dd04l
                    into table lt_repository bypassing buffer
                    where domname eq 'BUKRS' and
                         ( refkind eq space or refkind eq 'D' )
                          and as4local eq 'A'.
sort lt_repository.
(...)
read table lt_repository with key rollname = ls_dfies-rollname transporting no fields.
check sy-subrc = 0.

The snippet could be found here.

4 - Get The results

You can get the results immediately by the transaction SE16 (table TASUVSVD)

Create, Schedule and release Job in program 

This program is useful for create the transaction variant and run in background processing.

This program will create the transaction variant for a program.

New session will be opened using JOB_OPEN function module.

Program will be submit with variant for background schedule.

REPORT  ztest_job_call.

DATA : jobname TYPE tbtcjob-jobname VALUE 'ZJOBTEST',
       jobclass TYPE tbtcjob-jobclass VALUE 'A',
       jobcount TYPE tbtcjob-jobcount,
       lv_startdate LIKE sy-datum,
       lv_starttime LIKE sy-uzeit,
       authcknam TYPE tbtcjob-authcknam,
       lv_varname TYPE rsvar-variant,
       lwa_vardesc TYPE varid .

DATA: BEGIN OF gt_varid.
        INCLUDE STRUCTURE varid.
DATA: END OF gt_varid.

DATA: BEGIN OF gt_varit OCCURS 2.
        INCLUDE STRUCTURE varit.
DATA: END OF gt_varit.

DATA: BEGIN OF gt_rsparams OCCURS 0.
        INCLUDE STRUCTURE rsparams.
DATA: END OF gt_rsparams.

authcknam = sy-uname.

lv_startdate = sy-datum.
lv_starttime = sy-uzeit + 300.

CONCATENATE  'ABAP' lv_starttime INTO lv_varname.

lwa_vardesc-report = 'ZMMREPT_FUTURE_DELIVERY'.

* fill VARID structure - Variantenkatalog, variant description

gt_varid-mandt        = sy-mandt.
gt_varid-report       = lwa_vardesc-report.
gt_varid-variant      = lv_varname.
gt_varid-flag1        = space.
gt_varid-flag2        = space.
gt_varid-transport    = space.
gt_varid-environmnt   = 'A'.         "Variant for batch and online
gt_varid-protected    = space.
gt_varid-secu         = space.
gt_varid-version      = '1'.
gt_varid-ename        = sy-uname.
gt_varid-edat         = sy-datum.
gt_varid-etime        = sy-uzeit.
gt_varid-aename       = space.
gt_varid-aedat        = space.
gt_varid-aetime       = space.
gt_varid-mlangu       = sy-langu.

*.fill VARIT structure - Variantentexte; variant texts
gt_varit-mandt      = sy-mandt.
gt_varit-langu      = sy-langu.
gt_varit-report     = lwa_vardesc-report.
gt_varit-variant    = lv_varname.
gt_varit-vtext      = lv_varname.
APPEND gt_varit.

gt_rsparams-selname = 'S_PLNT'.
gt_rsparams-kind    = 'S'.
gt_rsparams-sign    = 'I'.
gt_rsparams-option  = 'EQ'.
gt_rsparams-low     = '1000'.
gt_rsparams-high    = '3500'.
APPEND gt_rsparams.

gt_rsparams-selname = 'S_MTART'.
gt_rsparams-kind    = 'S'.
gt_rsparams-sign    = 'I'.
gt_rsparams-option  = 'EQ'.
gt_rsparams-low     = 'FERT'.
gt_rsparams-high    = 'ROH'.
APPEND gt_rsparams.

gt_rsparams-selname = 'S_DDATE'.
gt_rsparams-kind    = 'S'.
gt_rsparams-sign    = 'I'.
gt_rsparams-option  = 'EQ'.
gt_rsparams-low     = '12.02.2008'.
gt_rsparams-high    = sy-datum.
APPEND gt_rsparams.

* Create Variant
CALL FUNCTION 'RS_CREATE_VARIANT'
  EXPORTING
    curr_report               = gt_varid-report
    curr_variant              = gt_varid-variant
    vari_desc                 = gt_varid
  TABLES
    vari_contents             = gt_rsparams
    vari_text                 = gt_varit
  EXCEPTIONS
    illegal_report_or_variant = 1
    illegal_variantname       = 2
    not_authorized            = 3
    not_executed              = 4
    report_not_existent       = 5
    report_not_supplied       = 6
    variant_exists            = 7
    variant_locked            = 8
    OTHERS                    = 9.

IF sy-subrc <> 0.

ENDIF.

CALL FUNCTION 'JOB_OPEN'
  EXPORTING
    jobname          = jobname
    jobclass         = jobclass
  IMPORTING
    jobcount         = jobcount
  EXCEPTIONS
    cant_create_job  = 1
    invalid_job_data = 2
    jobname_missing  = 3
    OTHERS           = 4.

IF sy-subrc = 0.

  CALL FUNCTION 'JOB_SUBMIT'
    EXPORTING
      authcknam               = authcknam
      jobcount                = jobcount
      jobname                 = jobname
      report                  = 'ZMMREPT_FUTURE_DELIVERY'
      variant                 = 'VAR'
    EXCEPTIONS
      bad_priparams           = 1
      bad_xpgflags            = 2
      invalid_jobdata         = 3
      jobname_missing         = 4
      job_notex               = 5
      job_submit_failed       = 6
      lock_failed             = 7
      program_missing         = 8
      prog_abap_and_extpg_set = 9
      OTHERS                  = 10.

  IF sy-subrc = 0.

    CALL FUNCTION 'JOB_CLOSE'
      EXPORTING
        jobcount             = jobcount
        jobname              = jobname
        sdlstrtdt            = lv_startdate
        sdlstrttm            = lv_starttime
      EXCEPTIONS
        cant_start_immediate = 1
        invalid_startdate    = 2
        jobname_missing      = 3
        job_close_failed     = 4
        job_nosteps          = 5
        job_notex            = 6
        lock_failed          = 7
        invalid_target       = 8
        OTHERS               = 9.
    IF sy-subrc = 0.

      CALL FUNCTION 'RS_VARIANT_DELETE'
        EXPORTING
          report               = gt_varid-report
          variant              = gt_varid-variant
          flag_confirmscreen   = 'X'
          flag_delallclient    = 'X'
        EXCEPTIONS
          not_authorized       = 1
          not_executed         = 2
          no_report            = 3
          report_not_existent  = 4
          report_not_supplied  = 5
          variant_locked       = 6
          variant_not_existent = 7
          no_corr_insert       = 8
          variant_protected    = 9
          OTHERS               = 10.
      IF sy-subrc <> 0.
      ENDIF.

    ENDIF.

  ENDIF.

ENDIF.
 
* program to execute jobs based on packet size for parallel processing.
* Data declaration.
TYPES: BEGIN OF ty_mara,
         matnr      TYPE mara-matnr,
        END OF ty_mara.
TYPES: BEGIN OF ty_jobs,
          jobname  TYPE tbtcjob-jobname,
          jobcount TYPE tbtcjob-jobcount,
        END OF ty_jobs.

DATA : gt_mara      TYPE STANDARD TABLE OF ty_mara.
DATA : gv_process       TYPE char10,
       gv_status        TYPE tbtcjob-status.
DATA:   gv_jobnumber  TYPE tbtcjob-jobcount,
        gv_printparam TYPE pri_params,
        gv_archparam  TYPE arc_params,
        gv_valid      TYPE c,
        gv_jobname    TYPE tbtcjob-jobname,
        gv_count(2)   TYPE c,
        gv_process1    TYPE char10,
        gv_bucket_size TYPE i.
* Local constants
CONSTANTS :gc_jobname TYPE tbtcjob-jobname VALUE 'X',
           gc_text    TYPE syprtxt         VALUE 'Y',
           gc_lines   TYPE sylinct         VALUE '60',
           gc_rows    TYPE sylinct         VALUE '240',
           gc_diff    TYPE c VALUE '-'.
* Retrieve the distinct Articles from general article data(MARA)
SELECT
     matnr
     FROM mara
     INTO TABLE gt_mara
     WHERE   mstae > 17.
DATA : lv_lines TYPE i,
       lv_start TYPE i,
       lv_end   TYPE i,
       lv_dummy TYPE f,
       lv_max   TYPE i.
* Count the no.of records of internal table GT_MARA
DESCRIBE TABLE gt_mara LINES lv_lines.
* Get the no of records for each process
lv_dummy = lv_lines / gv_bucket_size.
lv_max = ceil( lv_dummy ).
* Initialize Start & End
lv_start = 1.
* Check for the no.of records in GT_MARA
IF lv_lines < gv_bucket_size.
  lv_end = lv_lines.
ELSE.
  lv_end   = gv_bucket_size.
ENDIF.
gv_process = 1.
gv_fname_item  = gv_fname.
gv_fname_dunit  = gv_fname1.
DO.
  CLEAR gr_matnr_r.
*   Read internal table GT_MATNR for range LOW value
  READ TABLE gt_mara INTO gwa_mara INDEX lv_start.
*   Check for the Read statement
  IF sy-subrc = 0.
    gr_matnr_r-low = gwa_mara-matnr.
*     Read internal table GT_MATNR for range HIGH value
    READ TABLE gt_mara INTO gwa_mara INDEX lv_end.
    IF sy-subrc = 0.
      gr_matnr_r-high = gwa_mara-matnr.
      CONCATENATE gc_jobname
                gc_diff
                gv_process
                INTO gv_jobname.
      CONDENSE gv_jobname NO-GAPS.
*<<<<<< Print Parameters >>>>>>>>
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          no_dialog              = gc_x
        IMPORTING
          out_parameters         = gv_printparam
          out_archive_parameters = gv_archparam
          valid                  = gv_valid
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
      IF gv_valid <> space AND sy-subrc = 0.
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            in_archive_parameters  = gv_archparam
            in_parameters          = gv_printparam
            line_count             = gc_lines
            line_size              = gc_rows
            list_text              = gc_text
            no_dialog              = gc_x
          IMPORTING
            out_parameters         = gv_printparam
            valid                  = gv_valid
          EXCEPTIONS
            archive_info_not_found = 0
            invalid_print_params   = 0
            invalid_archive_params = 0
            OTHERS                 = 0.
      ENDIF.
*<<<<<< Job Open >>>>>>>>
      CALL FUNCTION 'JOB_OPEN'
        EXPORTING
          jobname          = gv_jobname
        IMPORTING
          jobcount         = gv_jobnumber
        EXCEPTIONS
          cant_create_job  = 1
          invalid_job_data = 2
          jobname_missing  = 3
          OTHERS           = 4.
    ENDFORM.                    "process_job
    IF sy-subrc = 0.
      CONCATENATE gv_path gc_slash gv_fname_item gc_underscore sy-datum
                  gc_underscore sy-uzeit
                  gc_underscore  gv_process  INTO gv_fname.
      CONDENSE gv_fname NO-GAPS.
      CONCATENATE gv_path gc_slash gv_fname_dunit gc_underscore sy-datum
                 gc_underscore sy-uzeit
                 gc_underscore  gv_process  INTO gv_fname1.
      CONDENSE gv_fname1 NO-GAPS.
*   for each process

      SUBMIT 'XY'
                       WITH s_matnr IN gr_matnr_r
                       TO SAP-SPOOL
                       SPOOL PARAMETERS gv_printparam
                       WITHOUT SPOOL DYNPRO
                       VIA JOB gv_jobname NUMBER gv_jobnumber
                       AND RETURN.
      IF sy-subrc = 0.
*<<<<<< Job Close >>>>>>>>
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            jobcount             = gv_jobnumber
            jobname              = gv_jobname
            strtimmed            = gc_x
          EXCEPTIONS
            cant_start_immediate = 1
            invalid_startdate    = 2
            jobname_missing      = 3
            job_close_failed     = 4
            job_nosteps          = 5
            job_notex            = 6
            lock_failed          = 7
            OTHERS               = 8.
        IF sy-subrc = 0.
          gwa_jobs-jobcount = gv_jobnumber.
          gwa_jobs-jobname  = gv_jobname.
          APPEND gwa_jobs TO gt_jobs.
          CLEAR: gwa_jobs.
        ENDIF.
*       Incriment the process for each Job
        gv_process = gv_process + 1.
      ELSE.
        EXIT.
      ENDIF.
    ELSE.
      EXIT.
    ENDIF.
*   Increment Start
    lv_start = lv_end + 1.
    IF lv_start > lv_lines.
      EXIT.
    ENDIF.
*   Increment End
    lv_end   = lv_start + gv_bucket_size - 1.
    IF lv_end > lv_lines.
      lv_end = lv_lines.
    ENDIF.
*   Check for the processess
    IF gv_process = lv_max AND lv_end < lv_lines.
      lv_end = lv_lines.
    ENDIF.
  ENDDO.
* Construct a do loop
*  DO p_maxbg TIMES.
  DO lv_max TIMES.
    READ TABLE gt_jobs INTO gwa_jobs INDEX 1.
    IF sy-subrc EQ 0.
      DO.
*       retrieve the status for the all jobs from table TBTCO
        SELECT SINGLE status
                      FROM tbtco INTO gv_status
                      WHERE jobname = gwa_jobs-jobname
                      AND   jobcount = gwa_jobs-jobcount.
*       Check for the select statement
        IF sy-subrc EQ 0 AND ( gv_status = gc_f OR
                               gv_status = gc_a ).
*         Delete the entry from internal table gt_jobs
          DELETE gt_jobs INDEX 1.
*         Clear local var gv_status and Exit from do loop
          CLEAR : gv_status.
*         Exit from do loop
          EXIT.
        ELSE.
*         wait for 3 seconds
          WAIT UP TO 3 SECONDS.
        ENDIF.
      ENDDO.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
 

Author: Chaitanya Raju
Submitted: Dec. 14 2007
Description: For some background update jobs, you might want to stop the user from submitting the jobs twice.

* Do this checks to prevent the users from submitting the
* same background job twice.
*
* Perform the checks before starting your programs.
*
* Create a MESSAGE-ID, the program will issue an error message
* in the Job logs.

TABLES:  tbtco.  "Job status overview table

DATA: t_jobcnt(1) TYPE n,
      t_sdluname LIKE tbtco-sdluname,
      t_strtdate LIKE tbtco-strtdate,
      t_strttime LIKE tbtco-strttime.

SELECT * FROM tbtco WHERE jobname  = 'ZXXX'
                      AND strtdate = sy-datum
                      AND status   = 'R'.

  t_jobcnt = t_jobcnt + 1.
  IF t_jobcnt = 1.
    t_sdluname = tbtco-sdluname.
    t_strtdate = tbtco-strtdate.
    t_strttime = tbtco-strttime.
  ENDIF.
ENDSELECT.

IF sy-subrc = 0.
  IF t_jobcnt < 1.
    MESSAGE e899 WITH t_sdluname 'have execute the program on'
                      t_strtdate t_strttime.
  ENDIF.
ENDIF.
 

Author: Sujeet Mishra
Submitted: 12/08/2013
Description: This program is to Check Background Jobs are Scheduled Correctly or Not??

                    Note : Program has not any maintained Text Element, so please Maintain text instead of Hard coding it as in below Program, This Program is just a sample template for Reference.

REPORT ZBASIS_BACKJOB
TABLES: TBTCP, TBTCO, T000, VARID.
DATA: FOUND(1) VALUE SPACE, STATEMENT(120), VALUE(20), ULOCK, UEXIST, DAYS TYPE I.
DATA: BEGIN OF I_REPS OCCURS 4, NAME LIKE TBTCP-PROGNAME, DESC(60),
END OF I_REPS.
DATA: VVAL LIKE RSPARAMS OCCURS 4 WITH HEADER LINE.
DATA: VTXT LIKE RSVSELTEXT OCCURS 4 WITH HEADER LINE.
DATA: numb TYPE I VALUE 0.
DATA: RCODE LIKE SY-SUBRC.
DATA: BEGIN OF I_JOBS OCCURS 4, NAME LIKE TBTCO-JOBNAME, REPO LIKE TBTCP-PROGNAME, DATE LIKE TBTCO-STRTDATE, TIME LIKE TBTCO-STRTTIME, MINS LIKE TBTCO-PRDMINS, HOUR LIKE TBTCO-PRDHOURS, DAYS LIKE TBTCO-PRDDAYS, WEEK LIKE TBTCO-PRDWEEKS, MONT LIKE TBTCO-PRDMONTHS, PERI LIKE TBTCO-PERIODIC, VARI LIKE TBTCP-VARIANT, USER LIKE TBTCP-AUTHCKNAM, MAND LIKE TBTCO-AUTHCKMAN,
END OF I_JOBS.
DATA: I_JOBS_WA LIKE I_JOBS.
*Below Jobs are some standard jobs which needs to be run everyday.
I_REPS-DESC = 'Delete old spool requests (old) OSS 48400, 16083'.
I_REPS-NAME = 'RSPO0041'. APPEND I_REPS.
I_REPS-DESC = 'Deletes old job logs'.
I_REPS-NAME = 'RSBTCDEL'.APPEND I_REPS.
I_REPS-DESC = 'Delete old spool requests (new) OSS 48400, 130978'.
I_REPS-NAME = 'RSPO1041'. APPEND I_REPS.
I_REPS-DESC = 'Spool consistency check display (old) OSS 48400'.
I_REPS-NAME = 'RSPO0043'. APPEND I_REPS.
I_REPS-DESC = 'Spool consistency check (new) OSS 48400'.
I_REPS-NAME = 'RSPO1043'. APPEND I_REPS.
I_REPS-DESC = 'Reorganize batch input logs OSS 16083, 147354'.
I_REPS-NAME = 'RSBDCREO'. APPEND I_REPS.
I_REPS-DESC = 'Delete old ABAP shortdumps OSS 16803, 126974'.
I_REPS-NAME = 'RSSNAPDL'. APPEND I_REPS.
I_REPS-DESC = 'Delete old Job statistics OSS 16803'.
I_REPS-NAME = 'RSBPSTDE'. APPEND I_REPS.
I_REPS-DESC = 'Collector for performance monitor OSS 127642'.
I_REPS-NAME = 'RSCOLL00'. APPEND I_REPS.
I_REPS-DESC = 'Collector for Job-statistics OSS 16083'.
I_REPS-NAME = 'RSBPCOLL'. APPEND I_REPS.
I_REPS-DESC = 'Generates or updates WBO indices OSS 18023'.
I_REPS-NAME = 'SAPRSEUT'. APPEND I_REPS.
I_REPS-DESC = 'Reorganizes WBO indices OSS 18023'.
I_REPS-NAME = 'SAPRSLOG'. APPEND I_REPS.
I_REPS-DESC = 'Deletes outdated print parameters OSS 307970 16083'.
I_REPS-NAME = 'RSBTCPRIDEL'. APPEND I_REPS.
I_REPS-DESC = 'Reorganizes table TXMILOGRAW OSS 16083, 182963'.
I_REPS-NAME = 'RSXMILOGREORG'. APPEND I_REPS.
I_REPS-DESC = 'Needed to start tools & methods Alert Mon. OSS 16083'.
I_REPS-NAME = 'RSAL_BATCH_TOOL_DISPATCHING'. APPEND I_REPS.
I_REPS-DESC = 'Reorganizes update records OSS 16083, 67014'.
I_REPS-NAME = 'RSM13002'. APPEND I_REPS.
\*---\- Select last runs \---------------------------------------\-
LOOP AT I_REPS.
&nbsp; &nbsp;EXEC SQL PERFORMING APPEND_JOBS. SELECT A.JOBNAME , B.PROGNAME , A.STRTDATE , A.STRTTIME , A.PRDMINS , A.PRDHOURS , A.PRDDAYS , A.PRDWEEKS , A.PRDMONTHS , A.PERIODIC , B.VARIANT , B.AUTHCKNAM , A.AUTHCKMAN INTO :I_JOBS_WA FROM TBTCO A , TBTCP B WHERE A.JOBNAME = B.JOBNAME AND A.JOBCOUNT = B.JOBCOUNT AND B.PROGNAME = :I_REPS-NAME AND A.STRTDATE = ( SELECT MAX(A_INNER.STRTDATE) FROM TBTCO A_INNER , TBTCP B_INNER WHERE A_INNER.JOBNAME = B_INNER.JOBNAME AND A_INNER.JOBCOUNT = B_INNER.JOBCOUNT AND B_INNER.PROGNAME = :I_REPS-NAME AND A_INNER.JOBNAME = A.JOBNAME )
&nbsp; &nbsp;ENDEXEC.
ENDLOOP.
SORT I_JOBS BY NAME REPO DATE TIME DESCENDING.
DELETE ADJACENT DUPLICATES FROM I_JOBS COMPARING NAME REPO DATE.
SORT I_JOBS BY REPO DATE.
SORT I_REPS BY NAME.
\*----\- Display \------------------------------------------------\-
LOOP AT I_REPS.
ADD 1 TO numb.
FOUND = SPACE.
WRITE:/ '========================================================='.
WRITE:/ numb, ' Program : ', I_REPS-NAME.
WRITE:/ '========================================================='.
LOOP AT I_JOBS.
IF I_JOBS-REPO = I_REPS-NAME.
FOUND = 'X'.
WRITE:/ '---------------------------------------------------------'.
WRITE:/ 'Jobname :', I_JOBS-NAME.
WRITE:/ 'Description :', I_REPS-DESC.
WRITE:/ 'Last run :'.
days = sy-datum - i_jobs-date.
IF days > 31.
WRITE: 'No last run info found for this job'.
ELSE.
WRITE: I_JOBS-DATE.
ENDIF.
WRITE:/ 'at :', I_JOBS-TIME.
WRITE:/ 'User :', I_JOBS-USER.
CALL FUNCTION 'USER_EXISTS'
EXPORTING
BNAME = I_JOBS-USER
CLIENT = I_JOBS-MAND
IMPORTING
LOCKED = ULOCK
EXCEPTIONS
USER_DONT_EXIST = 1
USER_EXISTS = 2
OTHERS = 3
.
IF SY-SUBRC <> 2.
WRITE: '( does not exist \!\! )'.
UEXIST = 'X'.
ENDIF.
IF ULOCK NE SPACE.
WRITE: '( is locked \!\! )'.
ENDIF.
WRITE:/ 'Type :'.
CASE I_JOBS-REPO.
WHEN 'RSBTCDEL'.
WRITE: 'Client-independent (if',i_jobs-user.
WRITE: 'has S_BTCH_ADM=Y)'.
WHEN 'RSPO1041' OR 'RSPO0041'.
WRITE: 'Client-independent (if client = "*" in variant)'.
WHEN 'RSPO1043' OR 'RSPO1043'.
WRITE: 'Client-dependent due to bug, OSS Note 375964.'.
WHEN 'RSBDCREO'. WRITE: 'Client-dependent'.
WHEN 'RSSNAPDL'. WRITE: 'Client-independent'.
WHEN 'RSBPSTDE'. WRITE: 'Client-independent'.
WHEN 'RSCOLL00'. WRITE: 'Client-independent'.
WHEN 'RSBPCOLL'. WRITE: 'Client-independent'.
WHEN 'SAPRSEUT'. WRITE: 'Client-independent'.
WHEN 'SAPRSLOG'. WRITE: 'Client-independent'.
WHEN 'RSBTCPRIDEL'. WRITE: 'Client-independent'.
WHEN 'RSXMILOGREORG'. WRITE: 'Client-independent'.
WHEN 'RSAL_BATCH_TOOL_DISPATCHING'. WRITE: 'Client-independent'.
WHEN 'RSM13002'. WRITE: 'Client-independent'.
ENDCASE.
WRITE:/ 'Client :', I_JOBS-MAND.
Select * from T000 where mandt = i_jobs-mand.
ENDSELECT.
if sy-subrc <> 0.
WRITE: '( Client does not exist)'.
ENDIF.
WRITE:/ 'Period :'.
IF I_JOBS-PERI NE SPACE.
IF I_JOBS-MINS NE 0.
WRITE: I_JOBS-MINS, 'minutes'.
ENDIF.
IF I_JOBS-HOUR NE 0.
WRITE: I_JOBS-HOur, 'hours'.
ENDIF.
IF I_JOBS-DAYS NE 0.
WRITE: I_JOBS-DAYS, 'days'.
ENDIF.
IF I_JOBS-WEEK NE 0.
WRITE: I_JOBS-WEEK, 'weeks'.
ENDIF.
IF I_JOBS-MONT NE 0.
WRITE: I_JOBS-MONT, 'months'.
ENDIF.
ENDIF.
WRITE:/ 'Variant :'.
IF I_JOBS-VARI EQ SPACE.
WRITE: 'Not applicable'.
ELSE.
WRITE: I_JOBS-VARI.
ENDIF.
WRITE:/ '---------------------------------------------------------'.
IF I_JOBS-VARI NE SPACE.
SELECT * from varid client specified
where mandt = i_jobs-mand
and REPORT = I_JOBS-REPO
and VARIANT = I_JOBS-VARI.
ENDSELECT.
IF RCODE NE 0.
WRITE:/ 'Variant', I_JOBS-VARI, ' does not exist \!\!'.
IF I_JOBS-MAND = SY-MANDT.
CALL FUNCTION 'RS_VARIANT_VALUES_TECH_DATA'
EXPORTING
REPORT = I_JOBS-REPO
VARIANT = I_JOBS-VARI
SEL_TEXT = 'X'
MOVE_OR_WRITE = 'W'
TABLES
VARIANT_VALUES = VVAL
VARIANT_TEXT = VTXT.
ENDIF.
ELSE.
LOOP AT VTXT. WRITE:/5 VTXT-TEXT. READ TABLE VVAL INDEX SY-TABIX. IF VVAL-KIND EQ 'P'. WRITE: VVAL-LOW. ELSEIF VVAL-KIND = 'S'. WRITE: VVAL-LOW, VVAL-HIGH. ENDIF.
ENDLOOP. ENDIF.
&nbsp; &nbsp; ENDIF.
ENDIF.
ENDLOOP.
IF FOUND EQ SPACE. IF I_REPS-NAME EQ 'RSM13002'. CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'rdisp/vb_delete_after_execution' ID 'VALUE' FIELD VALUE. IF VALUE NE '1'. WRITE:/ 'Since automatic deletion of update records is '.
WRITE:/ 'disabled, RSM13002 should be scheduled.'.
ELSE.
WRITE:/ 'Jobs is not neccesary since automatic deletion'.
WRITE:/ 'of update records is enabled.'.
ENDIF.
ELSeIF I_reps-name eq 'RSBTCPRIDEL'.
IF sy-saprl < '46A'.
WRITE:/ 'Job is not neccesary since R/3 release is '.
WRITE:/ 'lower than 46A.'.
ELSE.
WRITE:/ 'Job is neccesary since R/3 release is '.
WRITE:/ 'higher than 46A.'.
ENDIF.
ELSeIF I_reps-name eq 'RSXMILOGREORG'.
IF sy-saprl < '46A'.
WRITE:/ 'Job is not neccesary since R/3 release is '.
WRITE:/ 'lower than 46A.'.
ELSE.
WRITE:/ 'Job is neccesary since R/3 release is '.
WRITE:/ 'higher than 46A.'.
ENDIF.
ELSeIF I_reps-name eq 'RSAL_BATCH_TOOL_DISPATCHING'.
IF sy-saprl < '46A'.
WRITE:/ 'Job is not neccesary since R/3 release is '.
WRITE:/ 'lower than 46A.'.
ELSE.
WRITE:/ 'Job is neccesary since R/3 relaese is '.
WRITE:/ 'higher than 46A.'.
ENDIF.
ELSEIF I_reps-name eq 'RSPO0043' OR
I_reps-name eq 'RSPO1043'.
CONCATENATE 'Program' I_REPS-NAME 'not found in any job.' INTO
STATEMENT SEPARATED BY SPACE.
WRITE:/ STATEMENT.
WRITE:/ 'Schedule RSPO0043 OR preferably RSPO1043'.
WRITE:/ 'according to OSS Notes 16083 and 98065'.
WRITE:/ 'Note that these ABAPs are CLIENT-DEPENDENT due'.
WRITE:/ 'to a bug; see OSS Note 375964.'.
ELSEIF I_reps-name eq 'RSPO0041' OR
I_reps-name eq 'RSPO1041'.
CONCATENATE 'Program' I_REPS-NAME 'not found in any job.' INTO
STATEMENT SEPARATED BY SPACE.
WRITE:/ STATEMENT.
WRITE:/ 'Schedule RSPO0041 OR preferably RSPO1041'.
WRITE:/ 'according to : OSS Notes 16083 and 130978'.
ELSE.
CONCATENATE 'Program' I_REPS-NAME 'not found in any job.' INTO
STATEMENT SEPARATED BY SPACE.
WRITE:/ STATEMENT.
CONCATENATE 'Schedule' I_REPS-NAME 'according to OSS Note 16083.'
INTO STATEMENT SEPARATED BY SPACE.
WRITE:/ STATEMENT.
ENDIF.
ENDIF.
ENDLOOP.

REPORT z_mat_analyzer  LINE-SIZE 255
                       NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------
* Tool    : Job Log Analyzer
*           This tool analyzes the Job Log and summarizes the messages.
*----------------------------------------------------------------------

*----------------------------------------------------------------------
TABLES: tbtco.

*----------------------------------------------------------------------
SELECT-OPTIONS: so_jobnm  FOR tbtco-jobname.
SELECT-OPTIONS: so_strdt  FOR tbtco-strtdate DEFAULT sy-datum.
SELECT-OPTIONS: so_uname  FOR tbtco-reluname DEFAULT sy-uname.

*----------------------------------------------------------------------
CONSTANTS: c_hdr_lines           TYPE i VALUE 3.

TYPES: BEGIN OF typ_logsumm,
         msgid        TYPE tbtc5-msgid,
         msgno        TYPE tbtc5-msgno,
         msgtype      TYPE tbtc5-msgtype,
         text_gen     TYPE tbtc5-text,
         count        TYPE sy-index,
       END   OF typ_logsumm.

DATA: it_tbtco                   TYPE STANDARD TABLE OF tbtco
                                      WITH HEADER LINE,
      it_joblog                  TYPE STANDARD TABLE OF tbtc5
                                      WITH HEADER LINE,
      it_logsumm                 TYPE STANDARD TABLE OF typ_logsumm
                                      WITH HEADER LINE.

DATA: l_status(10)               TYPE c,
      l_alternate(01)            TYPE c,
      l_index                    TYPE sy-index.

*----------------------------------------------------------------------
START-OF-SELECTION.
*
  SET PF-STATUS '0002'.

  WRITE: / sy-uline(87).

  WRITE: / '|' NO-GAP,
           (32) 'Job Name'  COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (10) 'St Date'   COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (08) 'St Time'   COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (12) 'User'      COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (10) 'Status'    COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (08) 'Job Nbr'   COLOR COL_HEADING NO-GAP,   '|' NO-GAP.
  WRITE: / sy-uline(87).

*
  SELECT * FROM tbtco
    INTO TABLE it_tbtco
    WHERE jobname IN so_jobnm
    AND   strtdate IN so_strdt
    AND   reluname IN so_uname.

  SORT it_tbtco BY jobname jobcount DESCENDING.

  LOOP AT it_tbtco.
    CASE it_tbtco-status.
      WHEN 'F'.    l_status = 'Finished'.
      WHEN 'C'.    l_status = 'Active'.
      WHEN 'A'.    l_status = 'Canceled'.
      WHEN 'R'.    l_status = 'Ready'.
      WHEN 'P'.    l_status = 'Scheduled'.
      WHEN 'S'.    l_status = 'Scheduled'.
*   P & S - Should never show up in this report.
      WHEN OTHERS. l_status = it_tbtco-status.

    ENDCASE.

    IF l_alternate IS INITIAL.
      l_alternate = 'X'.
      FORMAT COLOR COL_NORMAL INTENSIFIED ON.
    ELSE.
      l_alternate = ' '.
      FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    ENDIF.

    WRITE: / '|' NO-GAP,
             (32) it_tbtco-jobname NO-GAP,  '|' NO-GAP,
             (10) it_tbtco-strtdate NO-GAP, '|' NO-GAP,
             (08) it_tbtco-strttime NO-GAP, '|' NO-GAP,
             (12) it_tbtco-reluname NO-GAP, '|' NO-GAP,
             (10) l_status NO-GAP,       '|' NO-GAP,
             (08) it_tbtco-jobcount NO-GAP, '|' NO-GAP.

  ENDLOOP.

  WRITE: / sy-uline(87).

*----------------------------------------------------------------------
AT LINE-SELECTION.

  l_index = sy-lilli - c_hdr_lines.

  READ TABLE it_tbtco INDEX l_index.
  CHECK sy-subrc = 0.

  REFRESH: it_joblog.

  CALL FUNCTION 'BP_JOBLOG_READ'
    EXPORTING
      jobcount              = it_tbtco-jobcount
      jobname               = it_tbtco-jobname
    TABLES
      joblogtbl             = it_joblog
    EXCEPTIONS
      cant_read_joblog      = 1
      jobcount_missing      = 2
      joblog_does_not_exist = 3
      joblog_is_empty       = 4
      joblog_name_missing   = 5
      jobname_missing       = 6
      job_does_not_exist    = 7
      OTHERS                = 8.
  IF sy-subrc <> 0.
    WRITE: / 'No Log found for Job:', it_tbtco-jobname.
  ENDIF.

  REFRESH: it_logsumm.
  it_logsumm-count = 1.

  LOOP AT it_joblog.
    MOVE-CORRESPONDING  it_joblog  TO it_logsumm.
    SELECT SINGLE text INTO it_logsumm-text_gen
           FROM  t100
           WHERE sprsl = sy-langu
           AND   arbgb = it_logsumm-msgid
           AND   msgnr = it_logsumm-msgno.
    COLLECT it_logsumm.
  ENDLOOP.

  FORMAT COLOR COL_HEADING.
  WRITE: / sy-uline(122).
  WRITE: / '|' NO-GAP,
           (02) 'ID' NO-GAP,        '|' NO-GAP,
           (03) 'Nbr' NO-GAP,       '|' NO-GAP,
           (01) 'T' NO-GAP,         '|' NO-GAP,
           (10) 'Count' NO-GAP,     '|' NO-GAP,
           (100) 'Error Message' NO-GAP,  '|' NO-GAP.
  WRITE: / sy-uline(122).

  LOOP AT it_logsumm.

    IF l_alternate IS INITIAL.
      l_alternate = 'X'.
      FORMAT COLOR COL_NORMAL INTENSIFIED ON.
    ELSE.
      l_alternate = ' '.
      FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    ENDIF.

    WRITE: / '|' NO-GAP,
             (02)  it_logsumm-msgid NO-GAP,    '|' NO-GAP,
             (03)  it_logsumm-msgno NO-GAP,    '|' NO-GAP,
             (01)  it_logsumm-msgtype NO-GAP,  '|' NO-GAP,
             (10)  it_logsumm-count NO-GAP,    '|' NO-GAP,
             (100) it_logsumm-text_gen NO-GAP, '|' NO-GAP.
  ENDLOOP.

  WRITE: / sy-uline(122).
 
REPORT zlsmw_analyze_mat  LINE-SIZE 255
                          NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------
* Tool    : Job Log Analyzer
*           This tool analyzes the Job Log and summarizes the messages.
*----------------------------------------------------------------------

*----------------------------------------------------------------------
TABLES: tbtco.

*----------------------------------------------------------------------
SELECT-OPTIONS: so_jobnm  FOR tbtco-jobname.
SELECT-OPTIONS: so_strdt  FOR tbtco-strtdate DEFAULT sy-datum.
SELECT-OPTIONS: so_uname  FOR tbtco-reluname DEFAULT sy-uname.

*----------------------------------------------------------------------
CONSTANTS: c_hdr_lines           TYPE i VALUE 3.

TYPES: BEGIN OF typ_logsumm,
         msgid        TYPE tbtc5-msgid,
         msgno        TYPE tbtc5-msgno,
         msgtype      TYPE tbtc5-msgtype,
         text_gen     TYPE tbtc5-text,
         count        TYPE sy-index,
       END   OF typ_logsumm.

DATA: it_tbtco                   TYPE STANDARD TABLE OF tbtco
                                      WITH HEADER LINE,
      it_joblog                  TYPE STANDARD TABLE OF tbtc5
                                      WITH HEADER LINE,
      it_logsumm                 TYPE STANDARD TABLE OF typ_logsumm
                                      WITH HEADER LINE.

DATA: l_status(10)               TYPE c,
      l_alternate(01)            TYPE c,
      l_index                    TYPE sy-index.

*----------------------------------------------------------------------
START-OF-SELECTION.
*
  SET PF-STATUS '0002'.

  WRITE: / sy-uline(87).

  WRITE: / '' NO-GAP,
           (32) 'Job Name'  COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (10) 'St Date'   COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (08) 'St Time'   COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (12) 'User'      COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (10) 'Status'    COLOR COL_HEADING NO-GAP,   '|' NO-GAP,
           (08) 'Job Nbr'   COLOR COL_HEADING NO-GAP,   '|' NO-GAP.
  WRITE: / sy-uline(87).

*
  SELECT * FROM tbtco
    INTO TABLE it_tbtco
    WHERE jobname IN so_jobnm
      AND strtdate IN so_strdt
      AND reluname IN so_uname.

  SORT it_tbtco BY jobname jobcount DESCENDING.

  LOOP AT it_tbtco.
    CASE it_tbtco-status.
      WHEN 'F'.    l_status = 'Finished'.
      WHEN 'C'.    l_status = 'Active'.
      WHEN 'A'.    l_status = 'Canceled'.
      WHEN 'R'.    l_status = 'Ready'.
      WHEN 'P'.    l_status = 'Scheduled'.
      WHEN 'S'.    l_status = 'Scheduled'.
*   P & S - Should never show up in this report.
      WHEN OTHERS. l_status = it_tbtco-status.

    ENDCASE.

    IF l_alternate IS INITIAL.
      l_alternate = 'X'.
      FORMAT COLOR COL_NORMAL INTENSIFIED ON.
    ELSE.
      l_alternate = ' '.
      FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    ENDIF.

    WRITE: / '|' NO-GAP,
             (32) it_tbtco-jobname NO-GAP,  '|' NO-GAP,
             (10) it_tbtco-strtdate NO-GAP, '|' NO-GAP,
             (08) it_tbtco-strttime NO-GAP, '|' NO-GAP,
             (12) it_tbtco-reluname NO-GAP, '|' NO-GAP,
             (10) l_status NO-GAP,       '|' NO-GAP,
             (08) it_tbtco-jobcount NO-GAP, '|' NO-GAP.

  ENDLOOP.

  WRITE: / sy-uline(87).

*----------------------------------------------------------------------
AT LINE-SELECTION.

  l_index = sy-lilli - c_hdr_lines.

  READ TABLE it_tbtco INDEX l_index.
  CHECK sy-subrc = 0.

  REFRESH: it_joblog.

  CALL FUNCTION 'BP_JOBLOG_READ'
    EXPORTING
      jobcount              = it_tbtco-jobcount
      jobname               = it_tbtco-jobname
    TABLES
      joblogtbl             = it_joblog
    EXCEPTIONS
      cant_read_joblog      = 1
      jobcount_missing      = 2
      joblog_does_not_exist = 3
      joblog_is_empty       = 4
      joblog_name_missing   = 5
      jobname_missing       = 6
      job_does_not_exist    = 7
      OTHERS                = 8.
  IF sy-subrc <> 0.
    WRITE: / 'No Log found for Job:', it_tbtco-jobname.
  ENDIF.

  REFRESH: it_logsumm.
  it_logsumm-count = 1.

  LOOP AT it_joblog.
    MOVE-CORRESPONDING  it_joblog  TO it_logsumm.
    SELECT SINGLE text INTO it_logsumm-text_gen
           FROM  t100
           WHERE sprsl = sy-langu
           AND   arbgb = it_logsumm-msgid
           AND   msgnr = it_logsumm-msgno.
    COLLECT it_logsumm.
  ENDLOOP.

  FORMAT COLOR COL_HEADING.
  WRITE: / sy-uline(122).
  WRITE: / '|' NO-GAP,
           (02) 'ID' NO-GAP,        '|' NO-GAP,
           (03) 'Nbr' NO-GAP,       '|' NO-GAP,
           (01) 'T' NO-GAP,         '|' NO-GAP,
           (10) 'Count' NO-GAP,     '|' NO-GAP,
           (100) 'Error Message' NO-GAP,  '|' NO-GAP.
  WRITE: / sy-uline(122).

  LOOP AT it_logsumm.

    IF l_alternate IS INITIAL.
      l_alternate = 'X'.
      FORMAT COLOR COL_NORMAL INTENSIFIED ON.
    ELSE.
      l_alternate = ' '.
      FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    ENDIF.

    WRITE: / '|' NO-GAP,
             (02)  it_logsumm-msgid NO-GAP,    '|' NO-GAP,
             (03)  it_logsumm-msgno NO-GAP,    '|' NO-GAP,
             (01)  it_logsumm-msgtype NO-GAP,  '|' NO-GAP,
             (10)  it_logsumm-count NO-GAP,    '|' NO-GAP,
             (100) it_logsumm-text_gen NO-GAP, '|' NO-GAP.
  ENDLOOP.

  WRITE: / sy-uline(122).
 

Author: Sreekumar Hariharan
Submitted: 12/13/2013

For faster results, we often execute programs in parallel using background jobs. Even though this might be a good idea in terms of processing efficiency, on many occasions this results in high utilization of the system resources and non-availability of background work processes for other key custom operations.

The below technique provides a controlled and conservative approach towards multiple/parallel job generation. With this technique, we can set a maximum utilization percentage and hence always reserve some work processes for other operations. The attributes like utilization threshold and delay can be input as a Parameter/ Select-option in the program or can be maintained in selection variable table TVARVC or a custom table, but to keep it simple I am going to use this as constants in the program.

The key function that we use in this method is TH_GET_WPINFO which returns the details of the active work processes in the system. The function takes as input 2 optional parameters SRVNAME (Application server) and WITH_CPU. If the job processing has to be limited to a specific server on the system, these parameters can be used to limit the query and later submit the job to the specific server group. But if no restrictions need to be imposed in terms of servers, these can be left blank. The function returns the list of work processes in the system and is similar to SM50 screen (except for the fact that SM50 shows the work processes only from the server on which user is logged on to). Based on this information, we can determine the total and available work processes and the background work process utilization level. Based on the percentage, we can either generate the next job or wait for predefined amount of time and try again.

 

REPORT  zcons_bgd_proc.
CONSTANTS:
  "Assuming the utilization limit to be 60%
  c_limit  TYPE p DECIMALS 2 VALUE 60.
DATA:
  "Assuming a total of 10 jobs need to be generated
  v_jobs    TYPE i VALUE 10,
  "Assuming a wait time of 10 seconds to be inserted
  " if utilization is above limit
  v_delay   TYPE i VALUE 10.
DATA:
  lt_wplist TYPE TABLE OF wpinfo,
  v_total   TYPE i,
  v_utilz   TYPE i,
  v_uperc   TYPE p DECIMALS 2.
DO.
  CALL FUNCTION 'TH_GET_WPINFO'
* EXPORTING
*   srvname          =  "Application server optional
*   with_cpu         =  "CPU optional
    TABLES
      wplist           = lt_wplist
   EXCEPTIONS
     send_error       = 1
     OTHERS           = 2.
  IF sy-subrc = 0.
    "Retain details of background work processes only
    DELETE lt_wplist WHERE wp_itype NE 4.
    DESCRIBE TABLE lt_wplist LINES v_total.
    "Delete the work processes in Waiting state
    DELETE lt_wplist WHERE wp_istatus = 2.
    DESCRIBE TABLE lt_wplist LINES v_utilz.
    v_uperc = v_utilz * 100 / v_total.
    "If utilization leass than threshold, proceed
    IF v_uperc LE c_limit.
      "<Generate background job>
      v_jobs = v_jobs - 1.
      IF v_jobs = 0.
        EXIT.
      ENDIF.
      " If utilization is over the threshold, wait
    ELSE.
      WAIT UP TO v_delay SECONDS.
    ENDIF.
  ENDIF.
ENDDO.

  • No labels