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: 

Sending mail with excel attachment-improper format

Former Member
0 Kudos

Dear experts,

I am sending a mail to outlook with an excel attachment. The mail is sent with attachment and the data, but all in one cell.

I am using SO_NEW_DOCUMENT_ATT_SEND_API1. What parameters do i need to manipulate to have data in different columns of excel? I am using "packing_list" table of FM. But dont know the exact parameters to be passed. Can anyone help with the same please?

Best regards and thanks!

Sumit Nene.

3 REPLIES 3

Former Member
0 Kudos

Hello Sumit,

I am using same function module to send mail with excel attachment.

Below I am attaching my own code for your reference.

Data which u want to add in excel file is maintain in IT_OBJBIN i.e. document information.

CLEAR :IMESSAGE,IT_OBJBIN,IT_OBJPACK,IT_RECLIST.

REFRESH: IMESSAGE[ ] , IT_OBJBIN[ ] , IT_OBJPACK[ ] , IT_RECLIST[ ].

" populate the text for body of the mail

CLEAR WA_IMESSAGE.

CONCATENATE 'Board : ' P_BOARD ':' 'Please find the excel attached for the list of Material whose routing is created' INTO WA_IMESSAGE-LINE.

APPEND WA_IMESSAGE TO IMESSAGE.

"document information

W_DOC_CHNG-OBJ_NAME = 'Excel'.

IF NOT P_BOARD IS INITIAL.

CONCATENATE 'Board : ' P_BOARD ':' 'List Of Routing Materials' INTO W_DOC_CHNG-OBJ_DESCR.

ELSE.

CONCATENATE 'List Of' ' Routing Materials' INTO W_DOC_CHNG-OBJ_DESCR.

ENDIF.

W_DOC_CHNG-SENSITIVTY = 'F'. " ->Functional object

" displaying material , plant in the excel

CONCATENATE 'BOARD NO : ' P_BOARD INTO WA_OBJBIN.

APPEND WA_OBJBIN TO IT_OBJBIN.

CONCATENATE 'MATERIAL' 'PLANT' 'DESCRIPTION' INTO WA_OBJBIN SEPARATED BY C_TAB.

CONCATENATE C_RET WA_OBJBIN INTO WA_OBJBIN.

APPEND WA_OBJBIN TO IT_OBJBIN.

CLEAR : WA_OBJBIN.

LOOP AT IT_DOWNLOAD INTO WA_DOWNLOAD. "It_orders is the internal table to be transferred to excel

CONCATENATE WA_DOWNLOAD-MATNR WA_DOWNLOAD-WERKS WA_DOWNLOAD-DESC INTO WA_OBJBIN SEPARATED BY C_TAB.

CONCATENATE C_RET WA_OBJBIN INTO WA_OBJBIN.

APPEND WA_OBJBIN TO IT_OBJBIN.

ENDLOOP.

DESCRIBE TABLE IT_OBJBIN LINES V_LINES_BIN. " no of lines for excel data

" pack the data as RAW

CLEAR WA_IT_OBJPACK-TRANSF_BIN. "Obj. to be transported not in binary form

WA_IT_OBJPACK-HEAD_START = 1. "Start line of object header in transport packet

WA_IT_OBJPACK-HEAD_NUM = 0. "Number of lines of an object header in object packet

WA_IT_OBJPACK-BODY_START = 1. "Start line of object contents in an object packet

WA_IT_OBJPACK-BODY_NUM = MESSAGE_LINES. "Number of lines of the mail body

WA_IT_OBJPACK-DOC_TYPE = 'RAW'.

APPEND WA_IT_OBJPACK TO IT_OBJPACK.

" pack the data as excel

WA_IT_OBJPACK-TRANSF_BIN = 'X'.

WA_IT_OBJPACK-HEAD_START = 1.

WA_IT_OBJPACK-HEAD_NUM = 1.

WA_IT_OBJPACK-BODY_START = 1.

WA_IT_OBJPACK-BODY_NUM = V_LINES_BIN. "no of lines of it_orders to give no of unprocessed orders

WA_IT_OBJPACK-DOC_TYPE = 'XLS'. " -> excel fomat

WA_IT_OBJPACK-OBJ_NAME = 'EXCEL ATTACHMENT'.

" attachment name

IF NOT P_BOARD IS INITIAL.

CONCATENATE P_BOARD '.XLS' INTO WA_IT_OBJPACK-OBJ_DESCR.

ELSE.

CONCATENATE 'LIST' '.XLS' INTO WA_IT_OBJPACK-OBJ_DESCR.

ENDIF.

WA_IT_OBJPACK-DOC_SIZE = V_LINES_BIN * 255.

APPEND WA_IT_OBJPACK TO IT_OBJPACK.

" creating email id

DATA: STR1 TYPE STRING,

STR2 TYPE STRING,

STR3 TYPE STRING,

ITAB TYPE TABLE OF STRING.

DATA : WA_I LIKE LINE OF ITAB.

SPLIT P_EMAIL AT ',' INTO: TABLE ITAB.

  • e-mail receivers.

CLEAR WA_IT_RECLIST.

LOOP AT ITAB INTO WA_I.

WA_IT_RECLIST-RECEIVER = WA_I.

  • WA_IT_RECLIST-RECEIVER = V_MAILADDR.

WA_IT_RECLIST-EXPRESS = 'X'.

WA_IT_RECLIST-REC_TYPE = 'U'. "-> Internet address

APPEND WA_IT_RECLIST TO IT_RECLIST.

CLEAR WA_IT_RECLIST.

ENDLOOP.

" sending mail

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = IT_OBJPACK

  • OBJECT_HEADER =

CONTENTS_BIN = IT_OBJBIN

CONTENTS_TXT = IMESSAGE

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = IT_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

.

COMMIT WORK.

IF SY-SUBRC = 0.

MESSAGE I001 WITH 'Routing is Created for Board' P_BOARD 'and Mail send on e-mail id :' P_EMAIL.

ENDIF.

Former Member
0 Kudos

..

Former Member
0 Kudos

Solved

Solution--

Referred standard report

BCS_EXAMPLE_7

and these field separators did the trick.

constants:
  gc_tab  type c value cl_bcs_convert=>gc_tab,               " for next cell
  gc_crlf type c value cl_bcs_convert=>gc_crlf.               " for next line  .

CONCATENATE 'line1-cell1' gc_tab 'line1-cell2' gc_tab gc_crlf 'line2-cell1' gc_tab 'line2-cell2' gc_tab INTO OBJCONT_PU-LINE.
APPEND OBJCONT_PU.

Regards,

Sumit