09-10-2008 10:00 PM
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.
09-10-2008 10:18 PM
Check the structure of parameter RECIPIENT_OBJ in FM JOB_CLOSE. I think here u can specify the recipient name to send a mail after completion of the job.
09-10-2008 10:18 PM
Check the structure of parameter RECIPIENT_OBJ in FM JOB_CLOSE. I think here u can specify the recipient name to send a mail after completion of the job.
09-11-2008 3:15 PM
Joyjit thanks for your reply.
i know there is RECIPIENT_OBJ , but i dont know how to use that. could you tell me if any SAP std program uses that obj.
Thanks!
09-11-2008 7:24 PM
solved by using
http://www.sap-basis-abap.com/sapac018.htm
and by SAP Report RSSOKIF1.
this solved my problem of sending an email to SAP inbox. Now my question is, how do I send an email to my office email-ID.
kindly tell me your solutions.
09-11-2008 7:32 PM
Hi,
Use the fm SO_NEW_DOCUMENT_ATT_SEND_API1.
Search in SCN ,There are so many examples are available.
Regards
Kiran
09-11-2008 7:56 PM
Kiran,
will this allow me to send an email after the background job is complete?
09-11-2008 8:11 PM
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
09-11-2008 8:50 PM
Bruce, thanks for your reply.
I could not find form 2000_send_email. in your pasted code.
09-11-2008 9:07 PM
09-12-2008 5:07 PM
Bruce,
again thanks for your reply.
I could send an email using my code itself with minor canges to the office email-ID, instead of the SAP Inbox.
But again i need to send body for an email (text). As of now i'm able to send Subjet and attachment.
09-12-2008 6:08 PM
Prema,
FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
is commonly used to send email. There are many examples in SDN and other web sites detailing how to use this FM. Do a search and you will find what you need.
Bruce
09-12-2008 7:20 PM
Thanks Bruce.
client said they are fine with an email to SAP Inbox. i think I'm good now.