Application Development 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: 

Job Spool and Job Log

Former Member
0 Kudos

Hi Everybody,

I need to create an ABAP program and schedule it so that it runs as soon as a given job finishes and download the job log and the job spool in to a file on PC.

The program should check if the given job has finished or not. if yes then it should download the job's log and spool on to a file on the PC(frontend).

How do i go about it?

Thanks in advance.

Berry

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Guarav,

See the below somple code to know the job ststus.

You can check the Batch job status in the tables

TBTCO , TBTCP and TSP01.

Based on that you can find the status and

send read the spool and downlaod to directory.


*--- 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 TBTCO
    WHERE  JOBNAME IN R_JOB  AND
           SDLDATE IN R_DATE.

  IF SY-SUBRC = 0.
    SELECT *
      INTO TABLE I_BTCJSTAT
      FROM BTCJSTAT
      WHERE JOBNAME   IN R_JOB  AND
            STATDATE  IN R_DATE.
  ENDIF.
  IF NOT I_TBTCO[] IS INITIAL.
    SELECT JOBNAME
           JOBCOUNT
           LISTIDENT
      INTO TABLE I_TBTCP
      FROM TBTCP
*      FOR ALL ENTRIES IN I_TBTCO
      WHERE JOBNAME  IN R_JOB.
*      WHERE JOBNAME  = I_TBTCO-JOBNAME AND
*            JOBCOUNT = I_TBTCO-JOBCOUNT.

    LOOP AT I_TBTCP.
      READ TABLE I_TBTCO WITH KEY JOBCOUNT = I_TBTCP-JOBCOUNT.
      IF SY-SUBRC = 0.
        IF NOT I_TBTCP-LISTIDENT IS INITIAL.
          PACK I_TBTCP-LISTIDENT TO I_SPOOLS2-RQIDENT.
          APPEND I_SPOOLS2.
          CLEAR  I_SPOOLS2.
        ENDIF.
      ENDIF.
    ENDLOOP.

    IF NOT I_SPOOLS2[] IS INITIAL.
      SELECT RQIDENT
        FROM TSP01
        INTO TABLE I_SPOOLS
        FOR ALL ENTRIES IN I_SPOOLS2
        WHERE RQIDENT = I_SPOOLS2-RQIDENT.
    ENDIF.

Hope this will helpful to you. Let m eknow if you have any questions.

Thanks&Regards,

Siri.

6 REPLIES 6

former_member188685
Active Contributor
0 Kudos

hi,

you can make use job_open,job_submit,job_close function modules and write the code.

thanks

vijay

Message was edited by: Vijay Babu Dudla

Former Member
0 Kudos

Hi Gaurav,

1 . as soon as a given job finishes

What details are available about

this job.

Just the program name ?

Or other details would also be available

ie. Jobname and jobcount.

It jobname and jobcount are avialble,

only then can we go further for the requirement.

2. Kindly clarify and answer !

Regards,

Amit M.

0 Kudos

hi Amit,

if all details are available about the give job

like jobname jobcount etc.

then how do i proceed...

thanks in advance

Berry

Former Member
0 Kudos

Hi Guarav,

See the below somple code to know the job ststus.

You can check the Batch job status in the tables

TBTCO , TBTCP and TSP01.

Based on that you can find the status and

send read the spool and downlaod to directory.


*--- 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 TBTCO
    WHERE  JOBNAME IN R_JOB  AND
           SDLDATE IN R_DATE.

  IF SY-SUBRC = 0.
    SELECT *
      INTO TABLE I_BTCJSTAT
      FROM BTCJSTAT
      WHERE JOBNAME   IN R_JOB  AND
            STATDATE  IN R_DATE.
  ENDIF.
  IF NOT I_TBTCO[] IS INITIAL.
    SELECT JOBNAME
           JOBCOUNT
           LISTIDENT
      INTO TABLE I_TBTCP
      FROM TBTCP
*      FOR ALL ENTRIES IN I_TBTCO
      WHERE JOBNAME  IN R_JOB.
*      WHERE JOBNAME  = I_TBTCO-JOBNAME AND
*            JOBCOUNT = I_TBTCO-JOBCOUNT.

    LOOP AT I_TBTCP.
      READ TABLE I_TBTCO WITH KEY JOBCOUNT = I_TBTCP-JOBCOUNT.
      IF SY-SUBRC = 0.
        IF NOT I_TBTCP-LISTIDENT IS INITIAL.
          PACK I_TBTCP-LISTIDENT TO I_SPOOLS2-RQIDENT.
          APPEND I_SPOOLS2.
          CLEAR  I_SPOOLS2.
        ENDIF.
      ENDIF.
    ENDLOOP.

    IF NOT I_SPOOLS2[] IS INITIAL.
      SELECT RQIDENT
        FROM TSP01
        INTO TABLE I_SPOOLS
        FOR ALL ENTRIES IN I_SPOOLS2
        WHERE RQIDENT = I_SPOOLS2-RQIDENT.
    ENDIF.

Hope this will helpful to you. Let m eknow if you have any questions.

Thanks&Regards,

Siri.

Former Member
0 Kudos

Hi again,

1. I assume u will use the standard FM

JOB_OPEN

JOB_SUBMIT

JOB_CLOSE

to run your NEW program in background.

2. The important thing here is JOB_CLOSE

3. In this FM, there are two parameters.

event_id = 'SAP_END_OF_JOB'

event_param = eventparm

(see below for eventparm)

4. Declaration

DATA : eventparm LIKE tbtcjob-eventparm.

5. eventparm = jobname.

eventparm+32 = jobcount.

(where jobname and jobcount refers the original job)

6. I have tried this and it works fantastic.

7. If u want to achieve this manually,

ie thru SM36,

then in START Condition Button,

AFTER EVENT Button

u can specify Event, and Parameter as above.

regards,

amit m.

former_member223537
Active Contributor
0 Kudos

Hi,

Use JOB_OPEN, pass the job name & get the jobcount which is a unique id to refer to your job.

Then use JOB_SUBMIT to Submit the job in background. Here you need to pass the jobname & jobcount. If you want the spool output to go to a printer then use GET_PRINT_PARAMETERS to get the print parameters & pass the same in JOB_SUBMIT.

Then close the Job using JOB_CLOSE.

To get the spool number use FM BP_JOB_READ. Pass jobname & jobcount & get job steplist. Read the same & get the spool number.

REFRESH : i_jobsteplist.

SET PF-STATUS 'AGENCY'.

*----


  • Get the Spool Number

*----


CALL FUNCTION 'BP_JOB_READ'

EXPORTING

job_read_jobcount = w_jobcount

job_read_jobname = w_jobname

job_read_opcode = '20'

  • JOB_STEP_NUMBER =

IMPORTING

job_read_jobhead = wa_jobhead

TABLES

job_read_steplist = i_jobsteplist

  • CHANGING

  • RET =

EXCEPTIONS

invalid_opcode = 1

job_doesnt_exist = 2

job_doesnt_have_steps = 3

OTHERS = 4

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*----


  • Read the Job Step list to get the spool number

*----


READ TABLE i_jobsteplist INTO wa_jobsteplist INDEX 1.

CHECK wa_jobsteplist-listident <> space.

*----


  • Spool Number

*----


l_rqident = wa_jobsteplist-listident.

*----


  • Check the spool in TSP01

*----


SELECT SINGLE * FROM tsp01 WHERE rqident = l_rqident.

IF sy-subrc = 0.

LEAVE TO LIST-PROCESSING.

*----


  • Display the Spool Content on Screen

*----


CALL FUNCTION 'RSPO_DISPLAY_SPOOLJOB'

EXPORTING

rqident = l_rqident

  • FIRST_LINE = 1

  • LAST_LINE =

EXCEPTIONS

no_such_job = 1

job_contains_no_data = 2

selection_empty = 3

no_permission = 4

can_not_access = 5

read_error = 6

OTHERS = 7

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

To get the status of the job, get Jobhead from FM BP_JOB_READ.

*----


  • To Display the STATUS of the JOB which is exectued in background

*----


CLEAR : wa_jobsteplist.

REFRESH : i_jobsteplist.

WRITE:/ text-044. " 'DISPLAYING JOB STATUS'

CALL FUNCTION 'BP_JOB_READ'

EXPORTING

job_read_jobcount = w_jobcount

job_read_jobname = w_jobname

job_read_opcode = '20'

  • JOB_STEP_NUMBER =

IMPORTING

job_read_jobhead = wa_jobhead

TABLES

job_read_steplist = i_jobsteplist

  • CHANGING

  • RET =

EXCEPTIONS

invalid_opcode = 1

job_doesnt_exist = 2

job_doesnt_have_steps = 3

OTHERS = 4

.

*----


  • To Display the status text as per the status type

*----


CASE wa_jobhead-status.

WHEN 'S'. WRITE: / text-045. "'Scheduled'.

WHEN 'R'. WRITE: / text-046. "'Released'.

WHEN 'F'. WRITE: / text-047. "'Completed'.

WHEN 'A'. WRITE: / text-048. "'Cancelled'.

WHEN OTHERS.

ENDCASE.

Now, inorder to see the job log :-

*----


  • To display the log of the background program

*----


LEAVE TO LIST-PROCESSING.

CALL FUNCTION 'BP_JOBLOG_SHOW_SM37B'

EXPORTING

client = sy-mandt

jobcount = w_jobcount

joblogid = ' '

jobname = w_jobname

EXCEPTIONS

error_reading_jobdata = 1

error_reading_joblog_data = 2

jobcount_missing = 3

joblog_does_not_exist = 4

joblog_is_empty = 5

joblog_show_canceled = 6

jobname_missing = 7

job_does_not_exist = 8

no_joblog_there_yet = 9

no_show_privilege_given = 10

OTHERS = 11.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Hope this solves the problem.

Best regards,

Prashant