Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

hi all--- excel file via email

Former Member
0 Kudos

hi all

my requirement is to generate a report and send that report in excel sheet an attachment via email and this whole thing has to run in the background (schedule job).

could any one give me small 1 record coding that displays and uses FM for picking up excel sheet and passing excel sheet name in the email FM, everything should happen automatically once the report is executed since it is scheduled job.

thaning u in advance.

rocky

4 REPLIES 4

former_member386202
Active Contributor
0 Kudos

Hi,

Use FM

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_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.

Regards,

Prashant

Former Member
0 Kudos

just look into below code.

&----


*& Form excelrep_criticaljobs

&----


  • Description : To send the critical Autosys job status via Excel

  • Report

----


  • Parameters : None.

----


FORM excelrep_criticaljobs .

DATA :l_syuzeit TYPE sy-uzeit,

l_time(5) TYPE c,

l_ampm(2) TYPE c,

l_subject(255) TYPE c.

CLEAR t_xls.

REFRESH t_xls.

l_syuzeit = sy-uzeit.

IF t_final_data1[] IS NOT INITIAL.

PERFORM fill_header.

LOOP AT t_final_data1 WHERE status NE space.

t_xls-jobname = t_final_data1-jobname.

WRITE t_final_data1-act_start_date TO t_xls-act_start_date.

WRITE t_final_data1-est_start_time TO t_xls-est_start_time.

WRITE t_final_data1-act_start_time TO t_xls-act_start_time.

WRITE t_final_data1-est_end_time TO t_xls-est_end_time.

WRITE t_final_data1-act_end_time TO t_xls-act_end_time.

t_xls-est_duration = t_final_data1-est_duration.

t_xls-act_duration = t_final_data1-duration.

t_xls-status = t_final_data1-comment.

t_xls-process = t_final_data1-desc.

t_xls-fill10 = c_0d.

t_xls-fill1 = c_09.

t_xls-fill2 = c_09.

t_xls-fill3 = c_09.

t_xls-fill4 = c_09.

t_xls-fill5 = c_09.

t_xls-fill6 = c_09.

t_xls-fill7 = c_09.

t_xls-fill8 = c_09.

t_xls-fill9 = c_09.

APPEND t_xls.

CLEAR t_xls.

ENDLOOP.

l_ampm = c_am.

IF l_syuzeit GT c_125959.

l_syuzeit = l_syuzeit - c_120000.

l_ampm = c_pm.

ELSEIF l_syuzeit GT c_120000.

l_ampm = c_pm.

ELSEIF l_syuzeit LT c_010000.

l_syuzeit = l_syuzeit + c_120000.

l_ampm = c_am.

ENDIF.

WRITE l_syuzeit TO l_time USING EDIT MASK c_edmask.

CONCATENATE text-070 l_time l_ampm INTO l_subject

SEPARATED BY space.

CLEAR w_doc_chng.

w_doc_chng-obj_name = l_subject.

w_doc_chng-obj_descr = l_subject.

CLEAR t_objtxt.

REFRESH t_objtxt.

t_objtxt = text-068.

APPEND t_objtxt.

CLEAR t_objtxt.

t_objtxt = space.

APPEND t_objtxt.

CLEAR t_objtxt.

t_objtxt = text-069.

APPEND t_objtxt.

CLEAR t_objtxt.

t_objtxt = space.

APPEND t_objtxt.

CLEAR t_objtxt.

MOVE w_sysinfo TO t_objtxt.

APPEND t_objtxt.

CLEAR t_objtxt.

t_objtxt = space.

APPEND t_objtxt.

CLEAR t_objtxt.

CLEAR w_tab_lines.

DESCRIBE TABLE t_objtxt LINES w_tab_lines.

w_doc_chng-doc_size = w_tab_lines * c_255.

CLEAR t_objpack.

REFRESH t_objpack.

t_objpack-body_start = c_1.

t_objpack-body_num = w_tab_lines * c_255.

t_objpack-doc_type = c_txt.

APPEND t_objpack.

CLEAR t_objpack.

CLEAR t_objbin.

REFRESH t_objbin.

LOOP AT t_xls.

t_objbin = t_xls.

APPEND t_objbin.

CLEAR t_objbin.

ENDLOOP.

CLEAR w_tab_lines.

DESCRIBE TABLE t_objbin LINES w_tab_lines.

CLEAR l_subject.

CONCATENATE text-083 sy-datum l_time l_ampm INTO l_subject

SEPARATED BY c_uscore.

CLEAR t_objhead.

REFRESH t_objhead.

t_objhead = l_subject.

APPEND t_objhead.

CLEAR t_objhead.

t_objpack-transf_bin = c_x.

t_objpack-head_start = c_1.

t_objpack-head_num = c_1.

t_objpack-body_start = c_1.

t_objpack-body_num = w_tab_lines.

t_objpack-doc_type = c_xls.

t_objpack-obj_name = text-070.

t_objpack-obj_descr = text-070.

t_objpack-doc_size = w_tab_lines * c_255.

t_objpack-mess_type = space.

APPEND t_objpack.

CLEAR t_objpack.

CLEAR t_reclist.

REFRESH t_reclist.

IF s_email[] IS NOT INITIAL.

LOOP AT s_email.

t_reclist-receiver = s_email-low.

t_reclist-rec_type = c_u.

APPEND t_reclist.

CLEAR t_reclist.

ENDLOOP.

ENDIF.

PERFORM mail_report.

ELSE.

MESSAGE e015 WITH text-072.

ENDIF.

CLEAR : w_doc_chng,

t_objpack,

t_objhead,

t_objbin,

t_objtxt.

REFRESH : t_objpack,

t_objhead,

t_objbin,

t_objtxt,

t_reclist.

ENDFORM. " excelrep_criticaljobs

FORM fill_header .

MOVE w_sysinfo TO t_xls-jobname.

t_xls-fill10 = c_0d.

t_xls-fill1 = c_09.

t_xls-fill2 = c_09.

t_xls-fill3 = c_09.

t_xls-fill4 = c_09.

t_xls-fill5 = c_09.

t_xls-fill6 = c_09.

t_xls-fill7 = c_09.

t_xls-fill8 = c_09.

t_xls-fill9 = c_09.

APPEND t_xls.

CLEAR t_xls.

MOVE text-012 TO t_xls-jobname.

MOVE text-020 TO t_xls-act_start_date.

MOVE text-058 TO t_xls-est_start_time.

MOVE text-059 TO t_xls-act_start_time.

MOVE text-060 TO t_xls-est_end_time.

MOVE text-061 TO t_xls-act_end_time.

MOVE text-062 TO t_xls-est_duration.

MOVE text-063 TO t_xls-act_duration.

MOVE text-064 TO t_xls-status.

MOVE text-065 TO t_xls-process.

t_xls-fill10 = c_0d.

t_xls-fill1 = c_09.

t_xls-fill2 = c_09.

t_xls-fill3 = c_09.

t_xls-fill4 = c_09.

t_xls-fill5 = c_09.

t_xls-fill6 = c_09.

t_xls-fill7 = c_09.

t_xls-fill8 = c_09.

t_xls-fill9 = c_09.

APPEND t_xls.

CLEAR t_xls.

ENDFORM. " fill_header

FORM mail_report .

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_chng

commit_work = c_x

TABLES

packing_list = t_objpack

object_header = t_objhead

contents_bin = t_objbin

contents_txt = t_objtxt

receivers = t_reclist

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.

IF sy-subrc NE 0.

CASE sy-subrc.

WHEN 1.

MESSAGE i015 WITH text-071.

WHEN 2.

MESSAGE i015 WITH text-072.

WHEN 4.

MESSAGE i015 WITH text-073.

WHEN OTHERS.

MESSAGE i015 WITH text-074.

ENDCASE.

ELSE.

MESSAGE s015 WITH text-081.

ENDIF.

ENDFORM. " mail_report

Former Member
0 Kudos

t_objhead TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

t_objbin TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

t_objpack TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

t_objtxt TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

t_reclist TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE.

Former Member
0 Kudos

check the below links,

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

https://forums.sdn.sap.com/click.jspa?searchID=5494658&messageID=2287077

https://forums.sdn.sap.com/click.jspa?searchID=5494658&messageID=1505085

Check Thomas Jung's excellent blog on this:

/people/thomas.jung3/blog/2004/09/09/receiving-e-mail-and-processing-it-with-abap--version-610-and-higher

reward if useful.