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

Issue With PDF Conversion in Email Attachment

Former Member
0 Likes
2,167

Hi All,

There is a custom develop program to send the payslip as an email in PDF Format.It was working fine but after SAP Upgrade there is a problem with the attachment. When we try to open the PDF it is giving the Error as 'There was an error open this file .TheFile is damaged and could not be repaired'. It is working fine when we download the payslip to our local system in pdf format.There is no error in converting to PDF. I am using the Following code to convert and send the payslip as an attachment.

Moderator message - Please respect the 5,000 character maximum when posting. Post only the relevant portions of code

Please advise

Regards,

Surya

Edited by: Rob Burbank on Feb 24, 2011 2:42 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,893

Hello,

What was the nature of the upgrade? What version of SAP are you running and is it Unicode?

Regards,

Michael

15 REPLIES 15
Read only

Former Member
0 Likes
1,894

Hello,

What was the nature of the upgrade? What version of SAP are you running and is it Unicode?

Regards,

Michael

Read only

0 Likes
1,893

Hello,

We are using ECC6.0 and it is a unicode system.It was working fine with the function module SO_NEW_DOCUMENT_SEND_API1 but after upgrade it is not working.

Please Advise.

Read only

0 Likes
1,893

I can vaguely remember a similar error back when we upgraded but that was a few years ago. What was your previous version of SAP? Was it Unicode and did it use SAPCONNECT for email?

It's odd that it works okay if downloaded but not if emailed. Try looking in txn: SCOT > Settings > Device types for format conversion and then look at the device type in txn: SPAD. Maybe the emails use a non-unicode PDF converter or one that doesn't support the languages and fonts you are using.

Read only

0 Likes
1,893

Hi,

You will have to changes your code. Instead of using the FM use this code to send email either to external email id or sap inbox.

  • -------- create persistent send request ------------------------

gc_send_request = cl_bcs=>create_persistent( ).

  • -------- create and set document -------------------------------

pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).

gc_document = cl_document_bcs=>create_document(

i_type = 'PDF'

i_hex = pdf_content

i_length = pdf_size

i_subject = gv_SO_OBJ_DES ). "#EC NOTEXT

gc_send_request->set_document( gc_document ).

      • This is done to change the sender address as given in the selection

      • screen

if p_sender is not INITIAL.

gv_sender_name = p_sender.

  • Get sender object

  • DATA: l_sender TYPE ad_smtpadr.

  • DATA: sender TYPE REF TO if_sender_bcs.

l_sender = gv_sender_name.

sender = cl_cam_address_bcs=>create_internet_address( l_sender ).

  • Add sender

CALL METHOD gc_send_request->set_sender

EXPORTING

i_sender = sender.

endif.

      • This is done to change the sender address as given in the selection

      • screen

clear : gv_subject_mail.

gv_subject_mail = gv_subject.

CALL METHOD GC_SEND_REQUEST->SET_MESSAGE_SUBJECT

EXPORTING

IP_SUBJECT = gv_subject_mail.

  • --------- create and set note ----------------------------------

CALL METHOD gc_send_request->set_note( t_note ).

  • --------- add recipient (e-mail address) -----------------------

loop at t_dli_entries into wa_dli_entries.

lv_index = sy-tabix.

      • Begin of changes HCHA330 2/22/2011

if wa_dli_entries-MEMBER_TYP = 'A'.

try.

  • create recipient object

gv_mailto = wa_dli_entries-MEMBER_ADR.

  • add document object to send request

gc_recipient = cl_cam_address_bcs=>create_internet_address(

gv_mailto ).

  • add recipient object to send request

gc_send_request->add_recipient( gc_recipient ).

  • ---------- send document ---------------------------------------

  • ------------ exception handling ----------------------------------

*

catch cx_bcs into gc_bcs_exception.

message i865(so) with gc_bcs_exception->error_type.

endtry.

sent_to_all = gc_send_request->send( i_with_error_screen = 'X').

commit work.

for sap inbox

data : l_uname TYPE salrtdrcpt.

  • l_sender1 TYPE REF TO if_sender_bcs.

data : lv_uname type sy-uname.

data : l_file type SO_OBJ_DES.

  • DATA: recipient TYPE REF TO if_recipient_bcs.

      • This is for SAP INBOX

gc_send_request = cl_bcs=>create_persistent( ).

l_file = gv_subject.

  • Creating Document

gc_document = cl_document_bcs=>create_document(

i_type = 'PDF'

i_hex = pdf_content

i_length = pdf_size

i_subject = l_file ).

CALL METHOD gc_send_request->set_document( gc_document ).

l_uname = sy-uname.

sender = cl_sapuser_bcs=>create( l_uname ).

CALL METHOD gc_send_request->set_sender

EXPORTING

i_sender = sender.

  • --------- add recipient (sap user) -----------------------

clear : lv_uname.

lv_uname = wa_dli_entries-MEMBER_NAM.

  • sender = cl_sapuser_bcs=>create( sy-uname ).

sender = cl_sapuser_bcs=>create( lv_uname ).

CALL METHOD gc_send_request->set_sender

EXPORTING

i_sender = sender.

  • recipient = cl_sapuser_bcs=>create( sy-uname ).

gc_recipient = cl_sapuser_bcs=>create( lv_uname ).

  • add recipient with its respective attributes to send request

CALL METHOD gc_send_request->add_recipient

EXPORTING

i_recipient = gc_recipient

i_express = 'X'.

sent_to_all = gc_send_request->send( i_with_error_screen = 'X').

commit work.

Data Declaration

data : gc_send_request type ref to cl_bcs.

data : gc_document type ref to cl_document_bcs.

data : gc_recipient type ref to if_recipient_bcs.

data : gc_bcs_exception type ref to cx_bcs.

data : sent_to_all type os_boolean.

data : gv_SO_OBJ_DES type SO_OBJ_DES.

data : gv_mailto type ad_smtpadr.

data : t_dli_entries type table of SODLIENTI1.

data : wa_dli_entries like LINE OF t_dli_entries.

data : gv_sender_name type string.

DATA : t_note TYPE bcsy_text.

data : wa_note type SOLI.

data : gv_subject_mail type string.

DATA: l_sender TYPE ad_smtpadr.

DATA: sender TYPE REF TO if_sender_bcs.

Read only

0 Likes
1,893

Hi,

How can i know which device type we are using while sending Email.i thik Basis Guy can tell me about it.

Mustafa

Read only

0 Likes
1,893

Hi Hiten,

Below is the code that i was using to send the email.Please tell me where i have to do the changes.

wa_document_data-obj_name = 'Payslip'.

  • wa_document_data-expiry_dat = sy-datum + 10.

wa_document_data-obj_descr = 'Monthly Payslip'.

wa_document_data-sensitivty = 'P'.

wa_document_data-obj_prio = '1'.

DATA: v_lines TYPE i.

DESCRIBE TABLE it_lines255 LINES v_lines.

i_packing_list-head_start = 1.

i_packing_list-head_num = 0.

i_packing_list-body_start = 1.

i_packing_list-body_num = v_lines.

i_packing_list-doc_type = 'RAW'.

APPEND i_packing_list.

i_packing_list-transf_bin = 'X'.

i_packing_list-head_start = 1.

i_packing_list-head_num = 1."0.

i_packing_list-body_start = 1.

i_packing_list-body_num = v_lines."1.

i_packing_list-doc_type = 'PDF'.

i_packing_list-obj_descr = v_filename.

i_packing_list-doc_size = v_lines * 255.

APPEND i_packing_list.

it_contents_txt-line = 'Please find your monthly payslip attached with this email.'.

APPEND it_contents_txt.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

  • i_objpack-body_num = v_lines_txt.

i_objpack-doc_type = 'RAW'.

APPEND i_objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_document_data

put_in_outbox = 'X'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = i_packing_list

  • OBJECT_HEADER = i_objpack

contents_bin = it_lines255

contents_txt = it_contents_txt

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = it_receivers"i_receiver_list

Read only

0 Likes
1,893

Hi,

I am sending the payslip to the MS outlook Exhange.

Read only

0 Likes
1,893

Your Basis team should understand about device types. If you upgraded from 4.6 to 6 there were some significant changes in how email is handled and several new PDF device types were introduced for Unicode support.

Read only

0 Likes
1,893

can you tell, what are you converting the PDF from? is it a smartform or a list or what?

Read only

0 Likes
1,893

Hi,

It is a smartform to send the payslip as an attachment to the employees.I am using the the FM Convert_OTF_2_PDF to convert the form to PDF and it is converting fine as i am able to download the payslip to my local PC.But,I am not able to view the attachment in the email.It is giving the error as 'The File is damaged and could not be repaired'.

Read only

0 Likes
1,893

Hi, Please try the following code:

1.- Get Smartform OTF Data


  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZFORM'
    IMPORTING
      fm_name            = lv_fname
    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.
  ELSE.

*     Control Parameters.
      ls_control_par-getotf    = 'X'.
      ls_control_par-no_dialog = 'X'.
      ls_control_par-preview   = ''.

      CALL FUNCTION lv_fname
        EXPORTING
          control_parameters = ls_control_par
        IMPORTING
          job_output_info    = p_job_info
        TABLES
          t_output           = lt_output[]
        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.

    ENDIF.
  ENDIF.

2.- Attach OTF Data and send by email.


  DATA: lv_size         TYPE i,
        lt_pdf          TYPE TABLE OF tline,
        lt_pdf_aux      TYPE TABLE OF solisti1,
        lv_bin          TYPE xstring,
        lv_send_request TYPE REF TO cl_bcs,
        lt_text         TYPE soli_tab,
        lv_document     TYPE REF TO cl_document_bcs,
        lv_result       TYPE os_boolean,
        lt_attach       TYPE solix_tab,
        lv_line         TYPE string,
        lv_email_add    TYPE adr6-smtp_addr,
        lwa_recipient   TYPE REF TO cl_cam_address_bcs,
        lv_string       TYPE sood-objdes,
        lv_sub          TYPE string,
        lt_otf          TYPE TABLE OF itcoo,
        lv_email_sender TYPE adr6-smtp_addr,
        lwa_sender      TYPE REF TO cl_send_request_bcs,
        lv_title        TYPE so_obj_des,
        lv_bcs_exception TYPE REF TO cx_bcs,
        lv_sender       TYPE REF TO if_sender_bcs,
        lt_att_table    TYPE soli_tab,
        lv_att_header   LIKE LINE OF lt_att_table,
        ls_address      TYPE bapiaddr3,
        lv_userid       TYPE bapibname-bapibname,
        lt_return       TYPE TABLE OF bapiret2,
        lv_low          TYPE tvarv_val.

  CONSTANTS: lc_pdf(3) TYPE c VALUE 'PDF',
             lc_raw(3) TYPE c VALUE 'RAW',
             lc_x TYPE c VALUE 'X'.

  DEFINE error_handling.
    message id 'VN' type 'E' number '073'.
  END-OF-DEFINITION.

    lt_otf[] = p_job_info-otfdata[].

    CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format                = lc_pdf
        max_linewidth         = 132
      IMPORTING
        bin_filesize          = lv_size
        bin_file              = lv_bin
      TABLES
        otf                   = lt_otf[]
        lines                 = lt_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.
    ELSE.

      CALL FUNCTION 'QCE1_CONVERT'
        TABLES
          t_source_tab = lt_pdf
          t_target_tab = lt_pdf_aux.

      TRY.
          CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
            EXPORTING
              buffer     = lv_bin
            TABLES
              binary_tab = lt_attach[].

***       Mail Contents and Title
          lv_line = 'Mail Content'.
          APPEND lv_line TO lt_text.

          lv_title = 'Mail Title'.

          lv_send_request = cl_bcs=>create_persistent( ).
          lwa_sender = lv_send_request->send_request.

          lv_document = cl_document_bcs=>create_document(
                          i_type    = lc_raw
                          i_text    = lt_text
                          i_length  = '100'
                          i_subject = lv_title ).

***       Mail Subject
          lv_sub = 'Mail subject'.

          CALL METHOD lv_send_request->set_message_subject
            EXPORTING
              ip_subject = lv_sub.

            lv_email_sender = 'sender address'.

          TRY.
            lv_sender ?=
            cl_cam_address_bcs=>create_internet_address( lv_email_sender ).

            CALL METHOD lwa_sender->setu_sender( lv_sender ).
          ENDTRY.
          CALL METHOD lv_send_request->set_document( lv_document ).

***       Target E-mail Address
          lv_email_add = 'target address'.

          lwa_recipient = cl_cam_address_bcs=>create_internet_address( lv_email_add ).

          CALL METHOD lv_send_request->add_recipient
            EXPORTING
              i_recipient = lwa_recipient
              i_express   = ' '.

Continues below.

Edited by: Ernesto Caballero on Feb 28, 2011 11:14 PM

Read only

0 Likes
1,893

I am sorry for the previous one. It print previewed ok, but post it as a string.



***       PDF - File Name
          CONCATENATE lv_sub '.' lc_pdf INTO lv_att_header.
          APPEND lv_att_header TO lt_att_table.

          CALL METHOD lv_document->add_attachment
            EXPORTING
              i_attachment_type    = lc_pdf
              i_attachment_subject = lv_string
              i_att_content_hex    = lt_attach[]
              i_attachment_header  = lt_att_table[].

          CALL METHOD lv_send_request->set_send_immediately( lc_x ).

          CALL METHOD lv_send_request->send(
          EXPORTING
            i_with_error_screen = lc_x
          RECEIVING
            result = lv_result ).

        CATCH cx_bcs INTO lv_bcs_exception.
          error_handling.

      ENDTRY.
      COMMIT WORK.
    ENDIF.

  ENDIF.

Edited by: Ernesto Caballero on Feb 28, 2011 11:15 PM

Read only

0 Likes
1,893

Hi,

I have used the following code but i am not getting the PDF as an attachment.i am able to receive the email but the PDF attachment is not coming

i_otf[] = i_job_output_info-otfdata[].

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

BIN_FILE = lv_bin

TABLES

OTF = i_otf

LINES = i_lines

.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = i_lines

t_target_tab = lt_pdf_aux[].

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = lv_bin

TABLES

binary_tab = lt_attach[].

lv_line = 'Mail Content'.

APPEND lv_line TO lt_text.

lv_title = 'Mail Title'.

lv_send_request = cl_bcs=>create_persistent( ).

lwa_sender = lv_send_request->send_request.

lv_document = cl_document_bcs=>create_document(

i_type = lc_raw

i_text = lt_text

i_length = '100'

i_subject = lv_title ).

CONCATENATE lv_sub '.' lc_pdf INTO lv_att_header.

APPEND lv_att_header TO lt_att_table.

CALL METHOD lv_document->add_attachment

EXPORTING

i_attachment_type = lc_pdf

i_attachment_subject = 'Monhtly Payslip'

i_att_content_hex = lt_attach[]

i_attachment_header = lt_att_table[].

CALL METHOD lv_send_request->set_document( lv_document ).

      • Mail Subject

lv_sub = 'Mail subject'.

CALL METHOD lv_send_request->set_message_subject

EXPORTING

ip_subject = lv_sub.

lv_email_sender = 'xyzzzzz'.

lv_sender ?= cl_cam_address_bcs=>create_internet_address( lv_email_sender ).

CALL METHOD lwa_sender->setu_sender( lv_sender ).

      • Target E-mail Address

lv_email_add = 'abcdzzzcom'.

lwa_recipient = cl_cam_address_bcs=>create_internet_address( lv_email_add ).

CALL METHOD lv_send_request->add_recipient

EXPORTING

i_recipient = lwa_recipient

i_express = ' '.

CALL METHOD lv_send_request->set_send_immediately( lc_x ).

CALL METHOD lv_send_request->send(

EXPORTING

i_with_error_screen = lc_x

RECEIVING

result = lv_result ).

COMMIT WORK.

Read only

0 Likes
1,893

Hi,

Are you receiving any data from QCE1_CONVERT FM?

Put a breakpoint in that call and check if table lt_pdf_aux[] contains data.

Regards,

Read only

Former Member
0 Likes
1,893

Hi,

Please try this

data rq type tsp01.

data bin_size type i.

data dummy type table of rspoattr.

data rqident type tsp01-rqident.

data pdf_size type so_obj_len.

rqident = gv_spool_nr.

  • ------------ get attributes of spool request ---------------------

call function 'RSPO_GET_ATTRIBUTES_SPOOLJOB'

EXPORTING

rqident = rqident

IMPORTING

rq = rq

TABLES

attributes = dummy

EXCEPTIONS

no_such_job = 1

others = 2.

if sy-subrc <> 0.

message e126(po) with rqident.

endif.

  • --- convert spool request into PDF, dependent on document type ---

if rq-rqdoctype = 'OTF' or rq-rqdoctype = 'SMART'.

call function 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = rqident

no_dialog = 'X'

pdf_destination = 'X'

no_background = 'X'

IMPORTING

pdf_bytecount = bin_size

bin_file = pdf_xstring

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

if sy-subrc <> 0.

message e712(po) with sy-subrc 'CONVERT_OTFSPOOLJOB_2_PDF'.

endif.

elseif rq-rqdoctype = 'LIST'.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = rqident

no_dialog = 'X'

pdf_destination = 'X'

no_background = 'X'

IMPORTING

pdf_bytecount = bin_size

bin_file = pdf_xstring

EXCEPTIONS

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

if sy-subrc <> 0.

WRITE: / 'Error in function CONVERT_ABAPSPOOLJOB_2_PDF'(f09).

MOVE text-f09 TO t_msg.

APPEND t_msg.

gv_failure = 'X'.

EXIT.

endif.

else.

message e789(po) with rq-rqdoctype.

endif.