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: 

How to schedule background job?

Former Member
0 Kudos
1,664

I want to schedule a background job, which has to execute a program at the scheduled time.

Please let me know how can i achieve this in ABAP?

1 ACCEPTED SOLUTION

0 Kudos
287

Dear Pallavi,

You can do this using function modules 'JOB_OPEN', 'JOB_CLOSED' and SUBMIT statement.

Please find the below example.

*Submit report as job(i.e. in background)

data: jobname like tbtcjob-jobname value

' TRANSFER TRANSLATION'.

data: jobcount like tbtcjob-jobcount,

host like msxxlist-host.

data: begin of starttime.

include structure tbtcstrt.

data: end of starttime.

data: starttimeimmediate like btch0000-char1.

  • Job open

call function 'JOB_OPEN'

exporting

delanfrep = ' '

jobgroup = ' '

jobname = jobname

sdlstrtdt = sy-datum

sdlstrttm = sy-uzeit

importing

jobcount = jobcount

exceptions

cant_create_job = 01

invalid_job_data = 02

jobname_missing = 03.

if sy-subrc ne 0.

"error processing

endif.

  • Insert process into job

SUBMIT zreport and return

with p_param1 = 'value'

with p_param2 = 'value'

user sy-uname

via job jobname

number jobcount.

if sy-subrc > 0.

"error processing

endif.

  • Close job

starttime-sdlstrtdt = sy-datum + 1.

starttime-sdlstrttm = '220000'.

call function 'JOB_CLOSE'

exporting

event_id = starttime-eventid

event_param = starttime-eventparm

event_periodic = starttime-periodic

jobcount = jobcount

jobname = jobname

laststrtdt = starttime-laststrtdt

laststrttm = starttime-laststrttm

prddays = 1

prdhours = 0

prdmins = 0

prdmonths = 0

prdweeks = 0

sdlstrtdt = starttime-sdlstrtdt

sdlstrttm = starttime-sdlstrttm

strtimmed = starttimeimmediate

targetsystem = host

exceptions

cant_start_immediate = 01

invalid_startdate = 02

jobname_missing = 03

job_close_failed = 04

job_nosteps = 05

job_notex = 06

lock_failed = 07

others = 99.

if sy-subrc eq 0.

"error processing

endif.

Thanks & Regards

Sastry

6 REPLIES 6

0 Kudos
288

Dear Pallavi,

You can do this using function modules 'JOB_OPEN', 'JOB_CLOSED' and SUBMIT statement.

Please find the below example.

*Submit report as job(i.e. in background)

data: jobname like tbtcjob-jobname value

' TRANSFER TRANSLATION'.

data: jobcount like tbtcjob-jobcount,

host like msxxlist-host.

data: begin of starttime.

include structure tbtcstrt.

data: end of starttime.

data: starttimeimmediate like btch0000-char1.

  • Job open

call function 'JOB_OPEN'

exporting

delanfrep = ' '

jobgroup = ' '

jobname = jobname

sdlstrtdt = sy-datum

sdlstrttm = sy-uzeit

importing

jobcount = jobcount

exceptions

cant_create_job = 01

invalid_job_data = 02

jobname_missing = 03.

if sy-subrc ne 0.

"error processing

endif.

  • Insert process into job

SUBMIT zreport and return

with p_param1 = 'value'

with p_param2 = 'value'

user sy-uname

via job jobname

number jobcount.

if sy-subrc > 0.

"error processing

endif.

  • Close job

starttime-sdlstrtdt = sy-datum + 1.

starttime-sdlstrttm = '220000'.

call function 'JOB_CLOSE'

exporting

event_id = starttime-eventid

event_param = starttime-eventparm

event_periodic = starttime-periodic

jobcount = jobcount

jobname = jobname

laststrtdt = starttime-laststrtdt

laststrttm = starttime-laststrttm

prddays = 1

prdhours = 0

prdmins = 0

prdmonths = 0

prdweeks = 0

sdlstrtdt = starttime-sdlstrtdt

sdlstrttm = starttime-sdlstrttm

strtimmed = starttimeimmediate

targetsystem = host

exceptions

cant_start_immediate = 01

invalid_startdate = 02

jobname_missing = 03

job_close_failed = 04

job_nosteps = 05

job_notex = 06

lock_failed = 07

others = 99.

if sy-subrc eq 0.

"error processing

endif.

Thanks & Regards

Sastry

0 Kudos
287

hi,

go to SM35/SM36 you can schedulke your job in backgroung ..

else in your selection screen program-->background job

rewards if useful,

regards,

nazeer

Former Member
0 Kudos
287

Hello,

Check this out.

If you want to execute the job in background .There are 2 options.

1.Online

Goto se38-->enter program name >(On menu bar) program>

Exceute-->Background.

2.Schedule

Scheduling Background Jobs:

1. Background jobs are scheduled by Basis administrators using transaction SM36.

2. To run a report in a background, a job needs to be created with a step using the report name

and a variant for selection parameters. It is recommended to create a separate variant for each

scheduled job to produce results for specific dates (e.g. previous month) or organizational units (e.g. company codes).

3. While defining the step, the spool parameters needs to be specified

(Step-> Print Specifications->Properties) to secure the output of the report and help authorized users to find the spool request. The following parameters needs to be maintained:

a. Time of printing: set to “Send to SAP spooler Only for now”

b. Name – abbreviated name to identify the job output

c. Title – free form description for the report output

d. Authorization – a value defined by Security in user profiles to allow those users to access

this spool request (authorization object S_SPO_ACT, value SPOAUTH). Only users with matching authorization value in their profiles will be able to see the output.

e. Department – set to appropriate department/functional area name. This field can be used in

a search later.

f. Retention period – set to “Do not delete” if the report output needs to be retained for more

than 8 days. Once the archiving/document repository solution is in place the spool requests could

be automatically moved to the archive/repository. Storage Mode parameter on the same screen

could be used to immediately send the output to archive instead of creating a spool request.

Configuring user access:

1. To access a report output created by a background job, a user must have at least access to SP01 (Spool requests) transaction without restriction on the user name (however by itself it will not let the user to see all spool requests). To have that access the user must have S_ADMI_FCD authorization object in the profile with SPOR (or SP01) value of S_ADMI_FCD parameter (maintained by Security).

2. To access a particular job’s output in the spool, the user must have S_SPO_ACT object in the profile with SPOAUTH parameter matching the value used in the Print Specifications of the job (see p. 3.d above).

3. Levels of access to the spool (display, print once, reprint, download, etc) are controlled by SPOACTION parameter of S_SPO_ACT. The user must have at least BASE access (display).

On-line reports:

1. Exactly the same configuration can be maintained for any output produced from R/3. If a user clicks “Parameters” button on a SAP Printer selection dialog, it allows to specify all the parameters as described in p. 3 of “Scheduling background jobs” section. Thus any output created by an online report can be saved and accessed by any user authorized to access that spool request (access restriction provided by the Authorization field of the spool request attributes, see p. 3.d of “Scheduling background jobs” section).

Access to report’s output:

1. A user that had proper access (see Configuring user access above) can retrieve a job/report output through transaction SP01.

2. The selection screen can be configured by clicking “Further selection criteria…” button (e.g. to bring “Spool request name (suffix 2)” field or hide other fields).

3. The following fields can be used to search for a specific output (Note that Created By must be blank when searching for scheduled job’s outputs)

a. Spool request name (suffix 2) – corresponds to a spool name in p. 3.b in “Scheduling background jobs” section above).

b. Date created – to find an output of a job that ran within a certain date range.

c. Title – corresponds to spool Title in p. 3.c in “Scheduling background jobs” section above).

d. Department - corresponds to spool Department in p. 3.e in “Scheduling background jobs” section above).

4. Upon entering selection criteria, the user clicks the Execute button to retrieve the list of matching spool requests.

5. From the spool list the user can use several function such as view the content of a spool request, print the spool request, view attributed of the spool request, etc. (some functions may need special authorization, see p.3 in Configuring user access)

a. Click the Print button to print the spool request with the default attributes (usually defined with the job definition). It will print it on a printer that was specified when a job was created.

b. Click the “Print with changed attributed” button to print the spool request with the different attributes (e.g. changing the printer name).

c. Click the “Display contents” button to preview the spool request contents. A Print and Download functions are available from the preview mode.

Afetr scheduling the job , you can check the status iof the job using SM37 Transaction code.

Hope this resolves your query.

Reward all the helpful answers.

Regards

Deepu.K

Former Member
0 Kudos
287

Hi,

To schedule B/g job,

go to Tcode SM36, provide Job name

Job calsss and stsatus.

and give the JOb START condtions (ex immediate, or date/time....and wheteher periodic/not) and give the report Name which u wantto schedule.

At that particular time it will execute the job.

if u wanna see the output of Job , go to tcode SM37 and see spool list

Revert back if any issues.

Reward with points if helpful.

Regards,

Naveen

Former Member
0 Kudos
287

hi Pallavi,

first execute the program then press f9 to scedule ur program.

then goto the sm36 to schedule ur job .herer you can give the timing for the op.

reward if helpful answer.

Thanks.

Paresh.

Former Member
0 Kudos
287

Hai,

There are two ways for you to handle,

one manually setting up the job through SM36 which is better and convinient,

secondly through program using FM's JOB_OPEN, SUBMIT, JOB_CLOSE.

Find below steps in doing both:

Procedure 1:

1. Goto Trans -> SM36

2. Define a job with the program and variant if any

3. Click on start condition in application tool bar

4. In the pop-up window, click on Date/Time

5. Below you can see a check box "Periodic Job"

6. Next click on Period Values

7. Select "Other Period"

8. Now give '15' for Minutes

9. Save the job

In SM37 u can check the status of the jobs that u have assigned to background...

Here u mention the job name or the report name to check the status of the job...

After mentioning the job name or program name u just execute it.. ( without any name also u can execute then it gives u all the jobs set by your user name..

the status colud be released,active,finished etc..

Procedure 2 via Program:

Below is a sample code for the same. Note the ZTEMP2 is the program i am scheduling with 15mins frequency.

DATA: P_JOBCNT LIKE TBTCJOB-JOBCOUNT,

L_RELEASE(1) TYPE c.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

JOBNAME = 'ZTEMP2'

IMPORTING

JOBCOUNT = P_JOBCNT

EXCEPTIONS

CANT_CREATE_JOB = 1

INVALID_JOB_DATA = 2

JOBNAME_MISSING = 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.

SUBMIT ZTEMP2 VIA JOB 'ZTEMP2' NUMBER P_JOBCNT

TO SAP-SPOOL WITHOUT SPOOL DYNPRO

WITH DESTINATION = 'HPMISPRT'

WITH IMMEDIATELY = SPACE

WITH KEEP_IN_SPOOL = 'X' AND RETURN.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

JOBCOUNT = P_JOBCNT

JOBNAME = 'ZTEMP2'

STRTIMMED = 'X'

PRDMINS = 15

IMPORTING

JOB_WAS_RELEASED = L_RELEASE

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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Regards,

Padmam.