cancel
Showing results for 
Search instead for 
Did you mean: 

how to send multiple attachment s with a mail??

Former Member
0 Kudos

Hi,

How to send multiple attachments with a mail??

Situation::

In my case i have 5 internal tables populated dynamically in the report.

I want to send them in .TXT format as attachment with 1 mail.

Can anybody tell me in 'SO_NEW_DOCUMENT_ATT_SEND_API1',

how we add multiple attachmants to table objin???

thanks,

deepak

View Entire Topic
messier31
Active Contributor
0 Kudos

Hi Deepak,

Please find the sample code for sending mail with multiple attachment.

----


  • Report ZPAN_02M *

----


REPORT zpan_02m .

*-MAIN DECLARATION----


DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

*-OTHER DECLARATIONS----


DATA : listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

DATA : tab_lines(3) TYPE n.

DATA : att_type LIKE soodk-objtp.

*OBJBIN = ' | '. APPEND OBJBIN.

*---For simple attachment -


DATA : BEGIN OF wi_data OCCURS 0,

c1(10),

c2(10),

END OF wi_data.

wi_data-c1 = 'Line 1'. wi_data-c2 = 'Line 1'. APPEND wi_data.

wi_data-c1 = 'Line 2'. wi_data-c2 = 'Line 2'. APPEND wi_data.

wi_data-c1 = 'Line 3'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 4'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 5'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 6'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 7'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 8'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 9'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 10'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 11'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 12'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 13'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 14'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 15'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 16'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 17'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 18'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 19'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 20'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 21'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 22'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 23'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 24'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 25'. wi_data-c2 = 'Line 3'. APPEND wi_data.

wi_data-c1 = 'Line 26'. wi_data-c2 = 'Line 3'. APPEND wi_data.

class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

con_cret type c value cl_abap_char_utilities=>CR_LF,

con_nwln type c value cl_abap_char_utilities=>NEWLINE.

LOOP AT wi_data.

CONCATENATE wi_data-c1 con_tab

wi_data-c2

INTO objbin.

condense objbin.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

ENDLOOP.

*---CREATE MESSAGE : DOCDATA -


  • Name

docdata-obj_name = 'TEST_ALI'.

  • Subject

docdata-obj_descr = 'Test including ALI/HTML Attachment'.

*---CREATE MESSAGE : BODY -


objtxt = 'Test Document.'.

APPEND objtxt.

objtxt = 'You will find an ALI/HTML attachment in this message.'.

APPEND objtxt.

objtxt = 'Have a nice day.'.

APPEND objtxt.

*-CREATE PACKING LIST-----TEXT--


objpack-head_start = 1.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

APPEND objpack.

*-CREATE PACKING LIST-----ATTACHMENT--


att_type = 'XLS'.

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( ( tab_lines / 2 ) - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines / 2.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT 1'.

objpack-obj_descr = 'Attached Document 1'.

APPEND objpack.

att_type = 'XLS'.

objpack-doc_size = ( ( tab_lines / 2 ) - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 14.

objpack-head_num = 14.

objpack-body_start = 14.

objpack-body_num = tab_lines / 2.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT 2'.

objpack-obj_descr = 'Attached Document 2'.

APPEND objpack.

*-CREATE RECEIVER LIST----


reclist-receiver = 'pankajs@hexaware.com'. reclist-rec_type = 'U'.

APPEND reclist.

reclist-receiver = sy-uname. reclist-rec_type = 'B'.

APPEND reclist.

*-SEND MESSAGE----


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • OBJECT_PARB =

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

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

Hope this is enough for you...

Enjoy SAP.

Pankaj Singh.