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

Function Module to send output list to mail.

Former Member
0 Likes
1,181

Hi,

Could anyone let me know the function module to send output list to mail.

Regards,

Ramesh

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
821

Here is a sample program which does the same.




report zrich_0003 .

data: list type table of  abaplist with header line.
data: htmllines type table of w3html with header line.

data: maildata   like sodocchgi1.
data: mailtxt    like solisti1 occurs 10 with header line.
data: mailrec    like somlrec90 occurs 0  with header line.

start-of-selection.

* Write the list
  do 100 times.
    write:/ sy-index, at 30 sy-index, at 50 sy-index.
  enddo.

* Save the list
  call function 'SAVE_LIST'
       tables
            listobject         = list
       exceptions
            list_index_invalid = 1
            others             = 2.

* Convert to HTML
  call function 'WWW_LIST_TO_HTML'
       tables
            html = htmllines.

  perform build_text_message.
  perform build_receivers.
  perform send_mail_nodialog..

************************************************************************
*      Form  BUILD_TEXT_MESSAGE
************************************************************************
form build_text_message.

  maildata-obj_name = 'TEST'.
  maildata-obj_descr = 'Test Subject'.

  loop at htmllines.
    mailtxt = htmllines.
    append mailtxt.
  endloop.

endform.

************************************************************************
*      Form  BUILD_RECEIVERS
************************************************************************
form build_receivers.

  mailrec-receiver = 'you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  append mailrec.

endform.

************************************************************************
*      Form  SEND_MAIL_NODIALOG
************************************************************************
form send_mail_nodialog.

  call function 'SO_NEW_DOCUMENT_SEND_API1'
       exporting
            document_data              = maildata
            document_type              = 'HTM'
            put_in_outbox              = 'X'
       tables
            object_header              = mailtxt
            object_content             = mailtxt
            receivers                  = mailrec
       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.

endform.

Regards,

Rich Heilman

Read only

0 Likes
821

HI,

I have given my mail ID in "form build_receivers".

But i could not get the output list to my inbox.

Is there anything we need to add to this code...

Regards,

Ramesh

Read only

0 Likes
821

You need to force the mail to be send, you can do this via SCOT.

Or you can added the following code at the end of the program. Of course, the sapconnect must be configure.

submit RSCONN01
       with mode = 'INT'
            and return.

Regards,

Rich Heilman

Read only

0 Likes
821

after the function module call place this code.

IF sy-subrc = 0.

MESSAGE s027(vv) WITH 'E-mail has been sent'.

COMMIT WORK.

*- buffered emails can be released via rsconn01.

SUBMIT rsconn01 USING SELECTION-SET 'SAP&CONNECTINT' AND RETURN.

ELSE.

MESSAGE s027(vv) WITH 'E-mail not sent'.

ENDIF.

this way you can send all spool mails immediately from it.

else you can use the transaction <b>SCOT</b>, to send the spool requests manually.

<b>SOST</b> is the transaction , to see the send mails status.

regards

srikanth

Read only

Former Member
0 Likes
821

hi ramesh,

use the FM SO_NEW_DOCUMENT_ATT_SEND_API1'

OR SO_OBJECT_SEND

&----


*& Report ZPSENDMAILEXTERNAL *

*& *

&----


*& *

*& *

&----


report zpsendmailexternal .

data: objpack like sopcklsti1 occurs 2 with header line.

data: objhead like solisti1 occurs 1 with header line.

data: objbin like solisti1 occurs 10 with header line.

data: objtxt like solisti1 occurs 10 with header line.

data: reclist like somlreci1 occurs 5 with header line.

data: doc_chng like sodocchgi1.

data: tab_lines like sy-tabix.

  • Creation of the document to be sent

  • File Name

doc_chng-obj_name = 'SENDFILE'.

  • Mail Subject

doc_chng-obj_descr = 'Send test Mail'.

  • Mail Contents

objtxt = 'HELLO'.

append objtxt.

objtxt = 'THIS IS THE FIRST TEST MAIL'.

append objtxt.

objtxt = 'have a good day'.

append objtxt.

describe table objtxt lines tab_lines.

read table objtxt index tab_lines.

**attachment

objbin-line = 'PRIYA... this is the first document'.

append objbin.

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

clear objpack-transf_bin.

*OBJPACK-TRANSF_BIN = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

*OBJPACK-BODY_NUM = 1.

objpack-doc_type = 'RAW'.

objpack-obj_name = 'Mail'.

objpack-obj_descr = 'First Mail'.

objpack-doc_size = 1 * 255.

append objpack.

  • Creation of the entry for the compressed document

*CLEAR OBJPACK-TRANSF_BIN.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

*OBJPACK-BODY_NUM = TAB_LINES.

objpack-body_num = 1.

objpack-doc_type = 'RAW'.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'Attached Document'.

objpack-doc_size = 1 * 255.

append objpack.

**Creation of the document attachment

    • (Assume that the data in OBJBIN is in BMP format)

*CLEAR OBJPACK-TRANSF_BIN.

objbin = ' \O/ '. append objbin.

objbin = ' | '. append objbin.

objbin = ' / \ '. append objbin.

describe table objbin lines tab_lines.

objhead = 'Ram149_jpg.jpg'.

append objhead.

    • Creation of the entry for the compressed attachment

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'JPG'.

objpack-obj_name = 'PICTURE'.

objpack-obj_descr = 'Picture'.

objpack-doc_size = tab_lines * 255.

append objpack.

  • Completing the recipient list

RECLIST-RECEIVER = <MAIL-ID>.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

  • Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = doc_chng

put_in_outbox = 'X'

commit_work = '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.

case sy-subrc.

when 0.

write: / 'Result of the send process:'.

loop at reclist.

write: / reclist-receiver(48), ':'.

if reclist-retrn_code = 0.

write 'The document was sent'.

else.

write 'The document could not be sent'.

endif.

endloop.

when 1.

write: / 'No authorization for sending to the specified number',

'of recipients'.

when 2.

write: / 'Document could not be sent to any recipient'.

when 4.

write: / 'No send authorization'.

when others.

write: / 'Error occurred while sending'.

endcase.

hope this helps,

do reward if it helps,

priya.

Read only

Former Member
0 Likes
821

Hi,

Please try with following sample code

Sending mail with attachment

  • This program will allowed you to send email with attachment.

  • First, specify the attachment file from your local hardisk and execute.

  • Next, specify the sender email address and click the send button.

report YUP_MAIL.

data method1 like sy-ucomm.

data g_user like soudnamei1.

data g_user_data like soudatai1.

data g_owner like soud-usrnam.

data g_receipients like soos1 occurs 0 with header line.

data g_document like sood4 .

data g_header like sood2.

data g_folmam like sofm2.

data g_objcnt like soli occurs 0 with header line.

data g_objhead like soli occurs 0 with header line.

data g_objpara like selc occurs 0 with header line.

data g_objparb like soop1 occurs 0 with header line.

data g_attachments like sood5 occurs 0 with header line.

data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.

data g_ref_document like sood4.

data g_new_parent like soodk.

data: begin of g_files occurs 10 ,

text(4096) type c,

end of g_files.

data : fold_number(12) type c,

fold_yr(2) type c,

fold_type(3) type c.

parameters ws_file(4096) type c default 'c:\debugger.txt'.

  • Can me any file fromyour pc ....either xls or word or ppt etc ...

g_user-sapname = sy-uname.

call function 'SO_USER_READ_API1'

exporting

user = g_user

  • PREPARE_FOR_FOLDER_ACCESS = ' '

importing

user_data = g_user_data

  • EXCEPTIONS

  • USER_NOT_EXIST = 1

  • PARAMETER_ERROR = 2

  • X_ERROR = 3

  • OTHERS = 4

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

fold_type = g_user_data-outboxfol+0(3).

fold_yr = g_user_data-outboxfol+3(2).

fold_number = g_user_data-outboxfol+5(12).

clear g_files.

refresh : g_objcnt,

g_objhead,

g_objpara,

g_objparb,

g_receipients,

g_attachments,

g_references,

g_files.

method1 = 'SAVE'.

g_document-foltp = fold_type.

g_document-folyr = fold_yr.

g_document-folno = fold_number.

g_document-objtp = g_user_data-object_typ.

*g_document-OBJYR = '27'.

*g_document-OBJNO = '000000002365'.

*g_document-OBJNAM = 'MESSAGE'.

g_document-objdes = 'sap-img.com testing by program'.

g_document-folrg = 'O'.

*g_document-okcode = 'CHNG'.

g_document-objlen = '0'.

g_document-file_ext = 'TXT'.

g_header-objdes = 'sap-img.com testing by program'.

g_header-file_ext = 'TXT'.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = sy-uname

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

  • FOLMEM_DATA =

  • RECEIVE_DATA =

.

  • File from the pc to send...

method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.

append g_files.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.

g_receipients-recesc = 'B'.

g_receipients-sndex = 'X'.

append g_receipients.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header.

*-- End of Program

Thanks,

-Pramod