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 create a program to schedule a job

Former Member
0 Kudos

Hi Friends,

I want to create a report that will run another program(program2) in background. What I need to do is, when I enter the transaction code of this program(report), it will automatically run the program2 in background. I tried using JOB_OPEN, JOB_SUBMIT and JOB_CLOSE. But when I checked in SM36, the job is just scheduled. I still need to release for the program to run.I should not be doing that anymore. The second program should automatically run when I enter the transaction code.

Please help.

Thanks,

zryxel

1 ACCEPTED SOLUTION

Jelena
Active Contributor

Did you use 'start immediately' parameter?

    CALL FUNCTION 'JOB_CLOSE'
      EXPORTING
        jobcount  = jobcount
        jobname   = jobname
        strtimmed = 'X'.            " Start immediately

Another option to consider would be to create an event-periodic job and simply trigger the event in your program (see FM BP_EVENT_RAISE).

2 REPLIES 2

Jelena
Active Contributor

Did you use 'start immediately' parameter?

    CALL FUNCTION 'JOB_CLOSE'
      EXPORTING
        jobcount  = jobcount
        jobname   = jobname
        strtimmed = 'X'.            " Start immediately

Another option to consider would be to create an event-periodic job and simply trigger the event in your program (see FM BP_EVENT_RAISE).

Former Member
0 Kudos

Hi,

Check this example..

DATA: p_jobcnt LIKE tbtcjob-jobcount,

l_release(1) TYPE c.

<b>* Open the job</b>

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = 'ZMY_OBJ'

IMPORTING

jobcount = p_jobcnt

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3

OTHERS = 4.

<b>* Submit the job.</b>

SUBMIT ztest_program VIA JOB 'ZMY_OBJ' NUMBER p_jobcnt

TO SAP-SPOOL WITHOUT SPOOL DYNPRO

WITH destination = 'LOCL'

WITH immediately = space

WITH keep_in_spool = 'X' AND RETURN.

<b>* Close the job.</b>

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = p_jobcnt

jobname = 'ZMY_OBJ'

<b>strtimmed = 'X'</b>

prdmins = 15

IMPORTING

job_was_released = l_release.

Thanks,

Naren