Skip to Content

corrupted pdf attachment. while retrieving from mail...?

hi all,

I am sending my smart form as a pdf attachment to be sent to mail of particular person email-id .

The mail with pdf attachment was successfully sent

but i am facing problem while retrieving the pdf from mail attachment ....

the pdf file could not be opened , it gets corrupted....... ?

I am not finding any proper reason for this altough i doubted that there may be any error in file size of pdf attachment , So i changed the size still when i sent again it is received in corrupted format, could not be opened.

I have also checked the tcode 'SOST' (sap connect transmission request) there also my pdf file is corrupted when i choose display document

could u plzz suggest some helpful points....

I am using the following code...........

data: v_language type sflangu value 'E',

v_e_devtype type rspoptype.

DATA : p_sender TYPE somlreci1-receiver VALUE 'an_email@address.com'.

data : w_sent_all(1) TYPE c.

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

ld_attfilename TYPE so_obj_des.

data: it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.

data : t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

IT_MESS TYPE STRING,

w_doc_data LIKE sodocchgi1,

W_CNT TYPE I.

DATA: tb_pdf255 TYPE so_text255 OCCURS 0,

gd_subject LIKE sodocchgi1-obj_descr.

DATA :T_BUFFER TYPE STRING.

data: t_otfdata type ssfcrescl.

data: t_otf type itcoo occurs 0 with header line,

GD_BUFFER TYPE STRING,

it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF MESSTAB OCCURS 0,

MESS TYPE STRING,

flag TYPE c,

END OF MESSTAB.

DATA : T_MESSTAB LIKE TABLE OF MESSTAB WITH HEADER LINE.

DATA : NUMBER(4) TYPE C VALUE 1,

w_bin_filesize type i.

call function 'CONVERT_OTF'

exporting

format = 'PDF'

max_linewidth = 132

* ARCHIVE_INDEX = ' '

importing

bin_filesize = w_bin_filesize

tables

otf = t_otf

lines = lines

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.

loop at LINES.

TRANSLATE LINES USING ' ~'.

CONCATENATE gd_buffer LINES 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.

** w_doc_data-doc_size = 1.

*** Populate the subject/generic message attributes

** w_doc_data-obj_langu = sy-langu.

** w_doc_data-obj_name = 'SAPRPT'.

** w_doc_data-obj_descr = 'Payslip' .

** w_doc_data-sensitivty = 'F'.

* Fill the document data and get size of attachment

CLEAR w_doc_data.

** describe TABLE IT_MESS_ATT LINES W_CNT.

READ TABLE IT_MESS_ATT INDEX w_cnt.

* DESCRIBE TABLE it_mess_att LINES SY-TFILL.

w_doc_data-doc_size =

** SY-TFILL * 255 + 62.

( w_cnt - 1 ) * 255 + STRLEN( IT_MESS_ATT ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = 'Payslip'.

** CONCATENATE 'Invoice' WA_VBRK2-VBELN INTO W_DOC_DATA-OBJ_DESCR SEPARATED BY SPACE. "Subject text

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = IT_MESS_ATT[].

it_mess_bod = 'Hi,'. "text in mail body

APPEND it_mess_bod.

IT_MESS_BOD = ' '.

append it_mess_bod.

IT_MESS_BOD = 'Please find the attached payslip.'.

append it_mess_bod.

IT_MESS_BOD = ' '.

append it_mess_bod.

IT_MESS_BOD = 'Regards,'.

append it_mess_bod.

IT_MESS_BOD = 'ABC_LTD'.

append it_mess_bod.

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = SPACE. "mail body parameters

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_mess_BOD LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

t_packing_list-transf_bin = 'X'. "attachment info

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = 'PDF'.

** CONCATENATE 'Invoice' WA_VBRK2-VBELN INTO t_packing_list-obj_descr SEPARATED BY SPACE.

t_packing_list-obj_descr = 'Payslip attachment' .

t_packing_list-obj_name = 'Payslip mail'.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = another_email@address'. "reciever's info

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_DATA

PUT_IN_OUTBOX = 'X'

SENDER_ADDRESS = p_sender

SENDER_ADDRESS_TYPE = 'INT'

COMMIT_WORK = 'X'

IMPORTING

SENT_TO_ALL = w_sent_all

TABLES

PACKING_LIST = T_PACKING_LIST

CONTENTS_BIN = t_attachment

CONTENTS_TXT = IT_MESS_BOD

RECEIVERS = t_receivers

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

write :/ 'Mail sent successfuly'.

ELSE.

ENDIF.

SUBMIT rsconn01 WITH mode = '*'

AND RETURN.

ENDIF.

CLEAR: WA_FINAL, WA_WPBP, WA_FIXEDCOMP, WA_DEDUCTIBLES,wa_rgdir,in_rgdir[], IT_MESS_BOD.

refresh : it_mess_bod.

ENDLOOP.

ENDIF.

ENDIF.

ENDLOOP.

ELSE.

MESSAGE 'No Data Exists for the given selection' TYPE 'I'.

ENDIF.

ENDFORM. "FETCH_DATA

Message was edited by: Matthew Billingham - removed real email addresses

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Jun 29, 2013 at 04:17 AM

    Hi Deepak,

    Try like this

    *--------------------------------------------------------------------*
    * V A R I A B L E S *
    *--------------------------------------------------------------------*

    data : w_frm type rs38l_fnam, " Smart form Function Module
    w_binsize type i, " Binary Size
    w_str type string. " String Variable

    *--------------------------------------------------------------------*
    * I N T E R N A L T A B L E D E C L A R A T I O N *
    *--------------------------------------------------------------------*

    data : it_final type table of sflight, " Final Table
    it_pdf type table of tline, " Internal Table For PDF Format
    it_cbin type table of solisti1, " Internal Table For Character Binary Format
    it_ctxt type table of solisti1, " Internal Table For Character Text Format
    it_pack type table of sopcklsti1, " Internal Table For Packing Data
    it_rec type table of somlreci1, " Internal Table For Receivers List
    it_mail type table of ymail_id. " Internal Table For Mail ID's

    *--------------------------------------------------------------------*
    * W O R K A R E A D E C L A R A T I O N *
    *--------------------------------------------------------------------*


    data : wa_final type sflight, " Wark Area For Final
    wa_ctrl type ssfctrlop, " Work Area For Control Data
    wa_out type ssfcompop, " Work Area For Out Data
    wa_otf type ssfcrescl, " Work Area For OTF Data
    wa_cbin type solisti1, " Work Area For Character Binary Data
    wa_ctxt type solisti1, " Work Area For Character Text Data
    wa_doc type sodocchgi1, " Work Area For document
    wa_pack type sopcklsti1, " Work Area For Packed Data
    wa_rec type somlreci1, " Work Area For Receiver's Data
    wa_mail type ymail. " Work Area For Mail Id's
    *--------------------------------------------------------------------*
    * F I E L D S Y M B O L S *
    *--------------------------------------------------------------------*

    field-symbols : <f_pdf> type tline. " Field Symbol For PDF Format

    *--------------------------------------------------------------------*
    * S E L E C T I O N S C R E E N *
    *--------------------------------------------------------------------*
    selection-screen : begin of block b1 with frame title text-001.
    parameters : p_date type sy-datum.
    selection-screen : end of block b1.

    *--------------------------------------------------------------------*
    * S T A R T - O F - S E L E C T I O N *
    *--------------------------------------------------------------------*
    start-of-selection.
    select * from sflight into table it_final up to 10 rows.
    end-of-selection.
    call function 'SSF_FUNCTION_MODULE_NAME'
    exporting
    formname = 'YSMARTFORM_NAME'
    importing
    fm_name = w_frm
    exceptions
    no_form = 1
    no_function_module = 2
    others = 3.
    if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.

    wa_ctrl-no_dialog = 'X'. "No Dialog for properties
    wa_ctrl-preview = ' '. "No Preview of printing
    wa_ctrl-getotf = 'X'. "To get in OTF Format
    wa_out-tddest = 'LP01'. "Standard Printer Format

    clear wa_otf.

    call function w_frm
    exporting
    control_parameters = wa_ctrl
    output_options = wa_out
    user_settings = ' '
    importing
    job_output_info = wa_otf
    tables
    it_final = it_final
    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.

    clear : w_binsize,
    it_pdf,
    w_str,
    wa_cbin,
    it_cbin,
    wa_ctxt,
    it_ctxt.

    call function 'CONVERT_OTF'
    exporting
    format = 'PDF'
    max_linewidth = 132
    importing
    bin_filesize = w_binsize
    tables
    otf = wa_otf-otfdata[]
    lines = it_pdf
    exceptions
    err_max_linewidth = 1
    err_format = 2
    err_conv_not_possible = 3
    err_bad_otf = 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.


    loop at it_pdf assigning <f_pdf>.
    concatenate w_str <f_pdf> into w_str.
    endloop.

    do.

    wa_cbin = w_str.
    append wa_cbin to it_cbin.
    clear wa_cbin.
    shift w_str left by 255 places.
    if w_str is initial.
    exit.
    endif.

    enddo.

    concatenate 'Sflight Details'(002) p_date into wa_ctxt separated by space.
    append wa_ctxt to it_ctxt.
    clear wa_ctxt.
    append wa_ctxt to it_ctxt.
    append wa_ctxt to it_ctxt.

    concatenate 'Regards'(003) ' ' into wa_ctxt.
    append wa_ctxt to it_ctxt.
    concatenate 'ABAP Team'(004) ' ' into wa_ctxt.
    append wa_ctxt to it_ctxt.

    wa_doc-obj_name = 'Testing'(005).
    concatenate 'Testing'(006) p_date into wa_doc-obj_descr.

    wa_doc-obj_langu = 'E'.
    wa_doc-sensitivty = 'O'. "Standard
    wa_doc-doc_size = w_binsize.

    wa_pack-obj_name = text-005.
    concatenate 'Testing'(006) p_date into wa_pack-obj_descr.
    wa_pack-transf_bin = space.
    wa_pack-head_start = 1.
    wa_pack-head_num = 1.
    wa_pack-body_start = 1.
    wa_pack-body_num = lines( it_ctxt ).
    wa_pack-doc_type = 'RAW'. "RAW type Data
    append wa_pack to it_pack.

    wa_pack-doc_size = w_binsize.
    wa_pack-transf_bin = 'X'.
    wa_pack-head_start = 1.
    wa_pack-head_num = 1.
    wa_pack-body_start = 1.
    wa_pack-body_num = lines( it_cbin ).
    wa_pack-doc_type = 'PDF'. "PDF Type data
    append wa_pack to it_pack.

    loop at it_mail into wa_mail.
    clear wa_rec.
    wa_rec-rec_type = 'U'. " Specification Of Receipient Type - ( To )
    wa_rec-com_type = 'INT'. " Transmission Method (Fax, Telex, ...) - ( Internet)
    wa_rec-receiver = wa_mail-email.
    append wa_rec to it_rec.
    endloop.

    call function 'SO_DOCUMENT_SEND_API1'
    exporting
    document_data = wa_doc
    put_in_outbox = 'X'
    commit_work = 'X'
    tables
    packing_list = it_pack
    contents_bin = it_cbin
    contents_txt = it_ctxt
    receivers = it_rec
    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 sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    else.
    message 'Mail Sended Successfully'(008) type 'I'.
    endif.

    endif.

    *--------------------------------------------------------------------*
    * E N D - O F - S E L E C T I O N *
    *--------------------------------------------------------------------*

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 27, 2013 at 10:48 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 27, 2013 at 10:50 AM

    Hi Deepak,

    Please check the settings in T.code SCOT

    INT -> SMTP, this opens a dialog-box.

    In that, click on set as shown below.

    It will open another dialog-box.

    In this, check whether the settings are correct. Mainly check the ABAP List is PDF.

    Hope this helps you.

    With Regards,

    Gurulakshmi


    pastedImage_0.png (15.7 kB)
    pastedImage_1.png (13.9 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • I also faced similar issue using 'SO_DOCUMENT_SEND_ATT_API1'. When I removed code for email body, attachment was fine. Also try using cl_bcs class for sending email, rather than using this FM.

      Check SAP example programs: "bcs_example_1" to "bcs_example_7".

  • Posted on Jun 28, 2013 at 11:13 AM

    Hi Deepak

    you don't have to calculate the doc_size, it will be done internal.

    and also the note 1430123 is important to have in the system.

    Best regards

    Jozsef

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 12 at 12:35 PM
    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.