‎2008 Jun 11 7:05 PM
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
‎2008 Jun 11 7:30 PM
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.
‎2008 Jun 11 7:15 PM
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
‎2008 Jun 11 7:30 PM
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.
‎2008 Jun 11 7:53 PM
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