Application Development and Automation 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: 
Read only

Send spool format through email as excel attachment

manubhutani
Active Contributor
0 Likes
851

Hi

The program output is in tabular format (using some write_display function module).

It is having 5 columns, I want to send this o/p through email

as an excel attachment, please help

Regards

Manu

Hi

The program output is in tabular format (using some write_display function module).

It is having 5 columns, I want to send this o/p through email

as an excel attachment, please help

Regards

Manu

1 REPLY 1
Read only

Former Member
0 Likes
466

Hi Manu,

You can use the FM SO_DOCUMENT_SEND_API1. This FM basically used to send the email with attachments. Kindly explore the same and let me know if you still have some doubt. Have this code for your reference as well.

  • To send the excel file as an attachment to mail id's specified without saving

  • the excel file in a path in our local machine.

TYPES: BEGIN OF ty_rec,

bname TYPE xubname,

persnumber TYPE ad_persnum,

smtp_addr TYPE ad_smtpadr,

END OF ty_rec.

TYPES: BEGIN OF ty_out,

stud_id(15) TYPE C,

marks1(15) TYPE C,

marks2(15) TYPE C,

marks3(15) TYPE C,

END OF ty_out.

DATA: it_attach TYPE STANDARD TABLE OF solisti1,

wa_attach TYPE solisti1,

it_rec TYPE STANDARD TABLE OF ty_rec,

wa_rec TYPE ty_rec.

DATA: it_out TYPE STANDARD TABLE OF ty_out,

wa_out TYPE ty_out.

*SELECT /bic/stu_id /bic/z_marks1 /bic/z_marks2 /bic/z_marks3 FROM /bic/azod_stu00 INTO TABLE it_out.

      • Creating Item Detial Data.

wa_out-stud_id = '90'.

wa_out-marks1 = '90'.

wa_out-marks2 = '95'.

wa_out-marks3 = '99'.

append wa_out to it_out.

wa_out-stud_id = '91'.

wa_out-marks1 = '91'.

wa_out-marks2 = '96'.

wa_out-marks3 = '100'.

append wa_out to it_out.

PERFORM build_xls_data.

*PERFORM get_recepients.

PERFORM send_mail.

&----


*& Form build_xls_data

&----


  • text

----


FORM build_xls_data.

CONSTANTS:

con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

CONCATENATE 'Student ID' 'Subject Marks1' 'Subject Marks2' 'Subject Marks3'

INTO wa_attach SEPARATED BY con_tab.

CONCATENATE con_cret wa_attach

INTO wa_attach.

APPEND wa_attach TO it_attach.

CLEAR wa_attach.

LOOP AT it_out INTO wa_out.

DATA: lv_sub1(20),

lv_sub2(20),

lv_sub3(20).

lv_sub1 = wa_out-marks1.

lv_sub2 = wa_out-marks2.

lv_sub3 = wa_out-marks3.

CONCATENATE wa_out-stud_id lv_sub1 lv_sub2 lv_sub3

INTO wa_attach SEPARATED BY con_tab.

CONCATENATE con_cret wa_attach

INTO wa_attach.

APPEND wa_attach TO it_attach.

CLEAR: wa_attach,

wa_out.

ENDLOOP.

ENDFORM.

"build_xls_data

&----


*& Form send_mail

&----


  • text

----


FORM send_mail.

DATA: lv_document_data TYPE sodocchgi1.

  • Body of the mail

DATA: contents TYPE TABLE OF solisti1 WITH HEADER LINE.

  • Recepient list.

DATA: lv_receivers TYPE TABLE OF somlreci1,

wa_receivers TYPE somlreci1.

DATA: lv_packing_list TYPE TABLE OF sopcklsti1,

lv_p_item TYPE sopcklsti1,

lv_date LIKE sy-datum,

len TYPE int4,

doc_count TYPE i.

lv_document_data-obj_descr = 'Student Marks Report'.

lv_document_data-sensitivty = 'P' .

lv_document_data-doc_size = 1.

READ TABLE it_attach INTO wa_attach INDEX doc_count.

lv_document_data-doc_size = ( doc_count - 1 ) * 255 + STRLEN( wa_attach ).

  • Body of the mail.

*Below code represents the body of the mail. "text-001" contains the contents of the first line,

*"text-002" contains the contents of the second line and so on

*Creation of Text Elements:

  • Create the following Text elements and activate. We can also create text elements

  • by double clicking on the serial number assigned to the text in the program

  • (text-001, text002, text003, text004) which would take us to the Text elements screen.

MOVE text-001 TO contents.

APPEND contents.

CLEAR contents.

MOVE text-002 TO contents.

APPEND contents.

CLEAR contents.

MOVE text-003 TO contents.

APPEND contents.

CLEAR contents.

MOVE text-004 TO contents.

APPEND contents.

CLEAR contents.

  • If we need to send this mail in "TO" list, please refer to the below code.

  • Create list of Receivers.

wa_receivers-receiver = 'VISHALJ'.

wa_receivers-rec_type = 'B'.

wa_receivers-no_forward = 'X'.

APPEND wa_receivers TO lv_receivers.

DESCRIBE TABLE contents LINES len.

lv_p_item-body_start = 1.

lv_p_item-body_num = len.

lv_p_item-doc_type = 'RAW'.

APPEND lv_p_item TO lv_packing_list.

DESCRIBE TABLE it_attach LINES len.

lv_p_item-transf_bin = 'X'.

lv_p_item-head_num = 1.

lv_p_item-head_start = 1.

lv_p_item-body_start = 1.

lv_p_item-body_num = len.

lv_p_item-doc_type = 'XLS'.

lv_p_item-obj_descr = 'Student_Marks_Report.xls'.

lv_p_item-obj_name = 'Marks_Report'.

lv_p_item-doc_size = len * 255.

APPEND lv_p_item TO lv_packing_list.

*In the below code, "text-005" refers to the sender address.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = lv_document_data

put_in_outbox = 'X'

sender_address = 'VISHALJ' " Sender's ID <this is my ID>

sender_address_type = 'B'

commit_work = 'X'

TABLES

packing_list = lv_packing_list

contents_bin = it_attach

contents_txt = contents

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

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

MESSAGE 'mail sent successfully' TYPE 'I'.

ENDFORM. "send_mail