Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to find the job has failed in back ground

Former Member
0 Likes
1,372

Hi All,

I have a requirement where i will be running a report online and background.

If my job has failed in Background, then i have to trigger a mail to the user stating that the job has been terminated.

Now, How will i know the Job has failed and how should i handle this in my report so as to trigger a mail.

Hope i am clear with my requirement.Kindly clarify if possibe with any func modules or sample codings.

Thanks in advance

Nanda

8 REPLIES 8
Read only

Former Member
0 Likes
1,004

I Think You Might be Using a function module to Open the Job. May be this <b>JOB_OPEN</b>, i don't know...

You can catch the sy-subrc and check if it fails then

you send the mail..

regards

vijay

Read only

andreas_mann3
Active Contributor
0 Likes
1,004

Hi try that:

try:

1) fm job_open

2) submit report

3) fm job_close

4) finally select table TBTCO

example:

 DATA: jobcount_test LIKE tbtcjob-jobcount,
        job_released    LIKE btch0000-char1,
        rcode(2),
        strtimmed LIKE btch0000-char1 VALUE 'X'.
  DATA jobname  LIKE tbtcjob-jobname.
 
  CONCATENATE  'TEST_' sy-repid '_' sy-datum INTO jobname.
 
  CALL FUNCTION 'JOB_OPEN'
       EXPORTING
            jobname          = jobname
       IMPORTING
            jobcount         = jobcount_test
       EXCEPTIONS
            cant_create_job  = 1
            invalid_job_data = 2
            jobname_missing  = 3
            OTHERS           = 4.
 
 
  IF sy-subrc NE 0.
    MESSAGE x000(yp) WITH 'JOB-START ' jobname ' failed !!!'.
  ELSE.
*--Step insert
    SUBMIT rsbdcsub
    USER sy-uname VIA JOB jobname NUMBER jobcount_test
    WITH mappe = map
    WITH von = pdatum
    WITH z_verarb = 'X'
    AND RETURN .
*
    CALL FUNCTION 'JOB_CLOSE'
         EXPORTING
              jobcount             = jobcount_test
              jobname              = jobname
              strtimmed            = strtimmed
              targetsystem         = sy-host
         IMPORTING
              job_was_released     = job_released
         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 > 1.
      MESSAGE x000(yp) WITH 'JOB-CLOSE ' jobname ' failed!!!'.
    ENDIF.
  ENDIF.

Andreas

Read only

Former Member
0 Likes
1,004
  call function 'JOB_OPEN'
       exporting
            jobname  = myjob_name
       importing
            jobcount = lv_job_nr.
   if sy-subrc = 0.
  call function 'JOB_SUBMIT'
       exporting
            authcknam = sy-uname
            jobcount  = lv_job_nr
            jobname   = myjob_name
            report    = lc_report
            variant   = lv_variant.
   if sy-subrc = 0.
  call function 'JOB_CLOSE'
       exporting
            jobcount         = lv_job_nr
            jobname          = myjob_name
            prdmins          = lv_periode
            sdlstrtdt        = lv_startdate
            sdlstrttm        = lv_starttime
       importing
            job_was_released = lf_ok.
endif.
endif.

try to do in similar way..

once job fails send the mail <b>if sy-subrc <> 0.</b>

Read only

christian_wohlfahrt
Active Contributor
0 Likes
1,004

Hi Nanda!

It's in the nature of a failure (e.g. shortdump), that no further program lines are executed. (OK, some exceptions can be handled by the program itself, but not all.)

So only general checks can be done: e.g. tell your basis to write a mail to the one who planned a failed job.

Regards,

Christian

Read only

andreas_mann3
Active Contributor
0 Likes
1,004

Hi,

or try fm SLW_WL1_GET_BTCH_JOB_STATUS

(->status F = ready)

regards Andreas

Read only

Former Member
0 Likes
1,004

Hi Nanda,

Through program you can check the job status.

This is the samle code try to use the table

I have used .


 *--- Fetching Job Status information from the table TBTCO
  CLEAR : I_TBTCO,
          I_TBTCO[],
          I_TBTCP,
          I_TBTCP[],
          I_BTCJSTAT,
          I_BTCJSTAT[].

  SELECT DISTINCT JOBNAME       " Jobname
       JOBCOUNT      " Background job number
       SDLUNAME      " User name of person scheduling job
       SDLSTRTDT     " Planned start date for batch job
       SDLSTRTTM     " Planned start time for batch job
       STATUS        " Status of the job
                  LASTCHDATE
                  LASTCHTIME
    INTO TABLE I_TBTCO
    FROM <b>TBTCO</b>
    WHERE  JOBNAME IN R_JOB  AND
           SDLDATE IN R_DATE.

  IF SY-SUBRC = 0.
    SELECT *
      INTO TABLE I_BTCJSTAT
      FROM <b>BTCJSTAT</b>
      WHERE JOBNAME   IN R_JOB  AND
            STATDATE  IN R_DATE.
  ENDIF.
      IF I_TBTCO-STATUS     = 'F'.
        WRITE : 84 'Finished'(007).
      ELSEIF I_TBTCO-STATUS = 'C'.
        WRITE : 84 'Canceled'(008).
      ELSEIF I_TBTCO-STATUS = 'R'.
        WRITE : 84 'Released'(009).
      ELSEIF I_TBTCO-STATUS = 'Y'.
        WRITE : 84 'Ready'(010).
      ELSEIF I_TBTCO-STATUS = 'A'.
READ TABLE I_BTCJSTAT WITH KEY 
 JOBNAME   = I_TBTCO-JOBNAME
 LASTCHDATE = I_TBTCO-LASTCHDATE
 LASTCHTIME = I_TBTCO-LASTCHTIME.
        IF SY-SUBRC = 0.
          WRITE : 84 'Active'(011).
        ELSE.
          WRITE : 84 'Canceled'(008).
        ENDIF.
      ELSEIF I_TBTCO-STATUS = 'S'
          OR I_TBTCO-STATUS = 'P'.
        WRITE : 84 'Scheduled'(012).
      ENDIF.

Thanks & Regards,

Siri.

Kindly award points if it is useful.

Read only

Former Member
0 Likes
1,004

Hi,

You can use FM 'BP_JOB_READ'. The import parameter JOB_READ_JOBHEAD contains status of job.

For Exapmle:

CALL FUNCTION 'BP_JOB_READ'

EXPORTING

JOB_READ_JOBCOUNT = ITAB_JOBS-JOBCOUNT

JOB_READ_JOBNAME = ITAB_JOBS-JOBNAME

JOB_READ_OPCODE = BTC_READ_JOBHEAD_ONLY

IMPORTING

JOB_READ_JOBHEAD = ITAB_CHECK_JOBHEADER

EXCEPTIONS

INVALID_OPCODE = 1

JOB_DOESNT_EXIST = 2

JOB_DOESNT_HAVE_STEPS = 3

OTHERS = 4.

Import parameter ITAB_CHECK_JOBHEADER will have ststus - finished or aborted.

Hope this helps.

Regards,

Ramesh Kashigari.

Read only

Former Member
0 Likes
1,004

Hi,

Try with the FM BP_JOB_STATUS_GET by passing the jobname.

Thanks,

Eswar