Skip to Content

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

Smartform to PDF conversion

Hi Experts ,

I am sending an e-mail aith a PDF attachment , the attachment contains a greeting card (BIT MAP file),

When i find the mail , PDF is opening with error 'Drawing Error Occured'.

Pls find the sample code ...

CALL FUNCTION V_FORM_NAME

EXPORTING

ARCHIVE_PARAMETERS = W_ARCLOP

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = 'X'

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

I_OTF[] = W_RETURN-OTFDATA[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

CHECK NOT ( I_TLINE[] IS INITIAL ).

DATA :LV_COUNTER TYPE I.

DATA :LV_FROM TYPE I.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING ' ~' .

CONCATENATE IT_ATTACHMENT_LONG I_TLINE INTO IT_ATTACHMENT_LONG

.

ENDLOOP.

TRANSLATE IT_ATTACHMENT_LONG USING '~ ' .

APPEND IT_ATTACHMENT_LONG.

CLEAR : LV_COUNTER.

DO.

LV_COUNTER = STRLEN( IT_ATTACHMENT_LONG ).

IF LV_COUNTER GE 255.

IT_ATTACHMENT = IT_ATTACHMENT_LONG(255).

APPEND IT_ATTACHMENT.

SHIFT IT_ATTACHMENT_LONG BY 255 PLACES.

ELSE.

IT_ATTACHMENT = IT_ATTACHMENT_LONG(LV_COUNTER).

APPEND IT_ATTACHMENT.

EXIT.

ENDIF.

ENDDO.

*END:ADDED COMMENTS LINE BY SUHAS 27.01.2007

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

DESCRIBE TABLE LT_OBJTXT LINES L_TAB_LINES.

READ TABLE LT_OBJTXT INDEX L_TAB_LINES.

LE_DOC_CHNG-DOC_SIZE = ( L_TAB_LINES - 1 ) * 255

+ STRLEN( LT_OBJTXT ).

  • Title of the email as spool name

CONCATENATE 'Happy Birthday :' T522T-ATEXT PA0002-VORNA PA0002-NACHN

INTO TITLE SEPARATED BY SPACE.

LV_DOCUMENT_DATA-OBJ_DESCR = TITLE.

LV_DOCUMENT_DATA-SENSITIVTY = 'O'.

LV_DOCUMENT_DATA-EXPIRY_DAT = SY-DATUM + 15.

LV_DOCUMENT_DATA-DOC_SIZE = STRLEN( LT_OBJTXT ).

  • e-mail body

CLEAR LT_OBJPACK.

LT_OBJPACK-HEAD_START = 1.

LT_OBJPACK-HEAD_NUM = 0.

LT_OBJPACK-BODY_START = 1.

LT_OBJPACK-BODY_NUM = L_TAB_LINES.

LT_OBJPACK-DOC_TYPE = 'RAW'.

APPEND LT_OBJPACK.

*START:ADDED COMMENTS BY SUHAS 27.01.2007

  • For e-mail attachment

DESCRIBE TABLE IT_ATTACHMENT LINES L_ATT_LINES.

READ TABLE IT_ATTACHMENT INDEX L_ATT_LINES.

*END:ADDED COMMENTS BY SUHAS 27.01.2007

*START:ADDED COMMENTS BY SUHAS 27.01.2007

CLEAR LT_OBJPACK.

LT_OBJPACK-TRANSF_BIN = 'X'.

LT_OBJPACK-HEAD_START = 1.

LT_OBJPACK-HEAD_NUM = 1.

LT_OBJPACK-BODY_START = 1.

LT_OBJPACK-BODY_NUM = L_ATT_LINES.

LT_OBJPACK-DOC_TYPE = 'PDF'.

LT_OBJPACK-OBJ_NAME = 'email'.

LT_OBJPACK-OBJ_DESCR = LV_SPOOL_DESC.

LT_OBJPACK-DOC_SIZE = ( 255 * ( L_ATT_LINES - 1 ) ) +

STRLEN(

IT_ATTACHMENT-LINE ).

LT_OBJPACK-OBJ_NAME = 'Salary Slip'.

LT_OBJPACK-OBJ_NAME = TITLE.

WRITE SY-DATUM TO LT_OBJPACK-OBJ_DESCR.

CONCATENATE 'Bday' LT_OBJPACK-OBJ_DESCR INTO

LT_OBJPACK-OBJ_DESCR

SEPARATED BY SPACE.

CONCATENATE LT_OBJPACK-OBJ_DESCR '.PDF' INTO

LT_OBJPACK-OBJ_DESCR.

APPEND LT_OBJPACK.

*END:ADDED COMMENTS BY SUHAS 27.01.2007

LT_RECLIST-RECEIVER = PA0105-USRID_LONG.

LT_RECLIST-REC_TYPE = 'U'.

APPEND LT_RECLIST.

CLEAR LT_RECLIST.

LT_RECLIST-RECEIVER = V_RESMAIL.

LT_RECLIST-REC_TYPE = 'U'.

APPEND LT_RECLIST.

CLEAR LT_RECLIST.

*START:ADDED LINE BY SUHAS 25.01.08

SELECT SINGLE BUKRS INTO PA0001-BUKRS

FROM PA0001

WHERE PERNR EQ IT_PA0001-PERNR AND

BEGDA LE SY-DATUM AND

ENDDA GE SY-DATUM.

SELECT A~PERNR INTO CORRESPONDING FIELDS OF TABLE IT_PR

FROM ZHR_BIRTHDAY AS A INNER JOIN PA0001 AS B ON

APERNR EQ BPERNR

WHERE A~DFLAG = '' AND

B~BUKRS EQ PA0001-BUKRS AND

B~BEGDA LE SY-DATUM AND

B~ENDDA GE SY-DATUM.

LOOP AT IT_PR.

SELECT SINGLE USRID_LONG INTO PA0105-USRID_LONG

FROM PA0105

WHERE PERNR = IT_PR-PERNR AND

SUBTY = '0010' AND

BEGDA LE SY-DATUM AND

ENDDA GE SY-DATUM.

IF SY-SUBRC = 0.

LT_RECLIST-RECEIVER = PA0105-USRID_LONG.

LT_RECLIST-REC_TYPE = 'U'.

APPEND LT_RECLIST.

ENDIF.

ENDLOOP.

*END:ADDED LINE BY SUHAS 25.01.08

  • Provide Employee Email List Cost Centerwise.

IF IT_PA0001-KOSTL NE ''.

SELECT PERNR INTO PA0001-PERNR

FROM PA0001

WHERE KOSTL = IT_PA0001-KOSTL AND

BEGDA LE SY-DATUM AND

ENDDA GE SY-DATUM.

IF SY-SUBRC = 0.

*CHECKING EMPLOYEE ACTIVE STATUS.

CALL FUNCTION 'RP_GET_FIRE_DATE'

EXPORTING

PERSNR = PA0001-PERNR

  • STATUS2 = '0'

IMPORTING

FIREDATE = FIRE_DATE1.

IF FIRE_DATE1 IS NOT INITIAL.

ELSE.

SELECT SINGLE USRID_LONG INTO PA0105-USRID_LONG

FROM PA0105

WHERE PERNR = PA0001-PERNR AND

SUBTY = '0010' AND

BEGDA LE SY-DATUM AND

ENDDA GE SY-DATUM.

IF SY-SUBRC = 0.

LT_RECLIST-RECEIVER = PA0105-USRID_LONG.

LT_RECLIST-REC_TYPE = 'U'.

APPEND LT_RECLIST.

ENDIF.

ENDIF.

ENDIF.

ENDSELECT.

ENDIF.

  • for it department employee

  • SELECT SINGLE PERNR INTO PA0001-PERNR

  • FROM PA0001

  • WHERE PERNR EQ IT_PA0001-PERNR AND

  • KOSTL IN S_KOSTL.

  • IF SY-SUBRC = 0.

  • SELECT PERNR INTO PA0001-PERNR

  • FROM PA0001

  • WHERE PERNR IN S_RESPER AND

  • KOSTL IN S_KOSTL.

  • SELECT SINGLE USRID_LONG INTO PA0105-USRID_LONG

  • FROM PA0105

  • WHERE PERNR = PA0001-PERNR AND

  • SUBTY = '0010' AND

  • BEGDA LE SY-DATUM AND

  • ENDDA GE SY-DATUM.

  • IF SY-SUBRC = 0.

  • LT_RECLIST-RECEIVER = PA0105-USRID_LONG.

  • LT_RECLIST-REC_TYPE = 'U'.

  • APPEND LT_RECLIST.

  • ENDIF.

  • ENDSELECT.

  • ENDIF.

  • send mail with attachment

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = LV_DOCUMENT_DATA

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = LT_OBJPACK

OBJECT_HEADER = LT_OBJHEAD

CONTENTS_BIN = IT_ATTACHMENT

CONTENTS_TXT = LT_OBJTXT

RECEIVERS = LT_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.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Many many happy returns of the day '.

LOOP AT LT_RECLIST.

IF LT_RECLIST-RETRN_CODE = 0.

WRITE '...sent successfully!!!'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

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.

REFRESH:LT_RECLIST.

CLEAR:MI_RQIDENT,LV_SPOOL_DESC,MC_VALID,

IT_ATTACHMENT_LONG,IT_ATTACHMENT,LV_DOCUMENT_DATA,MSTR_PRINT_PARMS,

LE_DOC_CHNG,LV_DOCUMENT_DATA,V_EMAIL,V_CELL,V_EXT.

REFRESH:LT_PDF,IT_ATTACHMENT_LONG,IT_ATTACHMENT,

MAIL_BODY,LT_OBJTXT,LT_OBJPACK,IT_ATTACHMENT,LT_OBJPACK,LT_RECLIST,

LT_OBJHEAD,IT_ATTACHMENT,LT_OBJTXT.

ENDIF.

ENDIF.

ENDIF.

  • ENDIF.

ENDLOOP.

Pls check ...

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