cancel
Showing results for 
Search instead for 
Did you mean: 

Corrupt file attachment when sending sapscript form by mail

Former Member
0 Kudos

i have requirment to send sapscript through mail but when open my attachment it is giving file is corrupted.let me know where i am wrong

i am specifying the code here

CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     format                      = 'PDF'
*     MAX_LINEWIDTH               = 132
*     ARCHIVE_INDEX               = ' '
*     COPYNUMBER                  = 0
*     ASCII_BIDI_VIS2LOG          = ' '
*     PDF_DELETE_OTFTAB           = ' '
*     PDF_USERNAME                = ' '
   IMPORTING
     bin_filesize                = binfilesize
*     BIN_FILE                    =
    TABLES
      otf                         = datab[]
      lines                       = pdftab[]
   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.

  REFRESH it_pdf[].

  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
    EXPORTING
      line_width_dst              = '255'
    TABLES
      content_in                  = pdftab[]
      content_out                 = it_pdf[]
    EXCEPTIONS
      err_line_width_src_too_long = 1
      err_line_width_dst_too_long = 2
      err_conv_failed             = 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.
  ELSE.
    "Subject of the mail.
    w_document_data-obj_name  = 'MAIL_TO_HEAD'.
    w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

    "Body of the mail
    w_body_msg = 'This is body of mail msg.'.
    APPEND w_body_msg TO i_body_msg.
    CLEAR  w_body_msg.

    "Write Packing List for Body
    DESCRIBE TABLE i_body_msg LINES g_tab_lines.
    w_packing_list-head_start = 1.
    w_packing_list-head_num   = 0.
    w_packing_list-body_start = 1.
    w_packing_list-body_num   = g_tab_lines.
    w_packing_list-doc_type   = 'RAW'.
    APPEND w_packing_list TO i_packing_list.
    CLEAR  w_packing_list.

    "Write Packing List for Attachment
    w_packing_list-transf_bin = 'X'.
    w_packing_list-head_start = 1.
    w_packing_list-head_num   = 0.
    w_packing_list-body_start = 1.
    DESCRIBE TABLE it_pdf LINES w_packing_list-body_num.
    w_packing_list-doc_type   = 'PDF'.
    w_packing_list-obj_descr  = 'PDF Attachment'.
    w_packing_list-obj_name   = 'PDF_ATTACHMENT'.
    w_packing_list-doc_size   = w_packing_list-body_num * 255.
    APPEND w_packing_list TO i_packing_list.
    CLEAR  w_packing_list.

    "Fill the document data and get size of attachment
    w_document_data-obj_langu  = sy-langu.
    READ TABLE i_body_msg INTO w_body_msg INDEX g_tab_lines.
    w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_body_msg ).

    "Receivers List.
    w_receivers-rec_type   = 'U'."Internet address
    w_receivers-receiver   = p_mail.
    w_receivers-com_type   = 'INT'.
    w_receivers-notif_del  = 'X'.
    w_receivers-notif_ndel = 'X'.
    APPEND w_receivers TO i_receivers .
    CLEAR:w_receivers.

    "Function module to send mail to Recipients
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = w_document_data
        put_in_outbox              = 'X'
        commit_work                = 'X'
      IMPORTING
        sent_to_all                = g_sent_to_all
      TABLES
        packing_list               = i_packing_list
        contents_bin               = it_pdf
        contents_txt               = i_body_msg
        receivers                  = i_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 <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    else.
      MESSAGE 'Mail Successfully Sent' type 'S'.
    ENDIF.

Edited by: sam_ins123524 on Oct 8, 2010 9:31 AM

Edited by: sam_ins123524 on Oct 8, 2010 9:33 AM

Moderator message: subject corrected for you, please use a more descriptive one next time, also use code tags.

Edited by: Thomas Zloch on Oct 8, 2010 10:51 AM

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Once you get otf data, Use FM 'SX_OBJECT_CONVERT_OTF_PDF' to convert it to PDF. Then use CONTENT_BIN to send mail.

Refer below code:

* Converting OTF data to single line
  LOOP AT I_OTF INTO WA_OTF.
    CONCATENATE WA_OTF-TDPRINTCOM WA_OTF-TDPRINTPAR INTO WA_PDF.
    MOVE WA_PDF TO WA_CONTENT_TXT.
    APPEND WA_CONTENT_TXT TO I_CONTENT_TXT.
    CLEAR: WA_CONTENT_TXT.
  ENDLOOP.

* Converting to PDF Format
  CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
    EXPORTING
      FORMAT_SRC      = C_OTF
      FORMAT_DST      = C_PDF
      DEVTYPE         = C_PRINTER
    CHANGING
      TRANSFER_BIN    = WA_TRANSFER_BIN
      CONTENT_TXT     = I_CONTENT_TXT
      CONTENT_BIN     = I_CONTENT_BIN
      OBJHEAD         = WA_OBJHEAD
      LEN             = V_LEN_IN.

*- Send mail
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA                    = L_WA_DOCUMENT_DATA
      TABLES
        OBJECT_CONTENT                   = I_CONTENT_BIN
        RECEIVERS                        = L_I_RECEIVERS. 

aidan_black
Active Contributor
0 Kudos

Hi,

I see you do not use the BIN_FILE parameter when calling CONVERT_OTF so therefore the PDF data is returned via internal table LINES. There can be problems with this in a Unicode system.

Can you try using parameter BIN_FILE when calling CONVERT_OTF so the PDF data is returned as type XSTRING and use the the example BCS_EXAMPLE_8 of SAP Note 1324547 to handle the PDF data returned?

Regards,

Aidan