Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

To send notepad as an attachment to email

Hi ,

I am facing one problem. I am sending a notepad as an attachment to a mail.

The reciepents name is in the distribution list. When I checked the notepad, Headers and the record are coming in the same line .

But it should come in the different line.

Here is the code.....

TYPE-POOLS: SLIS.

My final table is i_output.

TYPES: begin of TY_EMAIL,

field1(1) type c,

field2(8) type c,

field3(12) type c,

field4(34) type c,

field5(10) type c,

end of TY_EMAIL.

DATA: IT_ATTACH TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

T_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

T_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

T_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

W_CNT TYPE I,

W_SENT_ALL(1) TYPE C,

W_DOC_DATA LIKE SODOCCHGI1,

GD_ERROR TYPE SY-SUBRC,

GD_RECIEVER TYPE SY-SUBRC.

DATA: IT_EMAIL TYPE STANDARD TABLE OF TY_EMAIL WITH HEADER LINE.

START-OF-SELECTION.

PERFORM get_data.

PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT

TABLES IT_MESSAGE

IT_ATTACH

USING 'subject of mail'

'TXT'

'FILENAME'

CHANGING GD_ERROR

GD_RECIEVER.

END-OF-SELECTION.

form get_data.

CONCATENATE 'HEADER1'

'HEADER2'

'HEADER3'

'HEADER4'

'HEADER5'

INTO IT_ATTACH SEPARATED BY '~'

APPEND IT_ATTACH.

LOOP AT I_OUTPUT INTO WA_OUTPUT.

IT_EMAIL-FIELD1 = WA_OUPUT-FIELD1.

IT_EMAIL-FIELD2 = WA_OUPUT-FIELD2.

IT_EMAIL-FIELD3 = WA_OUPUT-FIELD3.

IT_EMAIL-FIELD4 = WA_OUPUT-FIELD4.

IT_EMAIL-FIELD5 = WA_OUPUT-FIELD5.

CONDENSE: IT_EMAIL-FIELD1,

IT_EMAIL-FIELD2,

IT_EMAIL-FIELD3,

IT_EMAIL-FIELD4,

IT_EMAIL-FIELD5.

CONCATTENATE: IT_EMAIL-FIELD1

IT_EMAIL-FIELD2

IT_EMAIL-FIELD3

IT_EMAIL-FIELD4

IT_EMAIL-FIELD5

INTO IT_ATTACH SEPERATED BY '~'

APPEND IT_ATTACH.

ENDLOOP.

FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE

PIT_ATTACH

USING P_MTITLE

P_FORMAT

P_FILENAME

CHANGING P_ERROR

P_RECIEVER.

DATA: BEGIN OF OBJPARA OCCURS 10 . "

INCLUDE STRUCTURE SELC. "

DATA: END OF OBJPARA. "

*

DATA: LD_ERROR TYPE SY-SUBRC,

LD_RECIEVER TYPE SY-SUBRC,

LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,

LD_EMAIL LIKE SOMLRECI1-RECEIVER,

LD_FORMAT TYPE SO_OBJ_TP ,

LD_ATTFILENAME TYPE SO_OBJ_DES ,

LD_RECEIVER LIKE SY-SUBRC.

DATA SENT_ALL LIKE SONV-FLAG.

DATA WARNING_MAIL LIKE SOODK.

LD_MTITLE = P_MTITLE.

LD_FORMAT = P_FORMAT.

LD_ATTFILENAME = P_FILENAME.

  • Fill the document data and get size of attachment

CLEAR OBJECT_HD.

READ TABLE IT_ATTACH INDEX W_CNT.

OBJECT_HD-DOC_SIZE =

( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).

OBJECT_HD-OBJ_LANGU = SY-LANGU.

OBJECT_HD-OBJ_NAME = 'SAPRPT'.

OBJECT_HD-OBJ_DESCR = LD_MTITLE.

OBJECT_HD-SENSITIVTY = 'F'.

CLEAR T_ATTACHMENT.

REFRESH T_ATTACHMENT.

T_ATTACHMENT[] = PIT_ATTACH[].

  • Describe the body of the message

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.

DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = 'RAW'.

APPEND T_PACKING_LIST.

  • Create attachment notification

T_PACKING_LIST-TRANSF_BIN = 'X'.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 1.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = LD_FORMAT.

T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.

T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.

APPEND T_PACKING_LIST.

  • Receipient Information for SAP Office.

MOVE: 'ZDIPIKA' TO RECEIVERS-RECNAM, "Receipient Name

'C ' TO RECEIVERS-RECESC, "Repeipient Type

' ' TO RECEIVERS-SNDEX, "Send Express

SY-DATUM TO RECEIVERS-RCDAT, "Message Date

SY-UZEIT TO RECEIVERS-RCTIM, "Message Time

'X' TO RECEIVERS-SNDCP. "Send Copy

APPEND RECEIVERS.

  • Add the recipients email address

CLEAR T_RECEIVERS.

REFRESH T_RECEIVERS.

T_RECEIVERS-RECEIVER = 'ZDIPIKA'. "LD_EMAIL.

T_RECEIVERS-REC_TYPE = 'C'.

T_RECEIVERS-COM_TYPE = 'INT'.

T_RECEIVERS-NOTIF_DEL = 'X'.

T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = OBJECT_HD

PUT_IN_OUTBOX = 'X'

  • SENDER_ADDRESS = LD_SENDER_ADDRESS

  • SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE

COMMIT_WORK = 'X'

IMPORTING

SENT_TO_ALL = W_SENT_ALL

TABLES

PACKING_LIST = T_PACKING_LIST

CONTENTS_BIN = T_ATTACHMENT

CONTENTS_TXT = IT_MESSAGE

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.

  • Populate zerror return code

LD_ERROR = SY-SUBRC.

*

IF SY-SUBRC NE 0.

MESSAGE A095(ZZ) WITH LD_ERROR.

ENDIF.

*

COMMIT WORK.

-- DEQUEUE THE LOCK CREATED BY SO_OBJECT_SEND -


CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.

endform. " SEND_FILE_AS_EMAIL_ATTACHMENT

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question