Skip to Content

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

PDF Emailing of script

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.

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