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: 

Mail Send Functionality using SO_NEW_DOCUMENT_ATT_SEND_API1

pintoo_d
Participant
0 Kudos

hi,

i m using Fn Module "SO_NEW_DOCUMENT_ATT_SEND_API1" to send email with attachment.

I have written a program which will fetch data in excel format . this excel should be sent as attachment to specified receiver. however i m having difficulties adding attachment to function module.

I specified under parameter "contents_bin" but its giving some error message related wth structure.

I chkd SDN and wasnt able to find any resolution yet.

Any suggestion or idea which can be useful on this.

Thanks.

13 REPLIES 13

former_member156446
Active Contributor
0 Kudos

<<<< nice documentation

Former Member
0 Kudos

use as below:

DATA: li_pdfdata TYPE STANDARD TABLE OF tline,

li_mess_att TYPE STANDARD TABLE OF solisti1,

li_mtab_pdf TYPE STANDARD TABLE OF tline,

li_objpack TYPE STANDARD TABLE OF sopcklsti1,

li_objtxt TYPE STANDARD TABLE OF solisti1,

li_objbin TYPE STANDARD TABLE OF solisti1,

li_reclist TYPE STANDARD TABLE OF somlreci1,

li_objhead TYPE soli_tab.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_doc_chng

put_in_outbox = gc_x

TABLES

packing_list = li_objpack

object_header = li_objhead

contents_bin = li_objbin

contents_txt = li_objtxt

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

agnihotro_sinha2
Active Contributor
0 Kudos

Here is a sample code:

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = pdf_bytecount

TABLES

otf = otf_data

doctab_archive = lt_docs

lines = pdfout

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

TABLES

content_in = pdfout

content_out = pdfout2.

CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'Order output'.

  • Mail Subject

CONCATENATE 'Order :' vbdka-vbeln INTO maildata-obj_descr .

  • Mail Contents

mailtxt-line = 'Order output '.

APPEND mailtxt.

  • Set recipient - email address here!!!

SELECT SINGLE adrnr FROM kna1

INTO adrnr_sv

WHERE kunnr = vbdka-kunnr.

SELECT SINGLE *

FROM adrc

INTO adrc_sv

WHERE addrnumber = adrnr_sv.

SELECT SINGLE smtp_addr FROM adr6

INTO email

WHERE addrnumber = adrnr_sv

AND flgdefault = 'X'.

mailrec-receiver = email.

mailrec-rec_type = 'U'.

APPEND mailrec.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = maildata

  • put_in_outbox = ' '

TABLES

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

Former Member
0 Kudos

Convert your attachment data to binary using FM's such as SCMS_XSTRING_TO_BINARY

etc., and pass it to CONTENTS_HEX in the FM SO_NEW_DOCUMENT_ATT_SEND_API1

0 Kudos

Still i m unlucky with this.

My output table is stored in internal table 'i_output'.

Using funtion modules to send across. have a look and correct me where i m going wrong.

-


CODE -


FORM download_to_excel .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:/temp.xls'

filetype = 'ASC'

write_field_separator = 'x'

TABLES

data_tab = i_output

fieldnames = i_header

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22

.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " DOWNLOAD_TO_EXCEL

FORM mail_send.

w_doc_data-doc_size = 1.

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ''.

w_doc_data-sensitivty = 'F'.

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = <email id>.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

t_packing_list-doc_type = 'XLS'.

APPEND t_packing_list.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = 'C:/temp.xls'

  • APPEND_TO_TABLE = ' '

  • IMPORTING

  • OUTPUT_LENGTH =

tables

binary_tab = i_output.

refresh t_attachment.

  • t_attachment[] = i_output[].

REFRESH it_message.

it_message = 'Please find attached Billing Invoice Details - RE modififed'.

APPEND it_message.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = t_packing_list

  • OBJECT_HEADER =

  • CONTENTS_BIN = i_output

contents_txt = it_message

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " MAIL_SEND

FORM initiate_mail_execute_program.

WAIT UP TO 5 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

0 Kudos

it seems fine.

put a break point in your program and check what data is coming exactly to i_output at different stages.

0 Kudos

I am reading all extracted table details from work area to internal table.

copied from workarea to internal table for gui download.

append w_output = i_output.

when i chkd the i_output [] .. it says table [1X202] ...

Former Member
0 Kudos

REPORT zsendemail .

PARAMETERS: psubject(40) type c default 'Hello',

p_email(40) type c default 'write email address' .

data: it_packing_list like sopcklsti1 occurs 0 with header line,

it_contents like solisti1 occurs 0 with header line,

it_receivers like somlreci1 occurs 0 with header line,

it_attachment like solisti1 occurs 0 with header line,

gd_cnt type i,

gd_sent_all(1) type c,

gd_doc_data like sodocchgi1,

gd_error type sy-subrc.

data: it_message type standard table of SOLISTI1 initial size 0

with header line.

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

*START-OF-SELECTION.

START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send

*program has been executed(rsconn01)

PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)

perform initiate_mail_execute_program.

&----


*& Form POPULATE_MESSAGE_TABLE

&----


  • Adds text to email text table

----


form populate_message_table.

Append 'Email line 1' to it_message.

Append 'Email line 2' to it_message.

Append 'Email line 3' to it_message.

Append 'Email line 4' to it_message.

endform. " POPULATE_MESSAGE_TABLE

&----


*& Form SEND_EMAIL_MESSAGE

&----


  • Send email message

----


form send_email_message.

  • Fill the document data.

gd_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = 'F'.

  • Describe the body of the message

clear it_packing_list.

refresh it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

describe table it_message lines it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

append it_packing_list.

  • Add the recipients email address

clear it_receivers.

refresh it_receivers.

it_receivers-receiver = p_email.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

it_receivers-notif_del = 'X'.

it_receivers-notif_ndel = 'X'.

append it_receivers.

  • Call the FM to post the message to SAPMAIL

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gd_doc_data

put_in_outbox = 'X'

importing

sent_to_all = gd_sent_all

tables

packing_list = it_packing_list

contents_txt = it_message

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

  • Store function module return code

gd_error = sy-subrc.

  • Get it_receivers return code

loop at it_receivers.

endloop.

endform. " SEND_EMAIL_MESSAGE

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


form initiate_mail_execute_program.

wait up to 2 seconds.

if gd_error eq 0.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

endform. " INITIATE_MAIL_EXECUTE_PROGRAM

0 Kudos

Well above we need to enter email id and subject .. my question is abt sending excel file as attachment which will have atleast 100 records [15 columns *100 rows].

Or is this possible. I have downloaded output data in excel file and stored in local system.

Is it possible to pick up same file and then send to receiver. if yes, how is that possible.

I need to send excel file on my system as an email. how will we pass that attachment to Function module ??

Please advise @ earliest.

Thanks

0 Kudos

Any Luck ????????????????

0 Kudos

try this :

Regards

Neha

0 Kudos

Well .. i need to use same function module "SO_NEW_DOCUMENT_ATT_SEND_API1" to achieve target. those link was very helpful, but doesnt provide me more info with same fn module.

can any one please provide me sol at earliest ??

Thanks

pintoo_d
Participant
0 Kudos

I had to use tab_space delimiters to separate field so that excel can read the data.

and also CR_LF to append to nextline.

thank everyone who helped me.