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: 

FM to send Email with 2 attachmetns ?

Former Member
0 Kudos

Dear all,

I require a FM in ABAP, which can be used to send a mail with 2 attachmets ..

Please help me with the answer.

Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

use FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

theja

8 REPLIES 8

Former Member
0 Kudos

hi,

use FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

theja

0 Kudos

Hi Thejaswi,

Is it possible to send two internal tables as attachments by using this FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' ?

If yes..could U please send me sample code ?

Thanks a lot.

Former Member
0 Kudos

SR

Normally we use FM : SO_NEW_DOCUMENT_SEND_API1

But i am not sure it is possible to attach 2 attachements.

Thanks

Jack

<b>Allot points if my post helps!!!</b>

Former Member
0 Kudos

The above mentioned FM can be used to send multiple attach ments also. oNly thing u have to do is to pass correct values to the

packing_list

object_header

contents_bin

contents_txt

refer to the documentation of this FM. this requires some coding before

Former Member
0 Kudos

hi,

check this out

Re: Emailing Two Attachments

Posted: Jun 12, 2006 1:18 PM Reply E-mail this post

hi john,

check this code...

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 = '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 = 'xxx@yahoo.com'.

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.

theja

0 Kudos

Thanks a lot Theja..

Former Member
0 Kudos

REPORT z_52341_mail.

  • Data Declaration

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

DATA packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE .

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.

objbin = ' | '. APPEND objbin.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

DESCRIBE TABLE objbin LINES tab_lines.

objpack-head_start = 1.

  • NOTE: Create ALI/OTF Document in Spool

  • ALI Document can be created by displaying a list and selecting

  • menue System -> List -> Print (only put to Spool).

  • OTF Document can be created running report SF_EXAMPLE_01 in system.

  • Example used here:

  • create list in memory

SUBMIT z_52341_alv EXPORTING LIST TO MEMORY AND RETURN.

  • and read list from memory into table

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'LIST_FROM_MEMORY'.

ENDIF.

packing_list = objpack.

  • Because listobject is of size RAW(1000)

  • and objbin is of size CHAR(255) we make this table copy

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

in = listobject

out = objbin

EXCEPTIONS

OTHERS = 1 .

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

  • NOTE: Creation of attachment is finished yet.

  • For your report, the attachment should be placed into table

  • objtxt for plain text or objbin for binary content.

  • Now create the message and send the document. 'recipients!'.

  • Create Message Body

  • Title and Description

docdata-obj_name = 'TEST_ALI'.

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

  • Main Text

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.

  • Write Packing List (Main)

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 Message Attachment

  • Write Packing List (Attachment)

att_type = 'AL'.

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 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.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'Attached Document'.

APPEND objpack.

*/ Above portion is with two Attachments.

objpack-doc_size = ( tab_lines - 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.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'Attached Document'.

APPEND objpack.

  • Create receiver list

*reclist-receiver = 'testuser@ COMPANY.COM'. "<-- change address

*reclist-rec_type = 'U'.

*APPEND reclist.

reclist-receiver = sy-uname. " <-- change internal user

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' "used from rel. 6.10

  • 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

.

IF sy-subrc <> 0.

MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

WITH docdata-obj_name.

ENDIF.

WRITE: / 'End of Program'.

Former Member
0 Kudos

Hi S R,

try this

REPORT Z_TEST.

*

  • --- Parameter für SO_DOCUMENT_SEND_API1

DATA: OBJ_PACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

OBJ_HEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

OBJ_BIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

OBJ_TXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

REC_LIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

DOC_DATA LIKE SODOCCHGI1.

*

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

*

START-OF-SELECTION.

*

  • email füllen

  • Betreff-Zeile

CLEAR: DOC_DATA.

DOC_DATA-OBJ_NAME = SY-REPID.

DOC_DATA-OBJ_DESCR = 'Send via email RAW'.

  • Empfängerliste

  • email-User (U)

CLEAR REC_LIST.

REC_LIST-RECEIVER = 'test@test.de'. "email address

REC_LIST-REC_TYPE = 'U'.

APPEND REC_LIST.

*

  • PACKING_LIST: 1. Zeile gilt immer für email-Inhalt

CLEAR OBJ_PACK.

OBJ_PACK-BODY_START = 01.

OBJ_PACK-BODY_NUM = 01.

OBJ_PACK-DOC_TYPE = 'RAW'.

APPEND OBJ_PACK.

*

  • PACKING_LIST: 2. und Folgezeilen gelten immer für Anlagen

CLEAR OBJ_PACK.

OBJ_PACK-TRANSF_BIN = 'X'.

OBJ_PACK-BODY_START = 01.

OBJ_PACK-BODY_NUM = 05.

OBJ_PACK-DOC_TYPE = 'RAW'.

OBJ_PACK-OBJ_NAME = 'Anhang1'.

OBJ_PACK-OBJ_DESCR = SY-REPID.

APPEND OBJ_PACK.

CLEAR OBJ_PACK.

OBJ_PACK-TRANSF_BIN = 'X'.

OBJ_PACK-BODY_START = 06.

OBJ_PACK-BODY_NUM = 10.

OBJ_PACK-DOC_TYPE = 'RAW'.

OBJ_PACK-OBJ_NAME = 'Anhang2'.

OBJ_PACK-OBJ_DESCR = SY-REPID.

APPEND OBJ_PACK.

*

*emailinhalt

CLEAR: OBJ_TXT.

OBJ_TXT-LINE = 'Hallo,'.

APPEND OBJ_TXT.

OBJ_TXT-LINE = 'Testline'.

APPEND OBJ_TXT.

*

*Anlageninhalt

OBJ_BIN = '01. Line'. APPEND OBJ_BIN.

OBJ_BIN = '02. Line'. APPEND OBJ_BIN.

OBJ_BIN = '03. Line'. APPEND OBJ_BIN.

OBJ_BIN = '04. Line'. APPEND OBJ_BIN.

OBJ_BIN = '05. Line'. APPEND OBJ_BIN.

*

OBJ_BIN = '06. Line'. APPEND OBJ_BIN.

OBJ_BIN = '07. Line'. APPEND OBJ_BIN.

OBJ_BIN = '08. Line'. APPEND OBJ_BIN.

OBJ_BIN = '09. Line'. APPEND OBJ_BIN.

OBJ_BIN = '10. Line'. APPEND OBJ_BIN.

  • --- Versenden des Dokuments

*

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_DATA

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJ_PACK

CONTENTS_TXT = OBJ_TXT

CONTENTS_BIN = OBJ_BIN

RECEIVERS = REC_LIST

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.

*

  • Besser 2 Sekunden warten, damit alles versendet ist

WAIT UP TO 2 SECONDS.

*

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = ' '

AND RETURN.

*

Regards, Dieter