Mail via Background job
Dear All,
We have a background job, which will execute a z program. The out put of Z program will be sent as a mail to the recipient listed in "Spool list recipient" (SM36).
We did unicode conversion and upgrade to ecc 6.0.
Even now background job send the out put to mail, but when we open the attached html file in the mail which contains the out put, it displaying with junk characters.
Out put looks like " æ¼â¾â¼¼ã¹¢â¼¼æ½¦ç®ã° "
Your help will be highly appriciated.
Thanks and regards
Joseph
hi check this...
Save Report Output to a PDF File
This report takes another report as input, and captures the output of that report. The output is then converted to PDF and saved to a local file. This shows how to use some of the PDF function modules, as well as an easy way to create PDF files.
One thing I am not thrilled about is how the spool number is retrieved. If anyone has any better method, please let me know! Until I actually have a production use for a program like this, I will not try to find a better way.
Source Code Listing
report zabap_2_pdf.
*-- Enhancements: only allow to be run with variant. Then called
*-- program will be transparent to users
*-- TABLES
tables:
tsp01.
*-- STRUCTURES
data:
mstr_print_parms like pri_params,
mc_valid(1) type c,
mi_bytecount type i,
mi_length type i,
mi_rqident like tsp01-rqident.
*-- INTERNAL TABLES
data:
mtab_pdf like tline occurs 0 with header line,
mc_filename like rlgrap-filename.
*-- SELECTION SCREEN
parameters:
p_repid like sy-repid, " Report to execute
p_linsz like sy-linsz default 132, " Line size
p_paart like sy-paart default 'X_65_132'. " Paper Format
start-of-selection.
concatenate 'c:\'
p_repid
'.pdf'
into mc_filename.
*-- Setup the Print Parmaters
call function 'GET_PRINT_PARAMETERS'
exporting
authority= space
copies = '1'
cover_page = space
data_set = space
department = space
destination = space
expiration = '1'
immediately = space
in_archive_parameters = space
in_parameters = space
layout = space
mode = space
new_list_id = 'X'
no_dialog= 'X'
user = sy-uname
importing
out_parameters = mstr_print_parms
valid = mc_valid
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
*-- Make sure that a printer destination has been set up
*-- If this is not done the PDF function module ABENDS
if mstr_print_parms-pdest = space.
mstr_print_parms-pdest = 'LOCL'.
endif.
*-- Explicitly set line width, and output format so that
*-- the PDF conversion comes out OK
mstr_print_parms-linsz = p_linsz.
mstr_print_parms-paart = p_paart.
submit (p_repid) to sap-spool without spool dynpro
spool parameters mstr_print_parms
via selection-screen
and return.
*-- Find out what the spool number is that was just created
perform get_spool_number using sy-repid
sy-uname
changing mi_rqident.
*-- Convert Spool to PDF
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid= mi_rqident
no_dialog = space
dst_device = mstr_print_parms-pdest
importing
pdf_bytecount = mi_bytecount
tables
pdf = mtab_pdf
exceptions
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others = 12.
call function 'DOWNLOAD'
exporting
bin_filesize = mi_bytecount
filename = mc_filename
filetype = 'BIN'
importing
act_filename = mc_filename
tables
data_tab = mtab_pdf.
FORM get_spool_number *
Get the most recent spool created by user/report *
--> F_REPID *
--> F_UNAME *
--> F_RQIDENT *
form get_spool_number using f_repid
f_uname
changing f_rqident.
data:
lc_rq2name like tsp01-rq2name.
concatenate f_repid+0(8)
f_uname+0(3)
into lc_rq2name separated by '_'.
select * from tsp01 where rq2name = lc_rq2name
order by rqcretime descending.
f_rqident = tsp01-rqident.
exit.
endselect.
if sy-subrc ne 0.
clear f_rqident.
endif.
endform." get_spool_number
regards,
venkat .
Similar Messages
-
Reg: File Extraction from SAP Queries via background job
Hi ,
Is it possible to Extract a file to the presentation Server by running the ABAP Query's through SQ01 as a back ground job to generate a file automatically without running it manually.
I have tried recording the query's thru SQ01 with the File store Option to download it to Excel on the Presentation server.I have used CAll Transaction for SQ01 in the Zprg and submitted that Query to be able to download that Query in the mentioned path .The Zprg was executed via Background job.The file is extracted to the presentation server when the Zprg was executed via Foreground,but its not getting Downloaded to Excel Via Back ground job.
Please provide me the solution.
Thanks in advance,
PremHi
u cannot get file in presentation server.. in background..
if you are scheduling any background jobs it should be out of any gui interface.. like gui_dowload , gui_upload// ur need to replace then with cl_gui_fronend_services Class
or u have a option of writing file to application server in background using open dataset syntax. -
Send Attachment via background job
Hi,
Is there any function module/program in SAP where we can send attachment to external parties via scheduled background job?
Thank you.Dear YEO WEI KOK,
Please check the following link:
http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm
Hope this helps you.
Do award points if you found them useful.
Regards,
Rakesh -
Hi Experts,
I have faced one problem in Mail Triggering. to the User.
Our Requirement is,
Whenever we execute one report ( ALV output) in Background , The Output should go the user thro mail ( automatic Mail trigger when the background Job is finished)
if anybody knows, plz guide me to do it.
With Regards,
Mahesh.Hi Dude,
Execute This Program as it is.UR requirement will be full filled .
Here the important Thing is the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
tables
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
Hope this Code helps U.
*& Report ZSENDMAIL
report zsendmail.
parameters: psubject(40) type c default 'Testing'.
PUSH BUTTON
data: it_packing_list like sopcklsti1 occurs 0 with header line,
it_contents like solisti1 occurs 0 with header line,
it_receivers like somlreci1 occurs 0 with header line,
it_attachment like solisti1 occurs 0 with header line,
gd_cnt type i,
gd_sent_all(1) type c,
gd_doc_data like sodocchgi1,
gd_error type sy-subrc.
data: it_message type standard table of solisti1 initial size 0
with header line.
*START-OF-SELECTION.
start-of-selection.
perform populate_message_table.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
perform send_email_message.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.
*& Form POPULATE_MESSAGE_TABLE
adds text to email text table
form populate_message_table.
data : itab type table of sflight with header line.
data : lv_itab(255) type c.
select carrid
connid from sflight into corresponding fields of table itab
where carrid = 'LH' and connid = '0400'.
loop at itab.
write : / itab-carrid , itab-connid.
concatenate itab-carrid itab-connid into lv_itab separated by space.
append lv_itab to it_message.
endloop.
endform. " POPULATE_MESSAGE_TABLE
**& Form SEND_EMAIL_MESSAGE
*send email message
form send_email_message.
*fill the document data.
gd_doc_data-doc_size = 1.
data: tab_lines like sy-tabix.
describe table it_message lines tab_lines.
read table it_message index tab_lines.
gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + strlen( it_message ).
**POPULATE the SUBJECT/GENERIC message ATTRIBUTES
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
**describe the body of the message
**information about structure of data tables
clear it_packing_list.
refresh it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
describe table it_message lines it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
append it_packing_list.
**add the recipients email address
clear it_receivers.
refresh it_receivers.
it_receivers-receiver = 'KRK'. "p_email.
it_receivers-rec_type = 'B'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
it_receivers-receiver = 'OBT'. "p_email.
it_receivers-rec_type = 'B'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
**CALL the fm TO post the MESSAGE to sapmail
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = gd_doc_data
put_in_outbox = 'X'
importing
sent_to_all = gd_sent_all
tables
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
**store function module return code
gd_error = sy-subrc.
**GET it_receivers return code
loop at it_receivers.
endloop.
endform. " SEND_EMAIL_MESSAGE
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
**instructs mail send program for sapconnect to send email.
form initiate_mail_execute_program.
wait up to 2 seconds.
if gd_error eq 0.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
endif.
endform. " INITIATE_MAIL_EXECUTE_PROGRAM -
Problem related to Outbound Delivery creation via Background Job
Hi ,
We are using the program RVV50R10C for creating OBD incase of STO .
Z variant is created to take care of selection parameters which inlcudes Shipping Point , Delivery creation date , Calc Rule, Delivery priority and shipping conditions.
The job is scheduled to run for every 10 minutes .
As planned the job is running for every 10 minutes but the OBD are created after 1 hour .
What are possible causes of this error.?
Please note that there exists enough stock.
Regards
Ramesh ChI think you will have the same problem when doing it manually with VL10B.
The creation is based on entries in an index. there is a userexit where you can influence how and when an entry goes into the index. E.g. you can speed up the overall performance if you do not update the index all the time, instead you are doing this with a background job from time to time.
Check if this is the case in your system.
this note may give you some hints:
Note 356061 - Incorrect index compilation caused by own checks -
Hi All,
We need to schedule a Job in background in every 30 min or 1 hr, which will monitor all the other Jobs running in background.
If any job is running more than 30000 sec, it should trigger an email.
Please guide me how to achieve this( i'm ABAPer).
Regards
VEnk@see the following t.code may be it will use
SWWCLEAR_INSERT
Workflow: Background Job 'SWWCLEAR';
Workflow: Hintergrundjob 'SWWCLEAR';
Workflow : job arr.-plan 'SWWCLEAR';
Workflow: achtergrondjob 'SWWCLEAR'
Workflow: Background Job 'SWWCLEAR'
SWWCOND_INSERT
Workflow: Background Job 'SWWCOND';
Workflow: Batchjob 'SWWCOND';
Workflow : job batch 'SWWCOND';
Workflow: achtergrondjob 'SWWCOND'
Workflow: Background Job 'SWWCOND'
SWWD
Maintain Work Item Error Monitoring;
Workitem-Fehlerüberwachung pflegen;
Gérer surveillance erreurs WI;
Workitem-foutbewaking verzorgen
Maintain Work Item Error Monitoring
Edited by: Krupaji on Feb 17, 2010 12:45 PM -
E-mail sending background job diappeared in the system
Hello Gurus,
We have one e-mail sending job in our production system. The frequency of the job is daily. Now we are not able to find the sheduled/Released/Active/Finished/Canceled status for this from the last 2 days.
Please help me to get back the job in the system.
Thanks in advance.
Thanks & Regards,
ASkHi,
Logon to the client from which the mails should be send, go to TA SCOT then choose menu: view -> jobs, you can also reschedule if required.
Or check via utilities when the mails were sent. -
Send mail from background job scheduling
Hi All,
I am facing one problem in which i have one standard transaction code COOIS for which there is no userexit.
we have to run this in background get the output in excelsheet and then mail the excel output to individual.
Please help me out.
Points wil be rewarded for sure.Hi
This is the sample code previously I achieved the same requirement.
FORM send_mail_2 USING msgid msgno msgv1.
mailuser oder Gruppe like sy-uname default 'Ruckerk'.
DATA: express_hold_time LIKE sovaltime.
DATA: text LIKE sotxtinfo.
DATA: receiver LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
MESSAGE ZF100 (FTP an UDB fehlgeschlagen)
text-msgid = msgid.
text-msgno = msgno.
text-msgv1 = msgv1.
text-msgv2 = ' '.
text-msgv3 = ' '.
text-msgv4 = ' '.
express_hold_time
express_hold_time-days = 01.
express_hold_time-h_min_sec = 240000.
receiver
receiver-receiver = mreceivr.
Gruppe von Empfängern
receiver-rec_type = 'C'.
und Expressmeldung ausgeben
receiver-express = 'X'.
APPEND receiver.
CALL FUNCTION 'MESSAGE_SEND_AS_MAIL'
EXPORTING
msgid = text-msgid
msgno = text-msgno
msgv1 = text-msgv1
msgv2 = text-msgv2
msgv3 = text-msgv3
TABLES
receivers = receiver.
IF sy-subrc <> 0.
WRITE:/ 'hat nicht geklappt', 'SY-SUBRC =', sy-subrc.
ENDIF.
PERFORM print_error_report.
Fehlermeldung zum Abbrechen des Report's ausgeben.
MESSAGE e398 WITH 'Jobabbruch' msgv1.
ENDFORM. " SEND_MAIL_2
Regards,
kumar -
Submit background job for a report
Hai Friends,
I want to submit a report in background which should run on first monday of every month. otherthen SM36 and SM37. Because we cant give date and time like this.
If any coding required Pl give me the code.
regards,
vamsykrishna.This is the Basic code to Achieve that.
Call Function 'JOB_OPEN'
SUBMIT RSBDCBTC
via background Job <Job info>
With QIE = <QID Returned by BDC_OPEN_Group FM>
AND RETURN.
Call Function 'JOB_CLOSE'
2) Also go through this
DATA: lv_job_name LIKE tbtco-jobname,
lv_job_nr LIKE tbtco-jobcount,
lv_job_released TYPE c,
lv_job_start_sofort TYPE c,
lv_print_parameters TYPE pri_params.
lv_job_name = 'Z_BGPROGRAM'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_job_name
IMPORTING
jobcount = lv_job_nr
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF syst-subrc = 0.
" submit job with all the selection screen params...
SUBMIT (lv_job_name)
WITH applfile = applfile " these are the parameters of the background program
WITH p_lines = p_lines
USER syst-uname " you must use this
VIA JOB lv_job_name NUMBER lv_job_nr AND RETURN.
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_job_nr
jobname = lv_job_name
strtimmed = 'X'
IMPORTING
job_was_released = lv_job_released
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 syst-subrc <> 0.
MESSAGE i162(00) WITH
'An error occured while closing the background job.'.
STOP.
ENDIF.
ENDIF.
ENDIF.
SKIP 1.
WRITE: / 'Background process', lv_job_name , 'called successfully' NO-GAP.
WRITE: / 'You can check the job in transaction SM37'. -
SUBMIT REPORT AS A BACKGROUND JOB
Hi all,
I am executing one report in foreground in that report i want to submit one report which should be executed in background only. how it is possible to execute 2nd report in <b>background mode</b> only.
Regards
deepakThis is the Basic code to Achieve that.
Call Function 'JOB_OPEN'
SUBMIT RSBDCBTC
via background Job <Job info>
With QIE = <QID Returned by BDC_OPEN_Group FM>
AND RETURN.
Call Function 'JOB_CLOSE'
2) Also go through this
DATA: lv_job_name LIKE tbtco-jobname,
lv_job_nr LIKE tbtco-jobcount,
lv_job_released TYPE c,
lv_job_start_sofort TYPE c,
lv_print_parameters TYPE pri_params.
lv_job_name = 'Z_BGPROGRAM'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_job_name
IMPORTING
jobcount = lv_job_nr
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF syst-subrc = 0.
" submit job with all the selection screen params...
SUBMIT (lv_job_name)
WITH applfile = applfile " these are the parameters of the background program
WITH p_lines = p_lines
USER syst-uname " you must use this
VIA JOB lv_job_name NUMBER lv_job_nr AND RETURN.
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_job_nr
jobname = lv_job_name
strtimmed = 'X'
IMPORTING
job_was_released = lv_job_released
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 syst-subrc <> 0.
MESSAGE i162(00) WITH
'An error occured while closing the background job.'.
STOP.
ENDIF.
ENDIF.
ENDIF.
SKIP 1.
WRITE: / 'Background process', lv_job_name , 'called successfully' NO-GAP.
WRITE: / 'You can check the job in transaction SM37'.
Thanks -
How to trigger a mail once BG job finished.
Hi,
Could anyone please let me know how to trigger a mail once Background job finished. I let you give one scenario where exactly I require this concept. Say, I execute t.code MB52 with particular variants in background to find stuck qty(s) of material(s) in given site(s).Now I want that system will trigger a mail to concern team once job finished.
Thanks,
AKYou can try using workflow transaction SBWP.
you need to create a distibution list in the above transaction and add the requested mail ids to it.
then when you create a jon using transaction SM37 you have the option SPOOL LIST RECIPIENT where you can add the created distibution list
so when ever the job has run sucessfully then a mail is sent to all the mail id's in the list.
hope this helps.
cheers
sundeep -
Convert Spool to PDF and mail for the jobs not run in background.
Dear All,
I need to convert the spool job into pdf and mail as attachment for job not run in background.
I am printing the bills using the program SD70AV3A to print the bills in a batch using the SUBMIT.
But i am not using the spool options since its going to into waiting state in spool...and i need to change the printer properties to G
to get the printer to print the reports as these jobs run in backgroud....but this solution is not acceptable solution.
SUBMIT SD70AV3A
WITH RG_KSCHL-LOW = 'ZRR'
WITH RG_NACHA-LOW = '1'
WITH PM_VERMO = '2'
WITH PM_NSORT = '1'
WITH RG_VBELN IN range.
* TO SAP-SPOOL
* SPOOL PARAMETERS print_parameters
* WITHOUT SPOOL DYNPRO
* VIA JOB name NUMBER number
* AND RETURN.
so how do i get the spool number from the above after the job is submitted....and then convert into pdf and mail
please suggest some solution. I have searched on net but most the solutions are say to run the job as background job...
i have also looked into the program RSTXPDFT4 but it asks for the spool id ....how can i get spool id for the job that has been completed.
please suggest some solution.
Thanks
Bhargava.Hi,
Spool to PDF : FM 'CONVERT_ABAPSOOLJOB_2_PDF'
Table TSP01 to get spool number
You ,may need to convert OTF to PDF: FM CONVERT_OTF
and the to binary : FM 'SMCS_XSTRING_TO_BINARY'
To send mail use class: cl_document _bcs.
Regards,
Maria João Rocha -
Mail configuration and background job scheduling for ST22 Data
Experts,
I want to know how can i schedule a background job in SAP to extract data from ST22 and send a automated mail for the same?
Any help will be appreciated, Thanks!!!
Regards,
Vinit PagariaYou don't need to do that, simply configure CCMS (RZ20) to send you an alert via mail when a dump occurs.
Read,
http://help.sap.com/saphelp_nw04/helpdata/EN/90/4e313f8815d036e10000000a114084/frameset.htm
Regards
Juan -
Hi All
The spool generated by background job can be send via mail. I am using this to sent to internal mail ie SAP mail . But I don't see provision for sending to multiple user at the same time. Can it be done
With Regards
ArunHi Arun
Please refer the below link. I think it may help you in this regards.
[http://www.home4sap.com/tips/spool-email.shtml]
Regards
Makarand -
Automatic Mail not getting generated through background job
Hi Experts,
We have set up a job variant with spool recipients. We are getting the automatic mail if the job is getting finished successfully. But we are not getting the automatic mail if the job is in cancelled status. Earlier we used to get the mail even if the job is in cancelled status. We are not sure if there is any setting which would restrict the automatic mail based on the job status.
Appreciate your help in this regard.
Thanks and Regards,
Ranjani.Hi,
Just for a work around, try checking the SAP user inbox for the user who has scheduled the background job.
I don't there is any seperate configuration in Spool List Recipient for the canceled jobs. We need to confirm that the email ids provided in the Spool List recipient are correct and the background job creates a spool request even if it is canceled.
Also if possible try deleting the existing background job and create a new background job with the same parameters and valid email id's maintained in the Spool List recipient.
OR
Without deleting the existing background job, parallely create a new background job with the same parameters and valid email id's maintained in the Spool List recipient. If it works then delete the old background job.
Thanks
Harish
Maybe you are looking for
-
Is there a way to copy and apply changes to photos in iPhoto?
In previous versions of iPhoto, I was able to edit a photo (adjusting exposure, colors, etc.) and then copy and apply the same changes to other photos. I can't seem to figure out how to do this in iPhoto 11 (v 9.3). Is this capability still presen
-
Camera rotation limits not right
I have a camera rotating left/right/up/down, I am trying to limit the rotation to 150 degrees in any direction. I have this code working for the left/right: if gPanLeft then pCamera.rotate(0,1,0) pCamera.transform.rotation.z = max(-150, min(150,pCame
-
I would like to change my email address
Hi, I want to start using a different email address on my mail. How do I start to use this new email address?
-
Utility to check battery in OS 10.1.5 ??
Is there a utility similar to coconut battery that will run under OS 10.1.5? I'm pretty sure the battery in my G3 iBook is failing, but wanted to test it. Thanks. iBook G4 1.42GHz PPC, 14" Mac OS X (10.4.6) also iBook G3 600MHz/ MacOS 10.1.5
-
Broadband connection gone slow
I've been connected since March at between 2800 and more recently 3100 kbps but yesterday I had to reboot the router as it had tripped over itself and now I cannot get over 1600 kbps. Any faults reported in Daventry? DownStream Connection Speed 1568