2020 Dec 14 4:20 PM
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.
2020 Dec 14 4:27 PM
Hello pankaj_p
First result of https://www.google.com/search?q=sap+abap+how+to+submit+report+in+background&oq=sap+abap+how+to+submi...
Kind regards,
Mateusz
2020 Dec 14 11:54 PM
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.
2020 Dec 15 9:36 AM
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?
2020 Dec 15 9:44 AM
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 aboveIn that case you would avoid the infinite loop.
2020 Dec 15 10:38 AM
2021 Jan 20 9:10 AM
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.