Skip to Content

Email: PDF FIle is damaged

We are emailing a smartform to multiple recipients. The list of recipients is determined dynamically.

The objective is to send a single email with multiplie recipients with the form output as a PDF attachment.

SAP connect is fully configured.

I can generate the email with attachment, however, the pdf file is corrupt and will not open.

Any assistance is appreciated.

I am passing the OTF output of the form to FM "CONVERT_OTF" as shown. "l_t_job_output-otfdata" contains the OTF data.

call function 'CONVERT_OTF'

exporting

format = 'PDF'

max_linewidth = 134

importing

bin_filesize = pdf_bytecount

tables

otf = l_t_job_output-otfdata

lines = objbin

exceptions

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

others = 4.

if sy-subrc <> 0.

  • NUM1 = SY-SUBRC.

  • SX_TRACE_MSG C_SWTMI_SX_CONV 'SX_OBJECT_CONVERT_OTF_PDF'

  • 'E' 032 FORMAT_SRC FORMAT_DST 'CONVERT_OTF' NUM1.

  • MESSAGE E834 RAISING ERR_CONV_FAILED.

endif.

Next the email is being prepared.

  • Create Message Body

  • Title and Description

docdata-obj_name = 'TEST_ALI'.

docdata-obj_descr = 'Test including PDF Attachment'.

  • Main Text

objtxt = 'Test Document.'.

append objtxt.

objtxt = 'You will find an PDFL attachment in this message.'.

append objtxt.

objtxt = 'Have a nice day.'.

append objtxt.

  • Write Packing List (Main)

describe table objtxt lines tab_lines.

read table objtxt index tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).

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.

  • Create Message Attachment

  • Write Packing List (Attachment)

att_type = 'PDF'.

describe table objbin lines tab_lines.

read table objbin index tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'Attached Document'.

append objpack.

  • Create receiver list

reclist-receiver = 'toocanad@yahoo.com.

reclist-rec_type = 'U'.

append reclist.

reclist-receiver = sy-uname.

reclist-rec_type = 'B'.

append reclist.

  • Send Message

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = 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

.

if sy-subrc <> 0.

message id 'SO' type 'S' number '023'

with docdata-obj_name.

endif.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 11:21 AM

    Hi ,

    We had a similar problem.

    A little more processing is reqd to process OBJBIN before you can use it.

    DATA HOTFDATA LIKE ITCOO OCCURS 0 WITH HEADER LINE.

    DATA WA_SOLI TYPE SOLI.

    DATA WA_SOLIX TYPE SOLIX.

    DATA LT_SOLIX LIKE SOLIX OCCURS 0 WITH HEADER LINE.

    DATA OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

    DATA DOC_SIZE(12) TYPE C.

    DATA LD_BINFILE TYPE XSTRING.

    DATA HTLINE LIKE TLINE OCCURS 1 WITH HEADER LINE.

    DATA: I TYPE I, N TYPE I.

    FIELD-SYMBOLS: <PTR_HEX> TYPE SOLIX.

    • Prepare Content

    REFRESH : HOTFDATA, LT_SOLIX, OBJBIN.

    LOOP AT L_TJOB_OUTPUT_INFO-OTFDATA INTO HOTFDATA.

    APPEND HOTFDATA.

    ENDLOOP.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    • MAX_LINEWIDTH = 132

    IMPORTING

    BIN_FILESIZE = DOC_SIZE

    BIN_FILE = LD_BINFILE

    TABLES

    OTF = HOTFDATA

    LINES = HTLINE

    EXCEPTIONS

    ERR_MAX_LINEWIDTH = 1

    ERR_FORMAT = 2

    ERR_CONV_NOT_POSSIBLE = 3

    OTHERS = 4.

    I = 0.

    N = XSTRLEN( LD_BINFILE ).

    WHILE I < N.

    LT_SOLIX-LINE = LD_BINFILE+I.

    APPEND LT_SOLIX.

    I = I + 255.

    ENDWHILE.

    LOOP AT LT_SOLIX INTO WA_SOLIX.

    CLEAR WA_SOLI.

    ASSIGN WA_SOLI TO <PTR_HEX> CASTING.

    MOVE WA_SOLIX TO <PTR_HEX>.

    APPEND WA_SOLI TO OBJBIN.

    ENDLOOP.

    Now use OBJBIN. Also see that you populate Objpack correctly .

    DESCRIBE TABLE OBJBIN LINES TAB_LINES.

    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 = 'ATTACHMENT'.

    OBJPACK-OBJ_DESCR = ''Attached Document'.

    OBJPACK-DOC_SIZE = TAB_LINES * 255.

    Cheers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 11:50 AM

    ..........deleted..........

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 07:22 PM

    Hi

    I would appreciate if someone could clarify this error that i am getting when i run the sample code discussed in this thread.

    Here is the code that i wrote.

    • Prepare Content

    REFRESH : i_otf, LT_SOLIX, i_OBJBIN.

    LOOP AT w_return-OTFDATA INTO i_otf.

    APPEND i_otf.

    ENDLOOP.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    format = 'PDF'

    • max_linewidth = 132

    IMPORTING

    bin_filesize = doc_size

    BIN_FILE = LD_BINFILE

    TABLES

    otf = i_otf

    lines = i_tline

    EXCEPTIONS

    err_max_linewidth = 1

    err_format = 2

    err_conv_not_possible = 3

    OTHERS = 4.

    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 = 0.

    N = XSTRLEN( LD_BINFILE ).

    WHILE I < N.

    LT_SOLIX-LINE = LD_BINFILE+I.

    APPEND LT_SOLIX.

    I = I + 255.

    ENDWHILE.

    LOOP AT LT_SOLIX INTO WA_SOLIX.

    CLEAR WA_SOLI.

    ASSIGN WA_SOLI TO <PTR_HEX> CASTING.

    MOVE WA_SOLIX TO <PTR_HEX>.

    APPEND WA_SOLI TO i_OBJBIN.

    ENDLOOP.

    DESCRIBE TABLE i_OBJBIN LINES v_lines_bin.

    i_OBJPACK-TRANSF_BIN = 'X'.

    i_OBJPACK-HEAD_START = 1.

    i_OBJPACK-HEAD_NUM = 1.

    i_OBJPACK-BODY_START = 1.

    i_OBJPACK-BODY_NUM = v_lines_bin.

    i_OBJPACK-DOC_TYPE = 'PDF'.

    i_OBJPACK-OBJ_NAME = 'ATTACHMENT'.

    i_OBJPACK-OBJ_DESCR = 'Attached Document'.

    i_OBJPACK-DOC_SIZE = v_lines_bin * 255.

    • Create receiver list

    i_reclist-receiver = 'saoeone@yahoo.com'.

    i_reclist-rec_type = 'U'.

    append i_reclist.

    i_reclist-receiver = sy-uname.

    i_reclist-rec_type = 'B'.

    append i_reclist.

    • Create Message Body

    • Title and Description

    w_doc_chng-obj_name = 'TEST_ALI'.

    w_doc_chng-obj_descr = 'Test including PDF Attachment'.

    • Main Text

    i_objtxt = 'Test Document.'.

    append i_objtxt.

    i_objtxt = 'You will find an PDFL attachment in this message.'.

    append i_objtxt.

    i_objtxt = 'Have a nice day.'.

    append i_objtxt.

    • * Write Packing List (Main)

    • describe table objtxt lines tab_lines.

    • read table objtxt index tab_lines.

    • docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).

    • 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.

    • Send Message

    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

    document_data = w_doc_chng

    put_in_outbox = 'X'

    commit_work = 'X' "used from rel. 6.10

    • IMPORTING

    • SENT_TO_ALL =

    • NEW_OBJECT_ID =

    tables

    packing_list = i_objpack

    *object_header = w_objhead

    contents_bin = i_objbin

    contents_txt = i_objtxt

    • CONTENTS_HEX = objhex

    • OBJECT_PARA =

    • OBJECT_PARB =

    receivers = i_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.

    i am not getting any output. No new outgoing messages are received in SCOT.

    I tried debugging and saw that I_OBJBIN was empty.

    Before making the changes that were discussed in this thread, pdf attachments were being emailed, but i was getting an error while opening them.

    Any help in this regard would be highly appreciated.

    Regards

    Maninder Sawhney

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.