10-15-2007 9:17 PM
hi there,
With the below code I actually get the email in my inbox with the pdf attachment.But the pdf file has 2 kb and it doen't open.
I get a message in a popup as " Could not open file because it is either not a supported file type or because the file has been damaged( for example it was sent as an attachment and wasn't correctly decoded"
some one plz help me.
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.
data: intnast like snast occurs 0 with header line.
DATA: E_EKGRP LIKE EKKO-EKGRP.
DATA: CCEMAIL LIKE T024-SMTP_ADDR.
data: LEN_IN like sood-objlen.
data: LEN_OUT like sood-objlen.
data: OTF_TAB TYPE SOLI_TAB.
data: itab2 TYPE SOLIX_TAB.
DATA: W_TRANSFER_BIN TYPE SX_BOOLEAN occurs 10 with header line. "Content
MOVE-CORRESPONDING nast TO intnast.
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = NAST-TDCOVTITLE.
Mail Contents
OBJTXT = NAST-TDCOVTITLE.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of 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.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = NAST-TDOCOVER.
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 = 'PDF'.
OBJPACK-OBJ_NAME = DOCSUB1.
OBJPACK-OBJ_DESCR = NAST-TDCOVTITLE.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
FORMAT_SRC = 'OTF'
FORMAT_DST = 'PDF'
DEVTYPE = 'ASCIIPRI'
LEN_IN = TAB_LINES
IMPORTING
LEN_OUT = LEN_OUT
TABLES
TRANSFER_BIN = W_TRANSFER_BIN
CONTENT_IN = intnast
CONTENT_OUT = ITAB2
EXCEPTIONS
ERR_CONV_FAILED = 1
OTHERS = 2.
SELECT SINGLE EKGRP INTO E_EKGRP FROM EKKO
WHERE EBELN = NAST-OBJKY.
SELECT SINGLE SMTP_ADDR INTO CCEMAIL FROM T024
WHERE EKGRP = E_EKGRP.
copy recipents
clear RECLIST.
RECLIST-RECEIVER = CCEMAIL.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
RECLIST-COPY = 'X'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
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.
10-16-2007 9:57 AM
Hi,
The error is bcz you need to convert the file to 255 character set.
Please refer this sample program:
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
* Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Best regards,
Prashant