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

Schedule a pgm in background using function modules from same program

Former Member
0 Likes
546

Hi Guys,

How to schedule a program in background(using function modules) from same program itself.

When click 'execute' button in report, it should schedule same program in background.

As per my knowledge, this will create an infinite loop if we schedule it normally from same program. How we can restrict the program to schedule it only once.

Hope you guys have already faced the same..

Pls help...

Regards,

Saj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
496

hi this is the example for this program..

DATA: number TYPE tbtcjob-jobcount,

name TYPE tbtcjob-jobname VALUE 'JOB_TEST',

print_parameters TYPE pri_params.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = name

IMPORTING

jobcount = number

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3

OTHERS = 4.

IF sy-subrc = 0.

SUBMIT submitable TO SAP-SPOOL

SPOOL PARAMETERS print_parameters

WITHOUT SPOOL DYNPRO

VIA JOB name NUMBER number

AND RETURN.

IF sy-subrc = 0.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = number

jobname = name

strtimmed = 'X'

EXCEPTIONS

cant_start_immediate = 1

invalid_startdate = 2

jobname_missing = 3

job_close_failed = 4

job_nosteps = 5

job_notex = 6

lock_failed = 7

OTHERS = 8.

IF sy-subrc <> 0.

...

ENDIF.

ENDIF.

ENDIF.

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
496

Yes definatly it will create infinite loop unless you set some variables ... and check them when you submit the program.

Like:


PARAMETERS: P_RUN AS CHECKBOX.  " when it is on, it will create a job

start-of-selection.
IF P_RUN = 'X'.

* call funcation JOB_OPEN

  SUBMIT <PROG>  "WITHOUT P_RUN = 'X'
   with jobname jobcount

* call function JOB_CLOSE

ENDIF.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
497

hi this is the example for this program..

DATA: number TYPE tbtcjob-jobcount,

name TYPE tbtcjob-jobname VALUE 'JOB_TEST',

print_parameters TYPE pri_params.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = name

IMPORTING

jobcount = number

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3

OTHERS = 4.

IF sy-subrc = 0.

SUBMIT submitable TO SAP-SPOOL

SPOOL PARAMETERS print_parameters

WITHOUT SPOOL DYNPRO

VIA JOB name NUMBER number

AND RETURN.

IF sy-subrc = 0.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = number

jobname = name

strtimmed = 'X'

EXCEPTIONS

cant_start_immediate = 1

invalid_startdate = 2

jobname_missing = 3

job_close_failed = 4

job_nosteps = 5

job_notex = 6

lock_failed = 7

OTHERS = 8.

IF sy-subrc <> 0.

...

ENDIF.

ENDIF.

ENDIF.

Read only

former_member195698
Active Contributor
0 Likes
496

You can use SY-BATCH to differentiate between your First Call and the Rest of the Calls.

Since you will call the Program in Foreground for the First time SY-BATCH will be initial and the Report will be scheduled in Background.

Now the Scheduled Report (Background) , will inturn check for the field SY-BATCH. Since SY-BATCH will be filled this time, your code of Submit Via Job will be skipped. So there will be no Recurrsion in the code.

Regards,

Aj