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

PDF attachment Email error

Former Member
0 Likes
1,626

Hello,

Similar type of questions have been raised many times, but this is with respect to Unicode system.

I am sending PDF attachment in mail and below is my sample code. I am reading PDF file from application server and sending in mail.

Please note that error is for some files not all files.

I downloaded that file in presentation server, its opening correctly in PDF, but in mail when checked in SOST I am getting below error:

"There was error opening this document. The file is damaged or could not be repaired"

OPEN DATASET  FILE_NAME FOR INPUT IN BINARY MODE .

           IF sy-subrc EQ 0.

             DO.

               ASSIGN wa_bin TO <hex_container> CASTING.

               READ DATASET FILE_NAME INTO <hex_container>.

               IF sy-subrc NE 0.

                 EXIT.

               ENDIF.

               APPEND wa_bin TO lv_content_out.

             ENDDO.

             CLOSE DATASET FILE_NAME.

           ENDIF.

*   add text attachment to document

           ztype = 'PDF'.

           document->add_attachment( i_attachment_type    = ztype

                                     i_attachment_subject = zattname

                                     i_att_content_hex   = lv_content_out ).

As this works perfect for some files, i wonder is this anything to do with file or system which is Unicode.

Please help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
883

Hi gaurav,

              Please check the below code

DATA: file(50) TYPE c ."VALUE './test.doc'.

    data : wa_bin type xstring,

            lv_ext TYPE SOODK-OBJTP,

            gv_file_size TYPE zfile-zsize.

DATA: document           TYPE REF TO cl_document_bcs.

open dataset file for input in binary mode.

 

    READ DATASET file INTO wa_bin actual length gv_file_size.

    binary_content = cl_document_bcs=>xstring_to_solix( wa_bin ).

 

document = cl_document_bcs=>create_document(

                        i_type    = 'RAW'

                        i_text    = text

                        i_length  = '1000'

                        i_subject = lv_subject )."'attachment' ).

 

CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'

            EXPORTING

              FILENAME        = file

*     UPPERCASE       = 'X'

           IMPORTING

             EXTENSION       = lv_ext.

  CALL METHOD document->add_attachment

              EXPORTING

                i_attachment_type    = lv_ext

                i_attachment_subject = file "'My attachment'

                i_att_content_hex    = binary_content.

May be it will solve your problem ,If you get any issues still please get back to me .

Thanks,

Kumar

2 REPLIES 2
Read only

Former Member
0 Likes
884

Hi gaurav,

              Please check the below code

DATA: file(50) TYPE c ."VALUE './test.doc'.

    data : wa_bin type xstring,

            lv_ext TYPE SOODK-OBJTP,

            gv_file_size TYPE zfile-zsize.

DATA: document           TYPE REF TO cl_document_bcs.

open dataset file for input in binary mode.

 

    READ DATASET file INTO wa_bin actual length gv_file_size.

    binary_content = cl_document_bcs=>xstring_to_solix( wa_bin ).

 

document = cl_document_bcs=>create_document(

                        i_type    = 'RAW'

                        i_text    = text

                        i_length  = '1000'

                        i_subject = lv_subject )."'attachment' ).

 

CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'

            EXPORTING

              FILENAME        = file

*     UPPERCASE       = 'X'

           IMPORTING

             EXTENSION       = lv_ext.

  CALL METHOD document->add_attachment

              EXPORTING

                i_attachment_type    = lv_ext

                i_attachment_subject = file "'My attachment'

                i_att_content_hex    = binary_content.

May be it will solve your problem ,If you get any issues still please get back to me .

Thanks,

Kumar

Read only

0 Likes
883

Thanks a lot. It has solved my problem.

I guess, Problem was with conversion to hex string conversion for some particular characters.

method you have given, solved my problem.