Background Job using JOB_OPEN & JOB_CLOSE
Experts,
I have coded a program in SE38 which calls other program to be scheduled in background using JOB_OPEN , SUBMIT, & JOB_CLOSE. Now my requirement is to send an email to the person who runs (schedules) a job in background by Email (SAP Inbox or office email-ID) of completion of the job. how do i do that?
Kindly send me your solutions.
Thanks.
Here is some code that will determine when a job has completed. We use this daily.
Bruce
start-of-selection.
perform 1000_submit_program.
perform 2000_send_email.
end-of-selection.
*>>>>>>>>> S T A R T O F F O R M S <<<<<<<
*& Form 1000_SUBMIT_Program
form 1000_submit_program.
concatenate 'Program' p_pgm 'finished.'
into w_subject separated by ' '.
*>> concatenate "Submit Program " and the first 17 characters
*>> of the program into the job name parameter
*>> eg "Submit Program ZFAPR061 "
concatenate p_jobnam(15) p_pgm(17) into p_jobnam separated by ' '.
call function 'JOB_OPEN'
exporting
jobname = p_jobnam
importing
jobcount = w_jobcount
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc <> 0.
case sy-subrc.
when 1.
w_code = 'cant_create_job'.
when 2.
w_code = 'invalid_job_data'.
when 3.
w_code = 'jobname_missing'.
when 4.
w_code = 'others'.
endcase.
message i000 with 'JOB_OPEN Error ' w_code ' Program aborted'.
format color col_negative.
skip 2.
write: / 'Program aborted.'.
write: / 'Function JOB_OPEN Error ', w_code.
stop.
endif. " sy-subrc ne 0
format color col_normal.
translate p_pgm to upper case.
get time field w_start . " program started
submit (p_pgm)
to sap-spool
destination p_prtr
immediately ' '
keep in spool 'X'
without spool dynpro
user sy-uname via job p_jobnam number w_jobcount
using selection-set p_var
using selection-sets of program p_pgm
and return.
skip 2.
write: / ' SUBMIT parameters after submit:'.
write: /4 'user ', sy-uname.
write: /4 'job ', p_jobnam.
write: /4 'jobcount ', w_jobcount.
write: /4 'program ', p_pgm.
write: /4 'variant ', p_var.
call function 'JOB_CLOSE'
exporting
jobname = p_jobnam
jobcount = w_jobcount
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.
case sy-subrc.
when 1.
w_code = 'cant_start_immediate'.
when 2.
w_code = 'invalid_startdate'.
when 3.
w_code = 'jobname_missing'.
when 4.
w_code = 'job_close_failed'.
when 5.
w_code = 'job_nosteps'.
when 6.
w_code = 'job_notex'.
when 7.
w_code = 'lock_failed'.
when 8.
w_code = 'others'.
endcase.
message i000 with 'JOB_CLOSE Error ' w_code ' Program aborted'.
skip 2.
format color col_negative.
write: / 'Program aborted.'.
write: / 'Function JOB_CLOSE Error ', w_code.
stop.
endif.
format color col_normal.
skip 2.
write: / ' JOB_CLOSE values after call:'.
write: /4 'jobname ', p_jobnam.
write: /4 'jobcount ', w_jobcount.
w_jobhead-status possible values
btc_running like tbtco-status value 'R',
btc_ready like tbtco-status value 'Y',
btc_scheduled like tbtco-status value 'P',
btc_released like tbtco-status value 'S',
btc_aborted like tbtco-status value 'A',
btc_finished like tbtco-status value 'F',
btc_put_active like tbtco-status value 'Z',
btc_unknown_state like tbtco-status value 'X'.
Wait for a while so job can finish
while ( not w_jobhead-status = 'F' ) and
( not w_jobhead-status = 'A' ).
call function 'BP_JOB_READ'
exporting
job_read_jobcount = w_jobcount
job_read_jobname = p_jobnam
job_read_opcode = '20'
importing
job_read_jobhead = w_jobhead
tables
job_read_steplist = i_int_job_read_steplist
exceptions
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 3
others = 4.
if w_jobhead-status = 'F'. " F = Finished
exit.
elseif w_jobhead-status = 'A'. " A = Aborted
message e935 with 'BP_JOB_READ function Aborted.'
'Status is '
w_jobhead-status
else.
wait up to 300 seconds.
wait up to p_wait seconds.
endif.
endwhile.
if w_jobhead-status <> 'F'.
write: / 'status', w_jobhead-status.
message e935 with
'BP_JOB_READ function did not complete successfully'
w_jobhead-status.
endif.
get time. " program finished
skip 2.
format color off.
endform. " 1000_SUBMIT_Program
Similar Messages
-
Submitting background jobs using an excecutable program
Hi all
Would anyone give an example program to submit jobs in background using job_open, job_submit, job_close F.M's,
please dont give complex coded program, easily understandable code with some useful comments will be apprecieated.
ThanksCreate a job using job_open
Create your job with JOB_OPEN. The module returns a unique job
number. Together with the jobname, this number identifies the
job. Other parameters are available, but are not required.
JOBNAME = 'Freely selectable name for the job(s) you create'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBNAME = JOBNAME
IMPORTING
JOBCOUNT = JOBNUMBER
EXCEPTIONS
CANT_CREATE_JOB = 01
INVALID_JOB_DATA = 02
JOBNAME_MISSING = 03
OTHERS = 99.
IF SY-SUBRC > 0.
<Error processing>
ENDIF.
Adding job step
Add a job step: ABAP program
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
AUTHCKNAM = SY-UNAME " Runtime authorizations
" user
JOBCOUNT = JOBNUMBER " Value from JOB_OPEN
JOBNAME = JOBNAME " Value from JOB_OPEN
REPORT = 'REPORT' " Report to be run
VARIANT = 'VARIANT' " Variant to use with
" report
PRIPARAMS = USER_PRINT_PARAMS " User printing options
ARCPARAMS = USER_ARC_PARAMS " User archiving options
" Both sets of options
" come from
" GET_PRINT_PARAMETERS
EXCEPTIONS
BAD_PRIPARAMS = 01
INVALID_JOBDATA = 02
JOBNAME_MISSING = 03
JOB_NOTEX = 04
JOB_SUBMIT_FAILED = 05
LOCK_FAILED = 06
PROGRAM_MISSING = 07
PROG_ABAP_AND_EXTPG_SET = 08
OTHERS = 99.
IF SY-SUBRC > 0.
<Error processing>
ENDIF.
**Closing job
Submit job for processing: immediate start
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBCOUNT = JOBNUMBER " Job identification: number
JOBNAME = JOBNAME " and name.
STRTIMMED = 'X' " Schedules the job for
" immediate start. The job
" is started immediately
" only if the user has the
" RELE authorization to
" release a job to run.
IMPORTING
JOB_WAS_RELEASED = JOB_RELEASED " If user has authorization
" to release jobs to run, job
" is automatically released
" when it is scheduled. This
" field is set to 'x' if the
" job has been released.
" Otherwise, the job is sche-
" duled but must be released
" by an administrator before
" it can be started.
EXCEPTIONS
CANT_START_IMMEDIATE No longer used. Replaced by IMPORTING
parameter JOB_WAS_RELEASED.
INVALID_STARTDATE = 01
JOBNAME_MISSING = 02
JOB_CLOSE_FAILED = 03
JOB_NOSTEPS = 04
JOB_NOTEX = 05
LOCK_FAILED = 06
OTHERS = 99.
IF SY-SUBRC > 0.
<Error processing>
ENDIF.
*Please note it's not my original code..I have done what you could do!! Just visited help.sap.com and typed Background jobs and got sample codes.. -
Schedule Background job using transaction CATM
Hi all,
Since we cannot schedule a background job using transaction CATM, I have created a program calling the CATM transaction through batch-input.
I have done a recording and entered the coding in a Z-program. For a vendor, I have recorded time in CAT2 for multiple purchase orders.
After entering the vendor number in CATM, all the purchase orders showed up. I have clicked 'select all' and posted.
When I run the program in the background, it posts only for one purchase order.
When I run the program in the foreground, using the Select All-button it only proceeds with the first line in my list of PO's.
How to read the whole stack and post the whole stack of purchase orders?
Please help me out with this.
Thanks
Regards
Srinivasan Desingh
408 368 3837Hi,
When I run the program in the background, it posts only for one purchase order.
When I run the program in the foreground, using the Select All-button it only proceeds with the first line in my list of PO's.
See..it's a Z-program so Its difficult to answer without checking the program. But I think, you should check your BDC again from Debugging, with the help of your abaper. You will find, why its is processing only one entry.
Regards
Shishir -
Schedule background job using system variant
Dear gurus,
We're planning to schedule background job using system variant, for example, current fiscal year and current posting period (transaction AFAB). Is it possible? So for example, for this month, "Posting Period" value will be 6, and then next month will be 7.
Can you tell me how to do this, if I want to set up the schedule only once?
Thanks for your help.
Best Regards,done using abap
-
How to schedule the background job using current selection screen field val
Hello Friends,
How to schedule the background job using current selection screen field values.
after completion of the job the spool should be sent as a mail to SAP Inbox.
Is there any way to create the variant dynamically by reading the current selection screen values.
Thanks,
RaviHi,
To get the variant details you can use teh following FM.
'RS_VARIANT_CONTENTS'.
Regards,
Ankur Parab -
Scheduling a background job using Job_Submit and Job_Close FM
Hi Guys,
I am calling a report in background using Job_Submit and Job_Close FM's.
I am not providing start time and date in the Job_close FM, in this case, when the job will be scheduled to start.
Even after an hour, job status is still scheduled.
I am not exporting variant, since I am using memory ID.
Thanks
Edited by: sapgeek007 on May 11, 2009 4:11 AMIn Job_close fm use the parameter 'STRTIMMED'
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = LV_NUMBER
jobname = LV_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
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.
That would start the background job immediately.
Regards,
Deepak -
Problem with background job using SUBMIT under different user
Hi All,
I am submitting a background job under different user name. I am submitting this job by using JOB_OPEN , SUBMIT report and JOB_CLOSE. But submit statement is returning sy-subrc 8, becuase of this the job_close is failed. Can you please help me to solve this problem.
Thanks in advance.
TjguptaHi,
The user is having all authorizations. is there any difference with user types?
This user is having user type " as communication data".
Thanks,
Tjgupta -
How to Execute RMDATIND inside another Background Job using a variant?
Hi,
It is only possible to start RMDATIND (direct input) in background from transaction BMV0 u2013 it is impossible just to place the program in another job in SM37 or SM36.
In a related thead I saw : u201DSolved my self by using BI_START_JOB. If I use this function module along with RS_CREATE_VARIANT and RS_VARIANT_DELETE. u201C
Following is the link to that thread
Re: Problem in using JOB_OPEN, JOB_SUBMIT & JOB_CLOSE
RS_CREATE_VARIANT (Creating a variant (not using a selection screen))
RS_VARIANT_DELETE(Variant to be deleted)
BI_START_JOB
Can some one provide me with all the parameters required to execute the above Function Modules?Hi,
Refer below thread:
Process Control in Confirmation Parameters
All the relevant details are explained in detail..
Best Regards,
Siva -
Simultaneous background jobs using the same BAPI issue
I scheduled 2 simultaneous background jobs on a custom program using the same BAPI (closing PM orders).
Run 1 to CLSD orders created on year 2001
Run 2 to CLSD orders created on year 2000
What happened was while run 1 was still active, run 2 encountered a dump and was cancelled.
Upon checking in ST22, dump was generated in CO_ZV_CONSISTENCY_CHECK.
Also, Run 2's dump happened when it encountered a data inconsistency for an order number being processed for Run 1.
Since the BAPI is being accessed at the same time by the two jobs, Is it possible that the commit work on run 1 could affect the processing for the Run 2, hence the data inconsistency?
Is this a buffer issue?
Additionally, no dump is encountered when Run 1 or Run 2 is run by itself.
I also encountered this issue before for creating Project and WBS using BAPI, but the solution we came up with was not to do parallel runs to avoid the error as this was a one time upload only.If the second job is dependent on the 1st job, then use following logic which will let you know the status of 1st job. Once 1st job is completed, call JOB_OPEN of 2nd job.
ENDLESS loop till 1st job is completed
DO.
CALL FUNCTION 'BP_JOB_READ'
EXPORTING
job_read_jobcount = w_jobcount
job_read_jobname = w_jobname
job_read_opcode = '20'
IMPORTING
job_read_jobhead = wa_jobhead
TABLES
job_read_steplist = i_jobsteplist
EXCEPTIONS
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 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.
To Display the status text as per the status type
CASE wa_jobhead-status.
WHEN 'S'. WRITE: / text-006. "'Scheduled'.
WHEN 'R'. WRITE: / text-007. "'Released'.
WHEN 'F'. WRITE: / text-008. "'Completed'.
WHEN 'A'. WRITE: / text-009. "'Cancelled'.
WHEN OTHERS.
ENDCASE.
IF wa_jobhead-status = 'F'.
exit.
ENDIF.
ENDDO.
PERFORM OPEN_2nd_JOb. -
How to schedule a background job using the Event concept..?
Hi Folks,
I have a requirement that, I need a schedule a background job.
Once after the previous job successful only, new job should get triggered. How to go ahead with this..?
For Eg, I am scheduling a job called ZTEST periodically for 1 minute. If the job is not get completing with in 1 minute, I dont want to start my new job. Only after the success of my old job, I want my new job to run.
Waiting for ur replies.
Regards,
Savi.Hi,
You can use events that have already been defined, or you can create new events for scheduling background jobs.
If you wish to use new events, do the following to implement the event scheduling:
Define and transport the event as a user event with transaction SM62.
You must define only event IDs; event arguments are not defined in the R/3 System. Instead, you specify event arguments when you schedule a job to wait for an event and when you trigger the event.
If you define a new event, you must also transport it to your production systems. The event transaction does not have a connection to the transport system. Instead, you must create a transport request for the event yourself.
Do this to transport an event:
Create a transport request.
Start the editor in the transport request and enter the following:
R3TR TABU <table name> where table name is BTCSEV for a system event ID, BTCUEV for a user event ID.
Press F2 with the cursor on the table name to call up the screen for specifying the table entries to transport. In this screen, enter the event IDs that you have created.
Save and release the transport request. Ensure that it is imported into your production system(s).
To trigger an event, add:
the function module BP_EVENT_RAISE to your ABAP program, or
the program SAPEVT to your external script, batch file, or program.
When your programs execute these keywords, an event will be triggered in the R/3 background processing system. The event-based scheduler is started immediately. It in turn starts all jobs that were waiting upon the event, subject to normal background processing restrictions, such as the requirement that the job has been released to start.
Schedule the jobs that are to run when your events are triggered.
You can schedule jobs for one-time start or to be started whenever an event is triggered.
Regards,
Raj. -
Any way to find out which program has created a job using 'JOB_OPEN'?
Hi,
I have some jobs created by some program. The job is incomplete, i.e., the programs which created the job just used 'JOB_OPEN' and it doesn't have any steps.
Is there any way to find out which program created that incomplete job?
Thanks in advance.
Regards,
Arun MohanNot sure but try this FM
BP_JOB_SELECT -Returns a table with job(s) details .
кu03B1ятu03B9к
Edited by: kartik tarla on Dec 30, 2008 6:50 PM -
Error While creating a Job using JOB_OPEN
Hello,
I am trying to create a job in the output type of a standard transaction.
But the job creation is failing. While debugging the transaction in update mode, I found out that the JOB_OPEN is coming out in the 'COMMIT WORK'.
Is there any other way to create a job so that the program executes properly.
Thanis/Regards,
Abhijit Anandgaonkar.Hi,
create a RFC function module....and inside the function module...create the batch job..
in the output type processing program...call the RFC function module in background task..
Thanks
Naren -
How to get data from the called program using SUBMIT in a background job?
Hi Experts,
I've a program which creates a background job using JOB_OPEN and JOB_CLOSE function modules.
Between the above function modules I need to call a program using SUBMIT VIA JOB statement.
My problem is, How do I fetch some data in an internal table in the called program to the calling program after the SUBMIT statement?
I tried to EXPORT and IMPORT the data, but they are giving a failed sy-subrc when using this background job.
Kindly let me know your inputs and valuable suggestions.Kumar,
When we execute a program as a background job then the output will be sent to Spool which needs to be fetched again.I guess we need to use Submit via spool as mentioned by Rajat.
Check these threads to get some idea
submit report to spool & import spool id
Re: Generate Spool for a report
K.Kiran. -
How can i get Background Jobs list which is made me?
I created background job using JOB_OPEN and SUBMIT and JOB_CLOSE.
I need to Background Job list which is made me..
Do u know any function or logic?
plz~[BP_JOBVARIANT_OVERVIEW|http://help.sap.com/saphelp_45b/helpdata/en/fa/096ccb543b11d1898e0000e8322d00/frameset.htm]
BP_JOBLOG_READ -
Spool list is not getting created for background job
I am creating background job using JOB_OPEN and then submitting my z-report using submit statement and then closing job using JOB_CLOSE. for this job is getting creating in sm37 and also gets finished but it does not create spool list showing output.
Any idea how to do this?
Thanks in advance.DATA: lv_jobname TYPE tbtcjob-jobname,
lv_jobcount TYPE tbtcjob-jobcount,
lv_variant TYPE variant,
wa_var_desc TYPE varid,
wa_var_text TYPE varit,
it_var_text TYPE TABLE OF varit,
it_var_contents TYPE TABLE OF rsparams.
REFRESH: it_var_contents, it_var_text.
CLEAR: wa_var_desc, wa_var_text.
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = sy-cprog
TABLES
selection_table = it_var_contents
EXCEPTIONS
not_found = 1
no_report = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CONCATENATE sy-datum sy-timlo INTO lv_variant.
wa_var_desc-mandt = sy-mandt.
wa_var_desc-report = sy-cprog.
wa_var_desc-variant = lv_variant.
wa_var_desc-transport = 'F'.
wa_var_desc-environmnt = 'B'.
wa_var_desc-version = '1'.
wa_var_desc-protected = 'X'.
wa_var_text-mandt = sy-mandt.
wa_var_text-langu = sy-langu.
wa_var_text-report = sy-cprog.
wa_var_text-variant = lv_variant.
lv_jobname = lv_variant.
CONCATENATE 'Batch Job Variant -'(006)
sy-uname INTO wa_var_text-vtext.
APPEND wa_var_text TO it_var_text.
Create the varaint for the back ground job.
CALL FUNCTION 'RS_CREATE_VARIANT'
EXPORTING
curr_report = sy-cprog
curr_variant = lv_variant
vari_desc = wa_var_desc
TABLES
vari_contents = it_var_contents
vari_text = it_var_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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Open the job.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
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.
submitt the job in background mode.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
authcknam = sy-uname
jobcount = lv_jobcount
jobname = lv_jobname
report = sy-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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
close the job.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
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
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 this will be helpful..
Maybe you are looking for
-
VBA or Non-VBA Solution to Filter records based on Master Selection.
Hi Folks, I have a rather complex requirement(for me). I have a Master sheet named "Master". In this there are names of employees. Now there are several other sheets named with Month & Year <January2014,Februrary2014...etc>. In these sheets, lies the
-
10g Report not running from Forms if called thru paramform on other domain
Hi... I'm using Dev10g Rel.2....If I call a report with paramform=no and pass it a value from forms then report runs well. but if I call report thru parameter form and pass value from parameter form the report doesn't run with error: The webpage cann
-
ORA-00932 on 11g + sdo_anyinteract + GROUP BY
select pco.pointclass_id, count(pco.rid) anzahl from pointcloud_output pco ,pointcloud_blk_25833 blk where 1=1 and blk.blk_id = pco.ptn_id and blk.obj_id = (SELECT pc.pc.pc_id FROM pointcloud_25833 pc WHERE prin_id = 1) and MDSYS.SDO_RELATE blk.blk_e
-
How to write this query to filter combination of few values
Hi, I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child. columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines. HEXA is a vaccine_id which is composite vaccine of
-
Upgrading JDeveloper11.1.1.2 to JDeveloper 11.1.1.5
Hi , I got an assignment to run our existing application which is developed in Jdeveloper 11.1.1.2.0 on JDeveloper 11.1.1.5 . I installed JDeveloper 11.1.1.5 and run my application . when I am going to login in the application . it gives me following