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

Background Job not getting Released

Former Member
0 Likes
2,937

Hi all,

I am trying to schedule a background job but i am facing a problem it is getting scheduled instead of Starting Immediately. How to Release it. I have searched the forum but could not get a working solution for my case. I used the following Code.

   call function 'JOB_OPEN'

     exporting

*    DELANFREP              = ' '

*    JOBGROUP               = ' '

      jobname                = jobname

      sdlstrtdt              = sy-datum

      sdlstrttm              = sy-uzeit

      jobclass               = 'C'

    importing

      jobcount               = jobcount

    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.

call function 'GET_PRINT_PARAMETERS'

  EXPORTING

     IMMEDIATELY                    = 'X'

     NO_DIALOG                      = C_TRUE

     RELEASE                        = 'X'

     USER                           = SY-UNAME

  IMPORTING

*   OUT_ARCHIVE_PARAMETERS         =

     OUT_PARAMETERS                 = parameters

     VALID                          = valid

           .

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 (program_name) using selection-set variant via job jobname number jobcount to sap-spool without spool dynpro

         spool parameters parameters and return.

   sdlstrtdt = sy-datum .

   sdlstrttm = sy-uzeit.

do.

   call function 'JOB_CLOSE'

     exporting

       jobcount             = jobcount

       jobname              = jobname

       sdlstrtdt            = sdlstrtdt

       sdlstrttm            = sdlstrttm

       strtimmed            = 'X'

     importing

       job_was_released     = released

     changing

       ret                  = ret

     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.

     exit.

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

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

   endif.

enddo.

but i am getting exception invalid Start Date on execution of Job_Close FM Since the job did not start and has been Scheduled

1 ACCEPTED SOLUTION
Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,357

Did you try without passing start_date and start_time to JOB_CLOSE?

Hi all,

I am trying to schedule a background job but i am facing a problem it is getting scheduled instead of Starting Immediately. How to Release it. I have searched the forum but could not get a working solution for my case. I used the following Code.

   call function 'JOB_OPEN'

     exporting

*    DELANFREP              = ' '

*    JOBGROUP               = ' '

      jobname                = jobname

      sdlstrtdt              = sy-datum

      sdlstrttm              = sy-uzeit

      jobclass               = 'C'

    importing

      jobcount               = jobcount

    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.

call function 'GET_PRINT_PARAMETERS'

  EXPORTING

     IMMEDIATELY                    = 'X'

     NO_DIALOG                      = C_TRUE

     RELEASE                        = 'X'

     USER                           = SY-UNAME

  IMPORTING

*   OUT_ARCHIVE_PARAMETERS         =

     OUT_PARAMETERS                 = parameters

     VALID                          = valid

           .

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 (program_name) using selection-set variant via job jobname number jobcount to sap-spool without spool dynpro

         spool parameters parameters and return.

   sdlstrtdt = sy-datum .

   sdlstrttm = sy-uzeit.

do.

   call function 'JOB_CLOSE'

     exporting

       jobcount             = jobcount

       jobname              = jobname

       sdlstrtdt            = sdlstrtdt

       sdlstrttm            = sdlstrttm

       strtimmed            = 'X'

     importing

       job_was_released     = released

     changing

       ret                  = ret

     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.

     exit.

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

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

   endif.

enddo.

but i am getting exception invalid Start Date on execution of Job_Close FM Since the job did not start and has been Scheduled

11 REPLIES 11
Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,358

Did you try without passing start_date and start_time to JOB_CLOSE?

Read only

Former Member
0 Likes
2,357

It worked. Thanks a lot. Could you please help me find the spool number generated because Sy-spono is 0 and i used the following code but getting wrong spool number.

  

   f_repid = program_name.

   f_uname = sy-uname.

   move f_repid+0(12) to lc_rq2name.

   condense lc_rq2name.

   select * from tsp01

           where  rq2name = lc_rq2name

             and  rqowner = sy-uname

           order by rqcretime descending.

     exit.

   endselect.

   f_rqident = tsp01-rqident.

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,357

Aren't you getting the spool in the output from FM GET_PRINT_PARAMETERS?

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,357

Once the Job Completed then only you can get the Spool. It will commit in the table TSP01. Till then you need to wait. You can use additional button to show up.. check the below code.

In the GET_PRINT_PARAMETERS Function module

check this Importing Parameter parameter-PLIST

Submit the Job like this

   *submit job with all the selection screen params...
SUBMIT (JOB_NAME) USER SYST-UNAME
VIA JOB JOB_NAME NUMBER JOB_NR
WITH CLIENT   = CLIENT
WITH MONIFROM = MONIFROM
WITH MONI_TO  = MONI_TO
WITH TQ_FROM  = TQ_FROM
WITH TQ_TO    = TQ_TO
WITH SPOOLNR  = SPOOLNR----------> This is of type TSP01-RQIDENT
TO SAP-SPOOL SPOOL PARAMETERS PARAMS
WITHOUT SPOOL DYNPRO
AND RETURN.

Hope this helps

Read only

Former Member
0 Likes
2,357

No I am not and I have used that FM get_print_parameters before the submit statement. Did you mean it gets modified in the Submit statement and if true even that is not happening in my case.

Regards,

Chandni Sharma

Read only

Former Member
0 Likes
2,357

Plist Contains the first 9 characters of the name of the program and the first 3 characters of my User ID.

And what I understood is Submit Statement is scheduling the job and Job_close is releasing it. But until the job is released the spool number will not be generated. I tried doing the same but still getting 0 in the variable Spool_nr.

Thanks & Regards,

Chandni Sharma.

Read only

0 Likes
2,357

Are you asking this for the background job, if yes

  • First get job info with FM GET_JOB_RUNTIME_INFO in the background job, else use values of jobname and jobcount from the caller program
  • Check status of job with FM BP_JOB_STATUS_GET
  • Then get spool info from table TBTC_SPOOLID.

Regards,

Raymond

Read only

Former Member
0 Likes
2,357

Tried the same but it gives me an exception no runtime info. But i could use tbtc_spoolid but the problem is i think i will have to order by Spool Count in descending order and then take the grea
test one assuming this to be the latest one corresponding to the Jobname and Jobcount i have provided.


Thanks & Regards,

Chandni Sharma.

Read only

Former Member
0 Likes
2,357

Tried the same but it gives me an exception no runtime info. But i could use tbtc_spoolid but the problem is i think i will have to order by Spool Count in descending order and then take the grea
test one assuming this to be the latest one corresponding to the Jobname and Jobcount i have provided.

and I am not getting the spool_id when i execute the program in background. i even used Wait up to 5 seconds. But still no value.


Thanks & Regards,

Chandni Sharma.

Read only

0 Likes
2,357

When executing in background you MUST use BP_JOB_STATUS_GET to insure job (step) is completed, else spool wont have been genrated.

Regards,

Raymond

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,357

WITH SPOOLNR  = SPOOLNR----------> This is of type TSP01-RQIDENT

Using WITH you pass the selection-screen parameters to the SUBMIT'ted program. AFAIK there is no such addition for the SUBMIT statement.

Release 731 documentation does not mention this addition in the SUBMIT statement. Can you redirect me to the one you are referring to!

BR,

Suhas