<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic email PDF in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/email-pdf/m-p/981315#M72034</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to email an PDF file to an internet address.&lt;/P&gt;&lt;P&gt;Upon opening the PDF document I get the following error&lt;/P&gt;&lt;P&gt;"There was an error opening this document. The file is damaged and could not be repaired."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When downloading the same document to my desktop with GUI_DOWNLOAD it looks fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my sample code (more or less SAP's BCS_EXAMPLE_5).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vibeke&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

REPORT ztest.

* This example shows how to send
*   - a simple text provided in an internal table of text lines
*   - and an attached MS word document provided in internal table
*   - to some internet email address.
*
* All activities done via facade CL_BCS!

DATA: send_request       TYPE REF TO cl_bcs.
DATA: text               TYPE bcsy_text.
DATA: binary_content     TYPE solix_tab.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA: sent_to_all        TYPE os_boolean.

DATA: l_spool LIKE tsp01-rqident VALUE 6509.
DATA: it_pdf LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: w_buffer TYPE string.

DATA: BEGIN OF it_buffer OCCURS 0.
DATA: line(255) TYPE c.
DATA: END OF it_buffer.

DATA: xx_pdf TYPE soli_tab.

START-OF-SELECTION.

  CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = l_spool
    TABLES
      pdf                      = it_pdf
    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.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename = 'C:ProfilerlpwDesktopfile.pdf'
      filetype = 'BIN'
    TABLES
      data_tab = it_pdf.

  LOOP AT it_pdf.
    TRANSLATE it_pdf USING '~'.
    CONCATENATE w_buffer it_pdf INTO w_buffer.
  ENDLOOP.

  TRANSLATE w_buffer USING '~'.

  DO.
    it_buffer = w_buffer.
    APPEND it_buffer.
    SHIFT w_buffer LEFT BY 255 PLACES .
    IF w_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.

  xx_pdf[] = it_buffer[].
  binary_content[] = it_buffer[].

  PERFORM main.


*---------------------------------------------------------------------*
*       FORM main                                                     *
*---------------------------------------------------------------------*
FORM main.

  TRY.
*     -------- create persistent send request ------------------------
      send_request = cl_bcs=&amp;gt;create_persistent( ).

*     -------- create and set document with attachment ---------------
*     create document from internal table with text
      APPEND 'Hello world!' TO text.
      document = cl_document_bcs=&amp;gt;create_document(
                      i_type    = 'RAW'
                      i_text    = text
                      i_length  = '12'
                      i_subject = 'test created by Vibeke' ).

*     add attachment to document
*     BCS expects document content here e.g. from document upload
*     binary_content = ...
      CALL METHOD document-&amp;gt;add_attachment
        EXPORTING
          i_attachment_type    = 'PDF'
          i_attachment_subject = 'My PDF attachment'
          i_att_content_text   = xx_pdf.
*          i_att_content_hex    = binary_content.

*     add document to send request
      CALL METHOD send_request-&amp;gt;set_document( document ).

*     --------- set sender -------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.

      sender = cl_sapuser_bcs=&amp;gt;create( sy-uname ).
      CALL METHOD send_request-&amp;gt;set_sender
        EXPORTING
          i_sender = sender.

*     --------- add recipient (e-mail address) -----------------------
*     create recipient - please replace e-mail address !!!
      recipient = cl_cam_address_bcs=&amp;gt;create_internet_address(
                              'xxxxx@xxxx.dk' ).

*     add recipient with its respective attributes to send request
      CALL METHOD send_request-&amp;gt;add_recipient
        EXPORTING
          i_recipient = recipient
          i_express   = 'X'.

*     ---------- send document ---------------------------------------
      CALL METHOD send_request-&amp;gt;send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = sent_to_all ).
      IF sent_to_all = 'X'.
        WRITE text-003.
      ENDIF.

      COMMIT WORK.


* -----------------------------------------------------------
* *                     exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
    CATCH cx_bcs INTO bcs_exception.
      WRITE: 'Fehler aufgetreten.'(001).
      WRITE: 'Fehlertyp:'(002), bcs_exception-&amp;gt;error_type.
      EXIT.

  ENDTRY.

ENDFORM.                    "main
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Vibeke Skov Baird&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Aug 2005 13:01:20 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-08-15T13:01:20Z</dc:date>
    <item>
      <title>email PDF</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/email-pdf/m-p/981315#M72034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to email an PDF file to an internet address.&lt;/P&gt;&lt;P&gt;Upon opening the PDF document I get the following error&lt;/P&gt;&lt;P&gt;"There was an error opening this document. The file is damaged and could not be repaired."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When downloading the same document to my desktop with GUI_DOWNLOAD it looks fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my sample code (more or less SAP's BCS_EXAMPLE_5).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vibeke&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

REPORT ztest.

* This example shows how to send
*   - a simple text provided in an internal table of text lines
*   - and an attached MS word document provided in internal table
*   - to some internet email address.
*
* All activities done via facade CL_BCS!

DATA: send_request       TYPE REF TO cl_bcs.
DATA: text               TYPE bcsy_text.
DATA: binary_content     TYPE solix_tab.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA: sent_to_all        TYPE os_boolean.

DATA: l_spool LIKE tsp01-rqident VALUE 6509.
DATA: it_pdf LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: w_buffer TYPE string.

DATA: BEGIN OF it_buffer OCCURS 0.
DATA: line(255) TYPE c.
DATA: END OF it_buffer.

DATA: xx_pdf TYPE soli_tab.

START-OF-SELECTION.

  CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = l_spool
    TABLES
      pdf                      = it_pdf
    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.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename = 'C:ProfilerlpwDesktopfile.pdf'
      filetype = 'BIN'
    TABLES
      data_tab = it_pdf.

  LOOP AT it_pdf.
    TRANSLATE it_pdf USING '~'.
    CONCATENATE w_buffer it_pdf INTO w_buffer.
  ENDLOOP.

  TRANSLATE w_buffer USING '~'.

  DO.
    it_buffer = w_buffer.
    APPEND it_buffer.
    SHIFT w_buffer LEFT BY 255 PLACES .
    IF w_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.

  xx_pdf[] = it_buffer[].
  binary_content[] = it_buffer[].

  PERFORM main.


*---------------------------------------------------------------------*
*       FORM main                                                     *
*---------------------------------------------------------------------*
FORM main.

  TRY.
*     -------- create persistent send request ------------------------
      send_request = cl_bcs=&amp;gt;create_persistent( ).

*     -------- create and set document with attachment ---------------
*     create document from internal table with text
      APPEND 'Hello world!' TO text.
      document = cl_document_bcs=&amp;gt;create_document(
                      i_type    = 'RAW'
                      i_text    = text
                      i_length  = '12'
                      i_subject = 'test created by Vibeke' ).

*     add attachment to document
*     BCS expects document content here e.g. from document upload
*     binary_content = ...
      CALL METHOD document-&amp;gt;add_attachment
        EXPORTING
          i_attachment_type    = 'PDF'
          i_attachment_subject = 'My PDF attachment'
          i_att_content_text   = xx_pdf.
*          i_att_content_hex    = binary_content.

*     add document to send request
      CALL METHOD send_request-&amp;gt;set_document( document ).

*     --------- set sender -------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.

      sender = cl_sapuser_bcs=&amp;gt;create( sy-uname ).
      CALL METHOD send_request-&amp;gt;set_sender
        EXPORTING
          i_sender = sender.

*     --------- add recipient (e-mail address) -----------------------
*     create recipient - please replace e-mail address !!!
      recipient = cl_cam_address_bcs=&amp;gt;create_internet_address(
                              'xxxxx@xxxx.dk' ).

*     add recipient with its respective attributes to send request
      CALL METHOD send_request-&amp;gt;add_recipient
        EXPORTING
          i_recipient = recipient
          i_express   = 'X'.

*     ---------- send document ---------------------------------------
      CALL METHOD send_request-&amp;gt;send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = sent_to_all ).
      IF sent_to_all = 'X'.
        WRITE text-003.
      ENDIF.

      COMMIT WORK.


* -----------------------------------------------------------
* *                     exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
    CATCH cx_bcs INTO bcs_exception.
      WRITE: 'Fehler aufgetreten.'(001).
      WRITE: 'Fehlertyp:'(002), bcs_exception-&amp;gt;error_type.
      EXIT.

  ENDTRY.

ENDFORM.                    "main
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Vibeke Skov Baird&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2005 13:01:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/email-pdf/m-p/981315#M72034</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-15T13:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: email PDF</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/email-pdf/m-p/981316#M72035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Vibeke,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi. The way you are creating the xx_pdf itab is flawed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The below code works&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    refresh tab_pdf.&lt;/P&gt;&lt;P&gt;    loop at lt_pdf into lw_pdf_lines.&lt;/P&gt;&lt;P&gt;      move lw_pdf_lines-tdformat to lw_charline.&lt;/P&gt;&lt;P&gt;      move lw_pdf_lines-tdline(132) to lw_charline+2(132).&lt;/P&gt;&lt;P&gt;      append lw_charline to tab_pdf.&lt;/P&gt;&lt;P&gt;    endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        perform tab_to_255 tables tab_pdf&lt;/P&gt;&lt;P&gt;                                  tab_soli.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        call method document-&amp;gt;add_attachment&lt;/P&gt;&lt;P&gt;          exporting&lt;/P&gt;&lt;P&gt;            i_attachment_type    = 'PDF'&lt;/P&gt;&lt;P&gt;            i_attachment_subject = l_subject&lt;/P&gt;&lt;P&gt;        "    i_attachment_size    = l_att_size&lt;/P&gt;&lt;P&gt;            i_att_content_text   = tab_soli[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form tab_to_255 tables tab_pdf&lt;/P&gt;&lt;P&gt;                       tab_255.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  data: l_pdf           type gtypes_pdf,&lt;/P&gt;&lt;P&gt;      l_attachment_long type string,&lt;/P&gt;&lt;P&gt;      l_attachment      type soli.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  check not ( tab_pdf[] is initial ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Convert pdf itab to 255 line itab.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  data :lv_counter  type i.&lt;/P&gt;&lt;P&gt;  data :lv_from     type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  loop at tab_pdf into l_pdf.&lt;/P&gt;&lt;P&gt;    translate  l_pdf using ' ~' .&lt;/P&gt;&lt;P&gt;    concatenate l_attachment_long l_pdf into l_attachment_long.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;  translate  l_attachment_long using '~ ' .&lt;/P&gt;&lt;P&gt;  clear : lv_counter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  do.&lt;/P&gt;&lt;P&gt;    lv_counter = strlen( l_attachment_long ).&lt;/P&gt;&lt;P&gt;    if lv_counter ge 255.&lt;/P&gt;&lt;P&gt;      l_attachment = l_attachment_long(255).&lt;/P&gt;&lt;P&gt;      append l_attachment to tab_255.&lt;/P&gt;&lt;P&gt;      shift l_attachment_long by 255 places.&lt;/P&gt;&lt;P&gt;    else.&lt;/P&gt;&lt;P&gt;      l_attachment = l_attachment_long(lv_counter).&lt;/P&gt;&lt;P&gt;      append l_attachment to tab_255.&lt;/P&gt;&lt;P&gt;      exit.&lt;/P&gt;&lt;P&gt;    endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  enddo.&lt;/P&gt;&lt;P&gt;endform.                                                    "tab_to_255&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Apr 2007 15:01:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/email-pdf/m-p/981316#M72035</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-19T15:01:37Z</dc:date>
    </item>
  </channel>
</rss>

