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: 

Code to create a job in background

Former Member
0 Kudos
494

Hi,

     I am written below code to create a job in background  .

     Some time job runs successfully and status 'finished',  sometime job status 'Scheduled' .

        

     For same user this happens.

     We have three instances of application server.

CALL FUNCTION 'JOB_OPEN'
         EXPORTING
*         DELANFREP        = ' '
*         JOBGROUP         = ' '
           JOBNAME          = JOBNAME
           SDLSTRTDT        = DAT
           SDLSTRTTM        = TIM
*         JOBCLASS         =
*         CHECK_JOBCLASS   =
         IMPORTING
           JOBCOUNT         = JOBNUMBER
*         INFO             =
*       CHANGING
*         RET              =
         EXCEPTIONS
           CANT_CREATE_JOB  = 1
           INVALID_JOB_DATA = 2
           JOBNAME_MISSING  = 3
           OTHERS           = 4.


       SUBMIT ZMM_MIGO_AUTOGR_POST
         WITH P_JOBID = SHMRY_NAME
         WITH S_ZEILE IN R_ZEILE
         AND RETURN
         USER SY-UNAME "WF_BATCH_ADMIN  "SY-UNAME
         VIA JOB JOBNAME NUMBER JOBNUMBER.


       CALL FUNCTION 'JOB_CLOSE'
         EXPORTING
           JOBCOUNT          = JOBNUMBER
           JOBNAME           = JOBNAME
           SDLSTRTDT         = DAT
           SDLSTRTTM         = TIM
           TARGETSYSTEM      = SY-HOST
         IMPORTING
           JOB_WAS_RELEASED  = JOB_RELEASED
         EXCEPTIONS
           INVALID_STARTDATE = 01
           JOBNAME_MISSING   = 02
           JOB_CLOSE_FAILED  = 03
           JOB_NOSTEPS       = 04
           JOB_NOTEX         = 05
           LOCK_FAILED       = 06
           OTHERS            = 99.

10 REPLIES 10

paul_bakker2
Active Contributor
0 Kudos
442

Do you check the exceptions after making the calls to those 2 function modules? That might give you a good clue as to what is going wrong.

0 Kudos
442

This message was moderated.

0 Kudos
442

This message was moderated.

0 Kudos
442

Hi Pramoth,

What value are you passing to the following export parameters for JOB_OPEN?

      SDLSTRTDT        = DAT

      SDLSTRTTM        = TIM


These are not mandatory, try without using these 2 export variables.

0 Kudos
442

      SDLSTRTDT        = DAT

      SDLSTRTTM        = TIM


I tried without date and time in job_open but , no effect.


Same result.

raymond_giuseppi
Active Contributor
0 Kudos
442

Which value do you pass for start date/time, are you sure they are i the future and valid, also did you fully analyzis error message and or authorization (seems you tryed to change the user name in some version of your program?)

Regards,

Raymond

0 Kudos
442

Hi,

I am not changing username , I use sy-uname .

I pass sy-datum and sy-uzeit, is it correct or should I add some time ( sy-uzeit + 10 ) future time.

Regards

Pramoth CG

0 Kudos
442

So you want to schedule the job immediately, don't use those date/time parameters but use

STRTIMMED = 'X' (There are samples in online documentation look at Sample Program: Immediate Start with JOB_CLOSE)

Regards,

Raymond

0 Kudos
442

0 Kudos
442

Use the link I already provided for the samples, some line earlier you got a Authorizations for Background Processing chapter, look for Releasing jobs to start. But this is most useful when scheduling with another user profile, I mentioned that due to the WF_BATCH_ADMIN in your source code.

All users can schedule, cancel, delete, and check the status of their own jobs with no additional special authorizations.


Hint: Use SE53 to get failed authorization check or execute an authorization trace with ST01.

Regards,

Raymond