Skip to Content
avatar image
Former Member

Getting PDF error while opening attached PO & mail not delivering to external mail IDs

Hi Experts,

I am getting 2 Errors while sending PO to vendor's external email IDs:

1) PDF error (see the attachment) as "Error opening document, file is damaged" while opening the attached PO in mail.

2) Mail is not getting delivered to external Email IDs such as Yahoo, Gmail, Hotmail etc. When I checked in SOST its showing error as "Not a valid recipient address". However, mail successfully delivered to our local company domain's Outlook folder.

Please reply with your useful suggestions.

Thanks.

PDF Error.JPG (21.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jan 14, 2015 at 07:16 AM

    Hi Alis,

    For 1st Error : Please check below Code

    PERFORM convert_spool_to_pdf.

    PERFORM process_email.

    FORM convert_spool_to_pdf.

       DATA: lines TYPE i,

              size TYPE i,

              doc LIKE TABLE OF docs,

              otf TYPE TABLE OF itcoo WITH HEADER LINE,

              w_char(100) TYPE c,

               w_tabix LIKE sy-tabix.

    *  This change is to append a static line into the PDF file

    *  DESCRIBE TABLE t_buffer LINES lines.

    *  lines =  lines - 1.

    *  LOOP AT t_buffer FROM  lines TO  lines.

    *    t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

    *    INSERT t_buffer.

    *    t_buffer-line = 'MT0085001408'.

    *    INSERT t_buffer.

    *    t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

    *    INSERT t_buffer.

    *    t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

    *    INSERT t_buffer.

    *  ENDLOOP.

       w_char = 'Page No : 1 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 2 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 3 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 4 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 5 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 6 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 7 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 8 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 9 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

       w_char = 'Page No : 10 of'.

       SEARCH t_buffer FOR w_char.

       w_tabix = sy-tabix.

       IF sy-tabix NE 0.

         w_tabix = w_tabix + 2.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           t_buffer-line = 'FCTIMES   130  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

           t_buffer-line = 'MT0085001408'.

           INSERT t_buffer.

           t_buffer-line = 'ST0653999 This is a computer generated printout for information purpose'.

           INSERT t_buffer.

           t_buffer-line = 'ST0070777only. This is not an invoice and is just an intimation.'.

           INSERT t_buffer.

           t_buffer-line = 'FCTIMES   100  00075XSF201SF011110000050E X'.

           INSERT t_buffer.

         ENDLOOP.

       ENDIF.

    *To remove 'VAT TAX INVOICE' text form the Invioce PDF

       DO 10 TIMES.

         w_char = 'VAT TAX INVOICE'.

         SEARCH t_buffer FOR w_char.

         w_tabix = sy-tabix.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           REPLACE w_char IN t_buffer WITH ' '.

           MODIFY t_buffer.

         ENDLOOP.

       ENDDO.

    *  To remove 'CASH MEMORANDUM/BILL OF SALE'  text form the Invioce PDF

       DO 10 TIMES.

         w_char = 'CASH MEMORANDUM/BILL OF SALE'.

         SEARCH t_buffer FOR w_char.

         w_tabix = sy-tabix.

         LOOP AT t_buffer FROM w_tabix TO w_tabix. "To read the text in the file

           REPLACE w_char IN t_buffer WITH ' '.

           MODIFY t_buffer.

         ENDLOOP.

       ENDDO.

    *Moving the Text data to OTF format

       LOOP AT t_buffer.

         CLEAR otf.

         otf = t_buffer.

         APPEND otf.

       ENDLOOP.

    *Converting OTF file to PDF file

       CALL FUNCTION 'CONVERT_OTF_2_PDF'

         EXPORTING

           use_otf_mc_cmd         = 'X'

         IMPORTING

           bin_filesize           = size

         TABLES

           otf                    = otf

           doctab_archive         = doc

           lines                  = it_pdf_output

         EXCEPTIONS

           err_conv_not_possible  = 1

           err_otf_mc_noendmarker = 2

           OTHERS                 = 3.

       IF sy-subrc NE 0.

         WRITE sy-subrc.

       ENDIF.

       CHECK sy-subrc = 0.

    * Transfer the 132-long strings to 255-long strings

       LOOP AT it_pdf_output.

         TRANSLATE it_pdf_output USING ' ~'.

         CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

       ENDLOOP.

       TRANSLATE gd_buffer USING '~ '.

       REFRESH it_mess_att[].

       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.

    ENDFORM.                    "convert_spool_to_pdf


    *---------------------------------------------------------------------*

    *       FORM process_email                                            *

    *---------------------------------------------------------------------*

    FORM process_email.

       DESCRIBE TABLE it_mess_att LINES gd_recsize.

       CHECK gd_recsize > 0.

       PERFORM send_email USING g_emailid.

    ENDFORM.                    "process_email


    ---------------------------------------------------------------------*

    *       FORM send_email                                               *

    *---------------------------------------------------------------------*

    *  -->  p_email                                                       *

    *---------------------------------------------------------------------*

    FORM send_email USING p_email TYPE any.

       CHECK NOT ( g_emailid IS INITIAL ).

       REFRESH it_mess_bod.

    * Email Subject  and email body matter

       gd_subject         = 'Dispatches Intimation'.

       gd_attachment_desc = g_invno.

       it_mess_bod        = 'Dear Customer, '.

       APPEND it_mess_bod.

       it_mess_bod        = '  '.

       APPEND it_mess_bod.

       it_mess_bod        = 'We have made dispatches as per the attached PDF document.'.

       APPEND it_mess_bod.

       it_mess_bod        = '  '.

       APPEND it_mess_bod.

       it_mess_bod        = 'This is only for information and not to be construed as an Invoice.'.

       APPEND it_mess_bod.

       it_mess_bod        = '  '.

       APPEND it_mess_bod.

       it_mess_bod        = '  '.

       APPEND it_mess_bod.

       it_mess_bod        = 'This is a Computer-generated email. Please do not reply to this message.'.

       APPEND it_mess_bod.

       it_mess_bod        = '  '.

       APPEND it_mess_bod.

    * If no sender specified - default blank

       IF g_sender EQ space.

         gd_sender_type  = space.

       ELSE.

         gd_sender_type  = 'INT'.

       ENDIF.

    * Send file by email as .pdf

       PERFORM send_file_as_email_attachment

                                    TABLES it_mess_bod

                                           it_mess_att

                                     USING g_emailid

                                           'Dispatches Intimation'

                                           'PDF'

                                           gd_attachment_name

                                           gd_attachment_desc

                                           g_sender

                                           gd_sender_type

                                  CHANGING gd_error

                                           gd_reciever.

    ENDFORM.                    "send_email



    *&---------------------------------------------------------------------*

    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT

    *&---------------------------------------------------------------------*

    *       Send email

    *----------------------------------------------------------------------*

    FORM send_file_as_email_attachment TABLES it_message

                                               it_attach

                                         USING p_email TYPE any

                                               p_mtitle TYPE any

                                               p_format TYPE any

                                               p_filename TYPE any

                                               p_attdescription TYPE any

                                               p_sender_address TYPE any

                                               p_sender_addres_type TYPE any

                                      CHANGING p_error TYPE any

                                               p_reciever TYPE any.

       DATA: ld_error    TYPE sy-subrc,

             ld_mtitle LIKE sodocchgi1-obj_descr,

             ld_email LIKE  somlreci1-receiver,

             ld_format TYPE  so_obj_tp ,

             ld_attdescription TYPE  so_obj_nam ,

             ld_attfilename TYPE  so_obj_des ,

             ld_sender_address LIKE  soextreci1-receiver,

             ld_sender_address_type LIKE  soextreci1-adr_typ,

             ld_receiver LIKE  sy-subrc.

       DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

               t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

               t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

               t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

               w_cnt TYPE i,

               w_sent_all(1) TYPE c,

               w_doc_data LIKE sodocchgi1.

       ld_email   = p_email.

       ld_mtitle = p_mtitle.

       ld_format              = p_format.

       ld_attdescription      = p_attdescription.

       ld_attfilename         = p_filename.

       ld_sender_address      = p_sender_address.

       ld_sender_address_type = p_sender_addres_type.

    * Fill the document data.

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

       w_doc_data-sensitivty = 'F'.

    * Fill the document data and get size of attachment

       CLEAR w_doc_data.

       READ TABLE it_attach INDEX w_cnt.

       w_doc_data-doc_size =

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

       w_doc_data-obj_langu  = sy-langu.

       w_doc_data-obj_name   = 'SAPRPT'.

       w_doc_data-obj_descr  = ld_mtitle.

       w_doc_data-sensitivty = 'F'.

       CLEAR t_attachment.

       REFRESH t_attachment.

       t_attachment[] = it_attach[].

    * Describe the body of the message

       CLEAR t_packing_list.

       REFRESH t_packing_list.

       t_packing_list-transf_bin = space.

       t_packing_list-head_start = 1.

       t_packing_list-head_num = 0.

       t_packing_list-body_start = 1.

       DESCRIBE TABLE it_message LINES t_packing_list-body_num.

       t_packing_list-doc_type = 'RAW'.

       APPEND t_packing_list.

    * Create attachment notification

       t_packing_list-transf_bin = 'X'.

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

       t_packing_list-obj_descr  =  ld_attdescription.

       t_packing_list-obj_name   =  ld_attfilename.

       t_packing_list-doc_size   =  t_packing_list-body_num * 255.

       APPEND t_packing_list.

    * Add the recipients email address

       CLEAR t_receivers.

       REFRESH t_receivers.

       t_receivers-receiver = ld_email.

       t_receivers-rec_type = 'U'.

       t_receivers-com_type = 'INT'.

       t_receivers-notif_del = 'X'.

       t_receivers-notif_ndel = 'X'.

       APPEND t_receivers.

    *FM to send the email

       CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

         EXPORTING

           document_data              = w_doc_data

           put_in_outbox              = 'X'

           sender_address             = ld_sender_address

           sender_address_type        = ld_sender_address_type

           commit_work                = 'X'

         IMPORTING

           sent_to_all                = w_sent_all

         TABLES

           packing_list               = t_packing_list

           contents_bin               = t_attachment

           contents_txt               = it_message

           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.

    * Populate zerror return code

       ld_error = sy-subrc.

    * Populate zreceiver return code

       LOOP AT t_receivers.

         ld_receiver = t_receivers-retrn_code.

       ENDLOOP.

    ENDFORM.                    "send_file_as_email_attachment

    For 2nd Error :  You need to contact with basis team and do some necessary setting in SCOT

    BR

    Harsh

    Add comment
    10|10000 characters needed characters exceeded

    • Which SAP form you are using here. Is it Smartform or Adobeform?

      Are you able to see print preview.

      Please check if there is any text of languages which are not supported. You may need to install that language.

      Also check if attachment is too big.

      Warm Regards,

      Shyam Agrawal

  • avatar image
    Former Member
    Jan 14, 2015 at 06:57 AM

    For issue 2, it is because external mail are not configured. Request your basis team to setup external email address in SCOT transaction.

    For issue 1, let us how do you send email? are you using class or FM?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I am attaching Smartform as PDF in mail after converting from OTF to PDF by FM 'CONVERT_OTF_2_PDF'. Translated the content using '~'. I am getting numerical value '3117' in doc_size.