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

SO_NEW_DOCUMENT_ATT_SEND_API1

Former Member
0 Likes
804

Hi,

I'm using SO_NEW_DOCUMENT_ATT_SEND_API1 FM to send email with attachments of type XLS.

The email is sent successfully but when try to open the attachment getting message as:

Not in recognisable format. When the document is opened the values ar enot properly displayed.

Pls help what could the problem:

Code is :

data Intabb like standard table of mara with header line.

select * from mara into table Intabb.

  • Creation of the document to be sent

doc_chng-obj_name = 'ANGEBOT'.

doc_chng-obj_DESCR = 'BG test description'.

objtxt = 'Please see attached document containing'.

append objtxt.

objtxt = 'Material Details.'.

append objtxt.

objtxt = ' Regards,'.

append objtxt.

objtxt = ' SAP.'.

append objtxt.

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.

  • Creation of the document attachment

  • Assume that the data in OBJBIN is in TXT format

LOOP AT Intabb.

CONCATENATE INTABB-matnr INTABB-mandt INTO OBJBIN.

Append objBin.

endloop.

Describe table objbin lines tab_lines.

*Objhead = 'Mat.xls'.

*Append Objhead.

  • Creation of the entry for the compressed attachment

clear objpack-transf_bin.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'XLS'.

objpack-obj_name = 'ANLAGE'.

objpack-obj_descr = 'OM_GGCS Cork Ireland Report_Date_Time'.

objpack-doc_size = tab_lines * 255.

append objpack.

reclist-receiver = '09022426'.

reclist-express = 'X'.

reclist-rec_type = 'B'.

append reclist.

  • Sending The Document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

Document_data = doc_chng

  • put_in_outbox = 'X'

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
682
5 REPLIES 5
Read only

anversha_s
Active Contributor
0 Likes
682

Hi prabha,

kindly chk ur code with this sample pgm.

it will help u.

<b><i>email with excel atach:</i></b>

report ZMAILTEST.

parameters: p_email type somlreci1-receiver

default 'you@yourcompany.com'.

data: begin of it001 occurs 0,

bukrs type t001-bukrs,

butxt type t001-butxt,

end of it001.

data: imessage type standard table of solisti1 with header line,

iattach type standard table of solisti1 with header line,

ipacking_list like sopcklsti1 occurs 0 with header line,

ireceivers like somlreci1 occurs 0 with header line,

iattachment like solisti1 occurs 0 with header line.

start-of-selection.

select bukrs butxt into table it001 from t001.

  • Populate table with detaisl to be entered into .xls file

perform build_xls_data .

  • Populate message body text

clear imessage. refresh imessage.

imessage = 'Please find attached excel file'.

append imessage.

  • Send file by email as .xls speadsheet

perform send_email_with_xls tables imessage

iattach

using p_email

'Example Excel Attachment'

'XLS'

'TestFileName'

'CompanyCodes'.

************************************************************************

  • Form BUILD_XLS_DATA

************************************************************************

form build_xls_data .

constants: con_cret type x value '0D', "OK for non Unicode

con_tab type x value '09'. "OK for non Unicode

*If you have Unicode check active in program attributes thnen you will

*need to declare constants as follows

*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.

concatenate 'BUKRS' 'BUTXT'

into iattach separated by con_tab.

concatenate con_cret iattach into iattach.

append iattach.

loop at it001.

concatenate it001-bukrs it001-butxt

into iattach separated by con_tab.

concatenate con_cret iattach into iattach.

append iattach.

endloop.

endform.

************************************************************************

  • Form SEND_EMAIL_WITH_XLS

************************************************************************

form send_email_with_xls tables pit_message

pit_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription.

data: xdocdata like sodocchgi1,

xcnt type i.

  • Fill the document data.

xdocdata-doc_size = 1.

  • Populate the subject/generic message attributes

xdocdata-obj_langu = sy-langu.

xdocdata-obj_name = 'SAPRPT'.

xdocdata-obj_descr = p_mtitle .

  • Fill the document data and get size of attachment

clear xdocdata.

read table iattach index xcnt.

xdocdata-doc_size =

( xcnt - 1 ) * 255 + strlen( iattach ).

xdocdata-obj_langu = sy-langu.

xdocdata-obj_name = 'SAPRPT'.

xdocdata-obj_descr = p_mtitle.

clear iattachment. refresh iattachment.

iattachment[] = pit_attach[].

  • Describe the body of the message

clear ipacking_list. refresh ipacking_list.

ipacking_list-transf_bin = space.

ipacking_list-head_start = 1.

ipacking_list-head_num = 0.

ipacking_list-body_start = 1.

describe table imessage lines ipacking_list-body_num.

ipacking_list-doc_type = 'RAW'.

append ipacking_list.

  • Create attachment notification

ipacking_list-transf_bin = 'X'.

ipacking_list-head_start = 1.

ipacking_list-head_num = 1.

ipacking_list-body_start = 1.

describe table iattachment lines ipacking_list-body_num.

ipacking_list-doc_type = p_format.

ipacking_list-obj_descr = p_attdescription.

ipacking_list-obj_name = p_filename.

ipacking_list-doc_size = ipacking_list-body_num * 255.

append ipacking_list.

  • Add the recipients email address

clear ireceivers. refresh ireceivers.

ireceivers-receiver = p_email.

ireceivers-rec_type = 'U'.

ireceivers-com_type = 'INT'.

ireceivers-notif_del = 'X'.

ireceivers-notif_ndel = 'X'.

append ireceivers.

call function 'SO_DOCUMENT_SEND_API1'

exporting

document_data = xdocdata

put_in_outbox = 'X'

commit_work = 'X'

tables

packing_list = ipacking_list

contents_bin = iattachment

contents_txt = imessage

receivers = ireceivers

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.

http://sap.ittoolbox.com/groups/technical-functional/sap-r3-dev/excel-attachment-for-sending-email-e...

rgds

anver

<i>if hlpful pls mark points</i>

Read only

0 Likes
682

Hi,

Thanks for reply.

Again i get athe same error for the codes which u have given.

The file is not in recongized format

Pls help

Ram

Read only

Former Member
0 Likes
683
Read only

Former Member
0 Likes
682

Hi Prabha,

i think the doc_size isn't correct.

I did it in this way:

<b>OBJ_PACK-DOC_SIZE = ( tab_lines - 1 ) * 255.</b>

Regards, Dieter

Read only

Former Member
0 Likes
682

Hi Prapha,

look at OSS-Note 190669.

And how many rows do you have in your itab.

For Test try this:

select * from mara into table Intabb up to 100 rows.

Regards, Dieter