cancel
Showing results for 
Search instead for 
Did you mean: 

Sending attachments with email

former_member445996
Participant
0 Kudos

Hi All,

I am using function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send a tab delimeted text file with an email. Email goes fine but when I open the file the format is not tab delimited. Well the fields are delimited by tabs but new record does not start on a new line rather it starts on the same line and I think after 255 characters.

I am assuming that it is because I am using binary flag = 'X' but if I send this flag as blank then no data gets generated in the file.

Does anyone know what the problem could be. Can we send the file as anything other than binary.

Also, can we send more than one attachment in one email?

data: objpack like sopcklsti1 occurs 0 with header line,

objhead like solisti1 occurs 0 with header line,

objbin like solisti1 occurs 0 with header line,

objtxt like solisti1 occurs 0 with header line,

reclist like somlreci1 occurs 0 with header line,

doc_chng like sodocchgi1,

tab_lines like sy-tabix,

l_num(3).

records = 0.

describe table download_file lines records.

doc_chng-obj_name = 'SEND_EMAIL'.

doc_chng-obj_descr = 'GLPCA Reclass Data'.

if records > 0.

objtxt = 'Attached file contains GLPCA Reclass data.'.

append objtxt.

clear objtxt.

objtxt = 'Please double click the attachment to verify data.'.

append objtxt.

clear objtxt.

else.

objtxt = 'No data found.'.

append objtxt.

clear objtxt.

endif.

describe table objtxt lines tab_lines.

read table objtxt index tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).

  • Creation of the entry for the compressed document

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.

clear objpack.

  • Creation of the entry for the compressed attachment

if records > 0.

loop at download_file.

move download_file to objbin.

condense objbin.

append objbin.

clear objbin.

endloop.

describe table objbin lines tab_lines.

objhead = b_file.

append objhead.

clear objhead.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'txt'.

objpack-obj_name = 'SEND_EMAIL1'.

objpack-obj_descr = 'Download File'.

objpack-doc_size = tab_lines * 255.

append objpack.

clear objpack.

endif.

  • Completing the recipient list For sending mail to Internet Address

reclist-receiver = email.

reclist-rec_type = 'U'.

append reclist.

clear reclist.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = doc_chng

TABLES

PACKING_LIST = objpack

OBJECT_HEADER = objhead

CONTENTS_BIN = objbin

CONTENTS_TXT = objtxt

RECEIVERS = reclist

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

Thanks for your help.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

CONSTANTS : cr_mark TYPE x VALUE '0D'.

"carriage return character

Concatenate cr_mark to each row in the internal table before you append to objbin.

ferry_lianto
Active Contributor
0 Kudos

Hi Aurang,

Please have a look at this link for sample codes.

http://www.sap-img.com/abap/sending-email-with-attachment.htm

Hope this will help.

Regards,

Ferry Lianto