cancel
Showing results for 
Search instead for 
Did you mean: 

Error to Send PDF file using mail

Former Member
0 Kudos

Hi all,

I create a report that send an mail with 2 different pdf attach.

I have a problem because one pdf attach is 663 KB and when I read it in mail it can not open the file and give me this error :

"Error opening PDF file --> There was an error opening this document.the file is damaged and could not be repareid "

I send the same mail with another PDF file (64,2 KB) and all it's work correct.

This files are in my application server, and this is the code that I use to read and send :

data: gt_table TYPE TABLE OF solix,

gs_table LIKE LINE OF gt_table.

open dataset wa for input in binary mode.

if sy-subrc eq 0.

do.

read dataset wa into gs_table LENGTH alen.

ctr = ctr + alen.

if sy-subrc ne 0.

exit.

endif.

append gs_table to gt_table.

enddo.

endif.

close dataset wa.

TRY.

  • (1) crea Oggetto

l_send_request = cl_bcs=>create_persistent( ).

  • (2) E-Mail - Crea Oggetto e Body del messaggio

.

.

.

  • (5) bcs attachment

l_attachment_size = ctr."tab_lines * 255.

CALL METHOD l_doc->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = l_attachment_subj

i_attachment_size = l_attachment_size

i_att_content_hex = gt_table."xsolix[].

CALL METHOD l_send_request->set_document( l_doc ).

CALL METHOD l_send_request->set_priority

EXPORTING

i_priority = '1'.

CALL METHOD l_send_request->set_send_immediately( 'X' ).

.

.

I find this link but the problem are not resolve :

Can anyone help me to understand where is the problem ?

thanks a lot

Barbara

Accepted Solutions (0)

Answers (1)

Answers (1)

aidan_black
Active Contributor
0 Kudos

Hi,

Before the code above, I guess you use function module CONVERT_OTF to convert spool data to PDF.

In your application, during the call to function module CONVERT_OTF, do do you use the BIN_FILE parameter? If not the PDF data is returned via internal table LINES. There can be problems with this. PDF data can be destroyed. e.g bu translate commands. See SAP note #1320163.

As a solution, use the parameter BIN_FILE when calling CONVERT_OTF so the PDF data is returned as type XSTRING and then use the example program BCS_EXAMPLE_8 of SAP note 1324547 to handle the PDF data returned and send as a email.

Regards,

Aidan

Former Member
0 Kudos

Hi Aidan,

Sorry but I don't have a spool. I read a file in my application server and then send it.

I verify that if th PDF file is 63 KB I don't have problem, but if I send a file of 600 KB I can not send it.

I also verify that if I use the TC CG3Z to update the file in application, this not work, but if I create a custom report usinf FM GUI_UPLOAD I can send the mail with attach.

Unfortunately my system administrator must insert the file using tc CG3Z and not using custom report.

thanks

barbara

Former Member
0 Kudos

Hi,

I find the way to resolve this topic, thanking a collegue.

The problem is the way that I use to read the file.

If I read the file in the following way, the problem concerning the size are bypassing.

DATA : gs_table LIKE LINE OF gt_table.

DATA: l_xstring TYPE xstring.

DATA : alen TYPE i.

OPEN DATASET p_p_file FOR INPUT IN BINARY MODE.

IF sy-subrc EQ 0.

  • DO.

READ DATASET p_p_file INTO l_xstring.

  • p_bin_filesize = p_bin_filesize + alen.

  • IF sy-subrc NE 0.

  • EXIT.

  • ENDIF.

*

  • APPEND gs_table TO gt_table.

  • ENDDO.

ENDIF.

CLOSE DATASET p_p_file.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = l_xstring

  • APPEND_TO_TABLE = ' '

IMPORTING

output_length = p_bin_filesize

TABLES

binary_tab = gt_table .

thanks a lot

barbara