Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error while Opening PDF attachment from Mail

Former Member
0 Likes
379

Hi,

We two Output Types created ZNEU and ZAUF. Two Smartforms are created for the same Output Types. The Issue now is, When ZNEU triggers and send a mail the document is properly decoded and gets opened but for ZAUF it doesn't. It says File damaged.

This is the code we have used for sending mail.


CONSTANTS:
          co_pdf(3) TYPE c VALUE 'PDF',
          co_raw(3) TYPE c VALUE 'RAW'.

  DATA:
        it_objbin TYPE STANDARD TABLE OF solisti1,
        wa_objbin TYPE solisti1.

  DATA:
         lv_filesize TYPE i.

  DATA:
        it_lines TYPE STANDARD TABLE OF tline.

  DATA:
        wa_mail_body TYPE solisti1,
        wa_receipients TYPE somlreci1.
  DATA:
       document           TYPE REF TO cl_document_bcs,
       content            TYPE solix_tab,
       wa_content         TYPE solix,
       send_request       TYPE REF TO cl_bcs,
       sender             TYPE REF TO if_sender_bcs,
       recipient          TYPE REF TO if_recipient_bcs,
       requested_status   TYPE REF TO bcs_rqst,
       status_mail        TYPE bcs_stml,
       bcs_exception      TYPE REF TO cx_bcs,
       lv_rec             TYPE adr6-smtp_addr.

  DATA:
         wa_attachx TYPE solix,
         l_pdf_len TYPE i,
         l_con_len TYPE i,
         l_pdf_pos TYPE i,
         l_con_pos TYPE i.
  FIELD-SYMBOLS: <fs_con> TYPE x.

  CLASS cl_cam_address_bcs     DEFINITION LOAD.
  CLASS cl_abap_char_utilities DEFINITION LOAD.

* Get the PDF version of the OTF
  CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     format                      = 'PDF'
   IMPORTING
     bin_filesize                = lv_filesize
    TABLES
      otf                         = job_output_info-otfdata
      lines                       = it_lines
   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.

* Convert the PDF format to the table type required for the attachment.
  CALL FUNCTION 'QCE1_CONVERT'
    TABLES
      t_source_tab         = it_lines
      t_target_tab         = it_objbin
    EXCEPTIONS
      convert_not_possible = 1
      OTHERS               = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Convert the data which is in text to binary
  l_con_pos = 0.

  DESCRIBE FIELD wa_objbin LENGTH l_pdf_len IN BYTE MODE.
  DESCRIBE FIELD wa_attachx LENGTH l_con_len IN BYTE MODE.

  LOOP AT it_objbin INTO wa_objbin.
    ASSIGN wa_objbin TO <fs_con> CASTING.
    CHECK sy-subrc EQ 0.
    DO l_pdf_len TIMES.
      l_pdf_pos = sy-index - 1.
      IF l_con_pos = l_con_len.
        APPEND wa_attachx TO content.
        FREE wa_attachx.
        l_con_pos = 0.
      ENDIF.
      MOVE <fs_con>+l_pdf_pos(1) TO wa_attachx-line+l_con_pos(1).
      ADD 1 TO l_con_pos.
    ENDDO.
  ENDLOOP.

  IF l_con_pos > 0.
    APPEND wa_attachx TO content.
  ENDIF.

  TRY .
*     -------- create persistent send request ------------------------
      send_request = cl_bcs=>create_persistent( ).

*     -------- create and set document with attachment ---------------
*     create document from internal table with text
      document = cl_document_bcs=>create_document(
                    i_type    = 'RAW'
                    i_text    = mail_body_tab
                    i_subject = email_subject ).
*     add attachment to document
      CALL METHOD document->add_attachment
        EXPORTING
          i_attachment_type    = 'PDF'
          i_attachment_subject = attachment_name
          i_att_content_hex    = content.

*     add document to send request
      CALL METHOD send_request->set_document( document ).

*    Set sender
      sender = cl_cam_address_bcs=>create_internet_address( sender_id ).
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.

*     Receipients
      LOOP AT receipients_tab INTO wa_receipients .
        lv_rec = wa_receipients-receiver.
        recipient = cl_cam_address_bcs=>create_internet_address( lv_rec ).
*       Add recipient with its respective attributes to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient = recipient.
      ENDLOOP.

* Set that you don't need a Return Status E-mail
      status_mail = 'N'.
      CALL METHOD send_request->set_status_attributes
        EXPORTING
          i_requested_status = 'N'
          i_status_mail      = status_mail.

* set send immediately flag
      send_request->set_send_immediately( 'X' ).

* Send document
      CALL METHOD send_request->send( ).

*      COMMIT WORK.


    CATCH cx_bcs INTO bcs_exception.
      RAISE EXCEPTION bcs_exception.

 ENDTRY.

This is in a Class which is been used in the print program for both the Output Types.

Can somebody throw light upon this.

Note: I tried using

....

but it is not working properly.

Thanks,

Prashanth

Edited by: Prashanth KR on Jan 5, 2010 6:20 AM

2 REPLIES 2
Read only

Former Member
0 Likes
330

Hi,

Please paste the part of code where you are getting error.

And if you are not clear about where the error is, try searching sdn or google with the error message that you are getting as this issue has been discussed many times earlier.

Check this link.

Hope it helps.

Regards,

Raj

Read only

0 Likes
330

Hi Raj,

Thanks for your reply. I did search the Form fo rnearly an hour and then posted this. Anyways i have fixed the issue my self. the Problem was with the Output Options.

Thanks,

Prashanth