‎2007 May 07 9:46 AM
Hi friends,
can we run the report in background through coding & how??
thanks,
Prashant
‎2007 May 07 9:49 AM
1. If you want to run something immeidately in the background, then you can use the SUBMIT REPORT option.
2. IF you want to schedule the job, you can call the functions, JOB_OPEN, JOB_SUBMIT / SUBMIT REPORT THROUGHT JOB NUMBER, JOB_CLOSE.
~As found in forum
Regards,
Amit
Reward all helpful replies.
‎2007 May 07 9:48 AM
hi,
There are two ways for you to handle,
one manually setting up the job through SM36 which is better and convinient,
secondly through program using FM's JOB_OPEN, SUBMIT, JOB_CLOSE.
Find below steps in doing both:
Procedure 1:
1. Goto Trans -> SM36
2. Define a job with the program and variant if any
3. Click on start condition in application tool bar
4. In the pop-up window, click on Date/Time
5. Below you can see a check box "Periodic Job"
6. Next click on Period Values
7. Select "Other Period"
8. Now give '15' for Minutes
9. Save the job
In SM37 u can check the status of the jobs that u have assigned to background...
Here u mention the job name or the report name to check the status of the job...
After mentioning the job name or program name u just execute it.. ( without any name also u can execute then it gives u all the jobs set by your user name..
the status colud be released,active,finished etc..
Procedure 2 via Program:
Below is a sample code for the same. Note the ZTEMP2 is the program i am scheduling with 15mins frequency.
DATA: P_JOBCNT LIKE TBTCJOB-JOBCOUNT,
L_RELEASE(1) TYPE c.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBNAME = 'ZTEMP2'
IMPORTING
JOBCOUNT = P_JOBCNT
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.
SUBMIT ZTEMP2 VIA JOB 'ZTEMP2' NUMBER P_JOBCNT
TO SAP-SPOOL WITHOUT SPOOL DYNPRO
WITH DESTINATION = 'HPMISPRT'
WITH IMMEDIATELY = SPACE
WITH KEEP_IN_SPOOL = 'X' AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBCOUNT = P_JOBCNT
JOBNAME = 'ZTEMP2'
STRTIMMED = 'X'
PRDMINS = 15
IMPORTING
JOB_WAS_RELEASED = L_RELEASE
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Hope the above helps you.
Kind Regards
Reshma
‎2007 May 07 9:49 AM
1. If you want to run something immeidately in the background, then you can use the SUBMIT REPORT option.
2. IF you want to schedule the job, you can call the functions, JOB_OPEN, JOB_SUBMIT / SUBMIT REPORT THROUGHT JOB NUMBER, JOB_CLOSE.
~As found in forum
Regards,
Amit
Reward all helpful replies.
‎2007 May 07 9:49 AM
‎2007 May 07 9:51 AM
HI,
*Submit report as job(i.e. in background)
data: jobname like tbtcjob-jobname value
' TRANSFER TRANSLATION'.
data: jobcount like tbtcjob-jobcount,
host like msxxlist-host.
data: begin of starttime.
include structure tbtcstrt.
data: end of starttime.
data: starttimeimmediate like btch0000-char1.
* Job open
call function 'JOB_OPEN'
exporting
delanfrep = ' '
jobgroup = ' '
jobname = jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit
importing
jobcount = jobcount
exceptions
cant_create_job = 01
invalid_job_data = 02
jobname_missing = 03.
if sy-subrc ne 0.
"error processing
endif.
* Insert process into job
SUBMIT zreport and return
with p_param1 = 'value'
with p_param2 = 'value'
user sy-uname
via job jobname
number jobcount.
if sy-subrc > 0.
"error processing
endif.
* Close job
starttime-sdlstrtdt = sy-datum + 1.
starttime-sdlstrttm = '220000'.
call function 'JOB_CLOSE'
exporting
event_id = starttime-eventid
event_param = starttime-eventparm
event_periodic = starttime-periodic
jobcount = jobcount
jobname = jobname
laststrtdt = starttime-laststrtdt
laststrttm = starttime-laststrttm
prddays = 1
prdhours = 0
prdmins = 0
prdmonths = 0
prdweeks = 0
sdlstrtdt = starttime-sdlstrtdt
sdlstrttm = starttime-sdlstrttm
strtimmed = starttimeimmediate
targetsystem = host
exceptions
cant_start_immediate = 01
invalid_startdate = 02
jobname_missing = 03
job_close_failed = 04
job_nosteps = 05
job_notex = 06
lock_failed = 07
others = 99.
if sy-subrc eq 0.
"error processing
endif.Regards
Sudheer
‎2007 May 07 10:13 AM
Hi Prashant,
inorder to run a report in background, u need to use these function modules
JOB_OPEN,
JOB_SUBMIT,
JOB_CLOSE.
Regards,
Vara Prasad
‎2008 May 27 2:13 PM
Hi friends,
I need to schedule the RSEOUT00 in Background
so I am creating the VARIANT using the
function Module RS_CREATE_VARIANT
and then calling by the func modules
JOB_OPEN,
JOB _ SUBMIT,
JOB_CLOSE.
Then we need to schedule the RSEOUT00 Program in Back ground or any thing we need to do extra.
PERFORM check_jobs TABLES gt_idocs
CHANGING gv_flg_error
gv_flg_exit.
&----
*& Form CHECK_JOBS
&----
text
----
FORM check_jobs TABLES t_idocs STRUCTURE gw_idocs
CHANGING xy_flg_error TYPE flag
xy_flg_exit TYPE flag.
DATA : lt_curjobs TYPE STANDARD TABLE OF lx_joblist_tab,
lt_jobstatus TYPE STANDARD TABLE OF lx_jobstatus,
lw_jobstatus TYPE lx_jobstatus,
lv_flg_complete TYPE flag,
lv_flg_error TYPE flag,
lv_seconds TYPE i,
lv_currjobs TYPE i .
CONSTANTS : lc_jobstatus_a VALUE 'A',
lc_jobstatus_f VALUE 'F'.
CLEAR: lv_flg_complete.
Converting the Minutes into Seconds
lv_seconds = xv_minute * 60.
PERFORM create_jobs TABLES t_idocs
lt_curjobs.
WHILE lt_curjobs[] IS NOT INITIAL.
SELECT query IS necessary inside loop AS after each quarter an
hour,table is supposed to be checked against job completion status
REFRESH: lt_jobstatus.
SELECT jobname jobcount status
INTO TABLE lt_jobstatus
FROM tbtco
FOR ALL ENTRIES IN lt_curjobs
WHERE jobname = lt_curjobs-jobname
AND jobcount = lt_curjobs-jobcount
AND status IN (lc_jobstatus_a , lc_jobstatus_f).
IF sy-subrc = 0.
SORT lt_jobstatus BY status.
READ TABLE lt_jobstatus INTO lw_jobstatus
WITH KEY status = lc_jobstatus_a
BINARY SEARCH.
IF sy-subrc = 0.
error generated
lv_flg_error = gc_true.
ENDIF.
DELETE the details of the processed records.
DELETE lt_curjobs WHERE jobname = lw_jobstatus-jobname.
ENDIF.
CLEAR: lv_currjobs.
lv_currjobs = LINES( lt_curjobs ).
IF lv_currjobs IS INITIAL.
If there are no Jobs Exit
EXIT.
ENDIF.
IF lv_flg_error = gc_true.
xy_flg_error = gc_true.
CLEAR: xy_flg_exit.
RETURN.
ELSE.
xy_flg_exit = gc_true.
CLEAR: xy_flg_error.
ENDIF.
ENDWHILE.
ENDFORM. " CHECK_JOBS
&----
*& Form CREATE_JOBS
&----
text
----
FORM create_jobs TABLES t_idocs STRUCTURE gw_idocs
t_curjobs STRUCTURE gw_curjobs.
CONSTANTS :
lc_repid TYPE sy-repid VALUE 'ZDM_CI_METERREADINGOUTBOUND',
lc_jobclass TYPE tbtcjob-jobclass VALUE 'B'.
DATA : lt_params TYPE STANDARD TABLE OF rsparams,
lt_text TYPE STANDARD TABLE OF varit,
lw_params TYPE rsparams,
lw_text TYPE varit,
lw_desc TYPE varid,
lv_variant TYPE rsvar-variant,
lv_jobname TYPE tbtcjob-jobname,
lv_count TYPE tbtcjob-jobcount.
LOOP AT t_idocs INTO gw_idocs.
----
Variant Creation
----
Wait is added to differentiate between the names of the variants
WAIT UP TO 1 SECONDS.
CONCATENATE gw_idocs-mru sy-datum+2 sy-uzeit INTO lv_variant.
CONDENSE lv_variant NO-GAPS.
Fill in the Parameters
lw_params-selname = 'DOCNUM'.
lw_params-kind = 'S'.
lw_params-sign = 'I'.
lw_params-option = 'EQ'.
lw_params-low = gw_idocs-docnum.
APPEND lw_params TO lt_params.
Fill in the variant description
lw_desc-mandt = sy-mandt.
lw_desc-report = lc_repid.
lw_desc-variant = lv_variant.
Fill in the variant text
lw_text-mandt = sy-mandt.
lw_text-langu = sy-langu.
lw_text-report = lc_repid.
lw_text-variant = lv_variant.
lw_text-vtext = lv_variant.
APPEND lw_text TO lt_text.
CREATE THE VARIANT
CALL FUNCTION 'RS_CREATE_VARIANT'
EXPORTING
curr_report = lc_repid
curr_variant = lv_variant
vari_desc = lw_desc
TABLES
vari_contents = lt_params
vari_text = lt_text
EXCEPTIONS
illegal_report_or_variant = 1
illegal_variantname = 2
not_authorized = 3
not_executed = 4
report_not_existent = 5
report_not_supplied = 6
variant_exists = 7
variant_locked = 8
OTHERS = 9.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
----
Job Scheduling
----
SCHEDULE THE JOB
lv_jobname = lc_repid.
CLEAR: lv_count.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
jobclass = lc_jobclass
IMPORTING
jobcount = lv_count
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
Background Job Creation Error.
MESSAGE s000(zmtx_dm) WITH text-021.
CONTINUE.
ENDIF.
Message to be included in Job description as a step
Background job <JOB NAME> <JOB ID> scheduled.
MESSAGE s000(zmtx_dm) WITH text-022 lv_jobname
lv_count text-023.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
authcknam = sy-uname
jobcount = lv_count
jobname = lv_jobname
report = lc_repid
variant = lv_variant
EXCEPTIONS
bad_priparams = 1
bad_xpgflags = 2
invalid_jobdata = 3
jobname_missing = 4
job_notex = 5
job_submit_failed = 6
lock_failed = 7
program_missing = 8
prog_abap_and_extpg_set = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE s000(zmtx_dm) WITH text-008.
"Background Job Submitting Error
CONTINUE.
ENDIF.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_count
jobname = lv_jobname
strtimmed = gc_true
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.
Message to be included in Job description as a step
MESSAGE s000(zumt_gen) WITH text-009.
" Background Job Closing Error
CONTINUE.
ENDIF.
gw_curjobs-variant = lv_variant.
gw_curjobs-jobname = lv_jobname.
gw_curjobs-jobcount = lv_count.
APPEND gw_curjobs TO t_curjobs.
ENDLOOP.
ENDFORM. " CREATE_SCHD_JOBS
Kindly guide me,
Thanks in Advance.
Ganesh.