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

Submit same report for background job schedule

5,083

Requirement -After executing the report should be executed in the bbackground and ALV list should be sent to spool.

My code is somewhat like this.

Report ABC.

selection_screen p_location.

Call Function job_open.

Select query and some data manipulation.

Submit report ABC

with p_location = p_location.

Call Function job_close.

My issue is this is creating n number of background jobs in SM37 and not a single Alv list is visible in spool list. Also, which alv method I should use.

Requirement -After executing the report should be executed in the bbackground and ALV list should be sent to spool.

My code is somewhat like this.

Report ABC.

selection_screen p_location.

Call Function job_open.

Select query and some data manipulation.

Submit report ABC

with p_location = p_location.

Call Function job_close.

My issue is this is creating n number of background jobs in SM37 and not a single Alv list is visible in spool list. Also, which alv method I should use.

6 REPLIES 6
Read only

MateuszAdamus
Active Contributor
0 Likes
4,077
Read only

OlegBash
Active Participant
4,077

I think you should get job number in JOB_OPEN and launch report via submit; also close the with JOB_CLOSE with immediate start.

It could be look like the following

data lV_JOB_NUM	TYPE BTCJOBCNT.
data lv_job_name type BTCJOB value 'ZJOBNAME'.
		  
CALL FUNCTION 'JOB_OPEN'
EXPORTING
  jobname          = lv_job_name
  jobclass         = 'B'
IMPORTING
  jobcount         = lV_JOB_NUM
EXCEPTIONS
  cant_create_job  = 1
  invalid_job_data = 2
  jobname_missing  = 3
  OTHERS           = 4.


if sy-subrc ne 0.
	" raise exception if any
endif.


SUBMIT zprogram_name
VIA JOB lv_job_name
NUMBER lV_JOB_NUM
WITH p_location = p_location
AND RETURN.




CALL FUNCTION 'JOB_CLOSE'
  EXPORTING
	jobcount             = lV_JOB_NUM
	jobname              = lv_job_name
	strtimmed            = 'X'
	sdlstrtdt            = sy-datum
	sdlstrttm            = conv syuzeit( sy-uzeit + 2 )
  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 EQ 0.
" raise exception if any
ENDIF.
Read only

0 Likes
4,077

Hi Oleg,

Thanks for your reply.

Yes I am adding all the things which you have mentioned in the answer.

As I am calling same report in my report , it is going in infinite loop.
I want to avoid that loop and "submit program" should be called only once.

Can you assist on this?

Can we use something like STOP, leave list processing or leave program?

Read only

OlegBash
Active Participant
4,077

In that case you need to create and pass parameter into you report.

E.g. in selection screen of your Z-report.

parameters: no_job type char1 default ' '.

and before planning/scheduling job you need to check this parameter.

if no_job eq abap_false.
schedule_this_rep_as_job( ).
endif.

and in schedule_this_rep_as_job

""" code with job open as above
SUBMIT zprogram_name
VIA JOB lv_job_name
NUMBER lV_JOB_NUM
WITH p_location = p_location
with no_job = abap_true
AND RETURN.

""" code with job close as above

In that case you would avoid the infinite loop.

Read only

RaymondGiuseppi
Active Contributor
4,077

In your report check value of SY-BATCH, if abap_true, 'X', then don't create a new backgroud job but actually execute the report.

Read only

0 Likes
4,077

Hello All,

Thank you for your suggestions.

To achieve the requirement, I have created another report say report_abc and called this report in my main program using job_open, submit report and job_close.