Skip to Content
0
Former Member
May 31, 2006 at 11:33 AM

Bug sending email with Excel file (immediate reply would he helpfull)

32 Views

Hi ,

Below is have pasted a sample code where it will sends a email along with an attachtment (xls) .where the email is working perfectly but the xls file attachtment has a blank space in the first line .

where iam facing the problem ,

ie there should not be any blank lines at the top .

Please run the code one i have pasted below .u can find the bug .

can any one help me on this .

please have ur mail id in ( reclist-receiver ) so that u can check for the output.

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

  • This table requires information about how the data in the

  • tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are

  • to be distributed to the documents and its attachments.

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

  • This table must contain the summarized data dependent on each object type.

  • SAPscript objects store information here about forms and styles,

  • for example. Excel list viewer objects store the number of rows and columns

  • amongst other things and PC objects store their original file name.

DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

*CREATION OF INTERNAL TABLE

DATA : BEGIN OF itobjbin OCCURS 10 ,

vbeln type vbrp-vbeln,

matnr type vbrp-matnr,

werks type vbrp-werks,

fktyp like vbrk-fktyp,

END OF itobjbin .

  • This table must contain the summarized content of the objects identified as binary objects.

*DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: wa_itobjbin LIKE itobjbin .

  • This table must contain the summarized content of the objects identified as ASCII objects.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

  • This table must contain the document recipients.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

  • This structure must contain the attributes of the document to be sent.

DATA: doc_chng LIKE sodocchgi1.

DATA: tab_lines LIKE sy-tabix.

DATA : V_FKTYP LIKE VBRK-FKTYP.

  • Creating the document to be sent

doc_chng-obj_name = 'OFFER'. " input contains the attributes of the document to be sent

doc_chng-obj_descr = 'EMAIL WITH EXCEL DOWNLOAD'. "input contains title/subject of the document

*BODY OF THE MAIL

OBJTXT = 'Hi'.

APPEND OBJTXT .

OBJTXT = 'Test for excel download'.

APPEND OBJTXT.

OBJTXT = 'Below is the attachment with Billing Document Details'.

APPEND OBJTXT.

OBJTXT = 'Regards'.

APPEND OBJTXT.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

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

  • Creating the entry for the compressed document

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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

select vbeln matnr werks

from vbrp into table itobjbin

up to 10 rows

where werks GE '1000'.

loop at itobjbin.

select single fktyp into v_fktyp from vbrk where vbeln = itobjbin-vbeln.

move v_fktyp to itobjbin-fktyp.

modify itobjbin.

endloop.

PERFORM build_xls_data_table .

DESCRIBE TABLE objbin LINES tab_lines.

objhead = 'ABC.XLS'. APPEND objhead.

  • Creating 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 = 'XLS'.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'XLS'.

objpack-doc_size = tab_lines * 255.

APPEND objpack..

  • Entering names in the distribution list

reclist-receiver = ''.

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 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of', 'recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

&----


*& Form build_xls_data_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_xls_data_table .

CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode

con_tab TYPE x VALUE '09'. "OK for non Unicode

CONCATENATE 'Billing Document' 'Material Number' 'Plant' 'Billing category' ' ' INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

LOOP AT itobjbin .

CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp' '

INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

ENDLOOP.

thanks in advance,

vinay .