<?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 Re: Issue with Email Attachment (PDF) from SAP Program in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770112#M907189</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Micky,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried testing only the 'converting spool to pdf' part and downloaded the PDF File. And this works perfect. I think there is the issue with the "Email". Can you please let me know if you find any issue with this functionality? I really appreciate your help! Thanks a ton.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Apr 2008 21:23:08 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-04-24T21:23:08Z</dc:date>
    <item>
      <title>Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770106#M907183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I have wrote a program to send an email with a pdf attachment to external id . The program works fine and sends email to the user id. However, when I try to open the PDF file, I am getting an error: &lt;EM&gt;Adobe Reader could not open 'EMAIL TEST.PDF' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody please let me know what is the issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 20:10:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770106#M907183</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T20:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770107#M907184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ofcourse, the pdf file is corrupted so just check whether you are creating the file properly or not(Source internal table..restructuring of the internal table contents line by line). A flimsy reply but just a starting hint..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 20:15:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770107#M907184</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T20:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770108#M907185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Amiya,&lt;/P&gt;&lt;P&gt;I am just converting the spool to pdf. I think the issue is with 'sending of email'. If I post the code, will you be able to figure out the issue? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 20:27:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770108#M907185</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T20:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770109#M907186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had similar problems when sending pdf in mail but I managed to solve it. Well, just post the coding and have SDN'ers have a look.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 20:30:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770109#M907186</guid>
      <dc:creator>Sm1tje</dc:creator>
      <dc:date>2008-04-24T20:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770110#M907187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check for my post in &lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="5197700"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;G@urav.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 20:39:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770110#M907187</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T20:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770111#M907188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's the Program Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT ZVTEST73  no standard page heading
                            line-count 65
                            line-size 165
                            message-id zxx.


*&amp;amp;-- Table declarations
tables: tbtcm,                              "Run-time info on batch job
        tbtcp,                              "Batch job step overview
        tsp01.                              "Spool Requests

*&amp;amp;-- Types
*-- For Spool Requests
types: begin of t_tbtcp.
        include structure tbtcp.
types: end of t_tbtcp.

data: i_tbtcp type standard table of t_tbtcp initial size 0,
      wa_tbtcp type t_tbtcp.


*-- Name of attachment
constants: g_attach_title type so_obj_des value 'TEST'
.

*&amp;amp;-- Variables
*-- Variables for Background Job
data: g_eventid like tbtcm-eventid,         "event ID
      g_eventparm like tbtcm-eventparm,     "event parameter
      g_xpflag like tbtcm-xpgactive,        "flag for ext. prog.
      g_jobcount like tbtcm-jobcount,       "job number
      g_jobname like tbtcm-jobname,         "jobname
      g_stepcount like tbtcm-stepcount,     "step ID number
      print_parms like pri_params,          "print parameters
      valid type c,                         "flag
      g_jobrel like btch0000-char1.         "flag for job release

*-- Variables for Spool
data: g_spoolid like tsp01-rqident,         "Spool id
      g_no_bytes type i,                    "No of bytes
      g_pdf_spoolid like tsp01-rqident.     "PDF spool id

*-- Variables for Email
data: g_attach_name type so_obj_des,        "Description of attachment
      g_sender_type like soextreci1-adr_typ,"Sender type
      w_doc_data like sodocchgi1,           "attachment data
      w_sent_all like sonv-flag,            "Sent to all Flag
      w_cnt type i.


*&amp;amp;-- Ranges


*&amp;amp;-- Internal tables
*-- Memory List
data: i_listobject like abaplist occurs 0 with header line.

*-- Spool List
data: i_listasci(100) type c occurs 0 with  header line.

*-- PDF Internal table
data: i_pdf like tline occurs 100 with header line.
*-- Email Description
data: i_mess_bod like solisti1 occurs 0 with header line.

*-- Packing List
data: i_packing_list like sopcklsti1 occurs 0 with header line.

*-- Attachment Name
data: i_objhead like solisti1 occurs 0 with header line.

*-- Contents of Email
data: i_contents like solisti1 occurs 0 with header line.

*-- Message of Email
data: i_message like solisti1 occurs 0 with header line.

*-- Recievers List
data: i_receivers like somlreci1 occurs 5 with header line.

*----------------------------------------------------------------------*
*  SELECTION-SCREEN DEFINITION
*----------------------------------------------------------------------*

*-- Data selection.
selection-screen begin of block b1 with frame title text-001.
parameters: p_email(42) type c,
            p_bemail(42) type c.
selection-screen end of block b1.
*----------------------------------------------------------------------*
*  AT SELECTION-SCREEN VALIDATIONS
*----------------------------------------------------------------------*
at selection-screen.


*----------------------------------------------------------------------*
*  INITIALIZATION
*----------------------------------------------------------------------*
initialization.


*----------------------------------------------------------------------*
*  START-OF-SELECTION
*----------------------------------------------------------------------*
start-of-selection.

*-- Get the Spool from the List
  perform get_spool_from_list.

*-- convert spool to pdf
  perform convert_spool_to_pdf.

*-- Compress Data
  perform compress_table.

*-- Brief Description with attachment in email
  i_mess_bod = 'This Email is to Notify TEST Calculations'.
  append i_mess_bod.

*-- Set Sender Type
  g_sender_type = 'INT'.

*-- Send Email
  perform send_email
              tables i_mess_bod
               using p_email
                     'Test Calculations'
                     'PDF'
                     g_attach_title
                     g_attach_name
                     g_sender_type.

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  get_spool_from_list
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_spool_from_list.

  g_jobname = 'ZTEST'.

  select * from tbtcp
           into table i_tbtcp
          where jobname  = g_jobname
            and progname = g_jobname
*            and sdldate  = sy-datum
            order by jobname
                     jobcount.

    read table i_tbtcp into wa_tbtcp index 1.
    if sy-subrc = 0.
      g_spoolid = wa_tbtcp-listident.
    endif.


endform.                    "get_spool_from_list
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  convert_spool_to_pdf
*&amp;amp;---------------------------------------------------------------------*
*       convert spool id to pdf
*----------------------------------------------------------------------*
form convert_spool_to_pdf.

  call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
    exporting
      src_spoolid              = g_spoolid
      no_dialog                = ' '
*       dst_device             =
*       pdf_destination        =
    importing
      pdf_bytecount            = g_no_bytes
      pdf_spoolid              = g_pdf_spoolid
*       list_pagecount         =
      btc_jobname              = g_jobname
      btc_jobcount             = g_jobcount
    tables
      pdf                      = i_pdf
    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
      otehrs                   = 12
              .
endform.                    "convert_spool_to_pdf
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  send_email
*&amp;amp;---------------------------------------------------------------------*
*       Send Email
*----------------------------------------------------------------------*
form send_email tables i_mess_bod
                 using f_email
                       f_email_title
                       f_format
                       f_title
                       f_attach_name
                       f_sender_type.

*--  Populate the subject/generic message attributes
  clear w_doc_data.
  read table i_message index w_cnt.
  w_doc_data-obj_name   = 'ZVTEST73'.
  w_doc_data-obj_descr  = f_title .
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-sensitivty = 'F'.
  w_doc_data-doc_size   = ( w_cnt - 1 ) * 255 + strlen( i_message ).

*-- Body of the message
  clear: i_packing_list.
  refresh: i_packing_list.
  i_packing_list-transf_bin = space.
  i_packing_list-head_start   = 1.
  i_packing_list-head_num     = 0.
  i_packing_list-body_start   = 1.
  describe table i_message lines i_packing_list-body_num.
  i_packing_list-doc_type     = 'RAW'.
  i_packing_list-obj_langu    = sy-langu.
  append i_packing_list.

*-- Attachment Details
  i_packing_list-transf_bin = 'X'.
  i_packing_list-head_start   = 1.
  i_packing_list-head_num     = 1.
  i_packing_list-body_start   = 1.
  describe table i_contents lines i_packing_list-body_num.
  i_packing_list-doc_type     = f_format.
  i_packing_list-obj_name     = 'ZVTEST73'.
  i_packing_list-obj_descr    = f_title.
  i_packing_list-obj_langu    = sy-langu.
  i_packing_list-doc_size     = i_packing_list-body_num * 255.
  append i_packing_list.

*-- Object Header
  i_objhead = f_title.
  append i_objhead.

*-- Contents of Attachment
  clear i_contents.
  refresh i_contents.
  i_contents[] = i_pdf[].

*-- Contents of Description Details
  clear i_message.
  i_message[] = i_mess_bod[].

*-- Add recievers to recipients list for email
  clear i_receivers .
  refresh i_receivers.
  i_receivers-receiver = p_email.
  i_receivers-rec_type = 'U'.
  i_receivers-com_type = 'INT'.
  append i_receivers.

  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    exporting
      document_data              = w_doc_data
*     put_in_outbox              = ' '
*     sender_address             =
      sender_address_type        = f_sender_type
      commit_work                = 'X'
*   importing
*     sent_to_all                = w_sent_all
*     new_object_id              =
*     sender_id                  =
    tables
      packing_list               = i_packing_list
      object_header              = i_objhead
      contents_bin               = i_contents
      contents_txt               = i_message
*      contents_hex               =
*      object_para                =
*      object_parb                =
      receivers                  = i_receivers
    exceptions
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      others                     = 8.

endform.                    "send_email&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 20:46:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770111#M907188</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T20:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770112#M907189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Micky,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried testing only the 'converting spool to pdf' part and downloaded the PDF File. And this works perfect. I think there is the issue with the "Email". Can you please let me know if you find any issue with this functionality? I really appreciate your help! Thanks a ton.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 21:23:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770112#M907189</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T21:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770113#M907190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I made a few minor changes to your report and now it's just working fine for me. Changes are highlighted. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. FORM COMPRESS_TABLE was not part of the coding you sent me??? So I commented the PERFORM.&lt;/P&gt;&lt;P&gt;2. The parameter sender_address_type is something I don't have in my SAP NW Version, so left that one out.&lt;/P&gt;&lt;P&gt;3. I added a part for converting i_pdf data.&lt;/P&gt;&lt;P&gt;4. I moved the part of the packing list for the attachment. I moved it down, since in the previous place the table was still empty, so the DESCRIBE was no good.&lt;/P&gt;&lt;P&gt;5. That was just about it, I hope. Formatting still needs to be done since it is kind of messed up in this SDN editor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zzz_test3  NO STANDARD PAGE HEADING
                            LINE-COUNT 65
                            LINE-SIZE 165
                            MESSAGE-ID zxx.


*&amp;amp;-- Table declarations
TABLES: tbtcm,                              "Run-time info on batch job
        tbtcp,                              "Batch job step overview
        tsp01.                              "Spool Requests

*&amp;amp;-- Types
*-- For Spool Requests
TYPES: BEGIN OF t_tbtcp.
        INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.

DATA: i_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
      wa_tbtcp TYPE t_tbtcp.


*-- Name of attachment
CONSTANTS: g_attach_title TYPE so_obj_des VALUE 'TEST'
.

*&amp;amp;-- Variables
*-- Variables for Background Job
DATA: g_eventid LIKE tbtcm-eventid,         "event ID
      g_eventparm LIKE tbtcm-eventparm,     "event parameter
      g_xpflag LIKE tbtcm-xpgactive,        "flag for ext. prog.
      g_jobcount LIKE tbtcm-jobcount,       "job number
      g_jobname LIKE tbtcm-jobname,         "jobname
      g_stepcount LIKE tbtcm-stepcount,     "step ID number
      print_parms LIKE pri_params,          "print parameters
      valid TYPE c,                         "flag
      g_jobrel LIKE btch0000-char1.         "flag for job release

*-- Variables for Spool
DATA: g_spoolid LIKE tsp01-rqident,         "Spool id
      g_no_bytes TYPE i,                    "No of bytes
      g_pdf_spoolid LIKE tsp01-rqident.     "PDF spool id

*-- Variables for Email
DATA: g_attach_name TYPE so_obj_des,        "Description of attachment
      g_sender_type LIKE soextreci1-adr_typ,"Sender type
      w_doc_data LIKE sodocchgi1,           "attachment data
      w_sent_all LIKE sonv-flag,            "Sent to all Flag
      w_cnt TYPE i.


*&amp;amp;-- Ranges


*&amp;amp;-- Internal tables
*-- Memory List
DATA: i_listobject LIKE abaplist OCCURS 0 WITH HEADER LINE.

*-- Spool List
DATA: i_listasci(100) TYPE c OCCURS 0 WITH  HEADER LINE.

*-- PDF Internal table
DATA: i_pdf LIKE tline OCCURS 100 WITH HEADER LINE.

*DATA:     w_record     TYPE solisti1,*
          *w_buffer     TYPE string. "To convert from 132 to 255*

*DATA: i_record     TYPE TABLE OF solisti1.*

*-- Email Description
DATA: i_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE.

*-- Packing List
DATA: i_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

*-- Attachment Name
DATA: i_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

*-- Contents of Email
DATA: i_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE.

*-- Message of Email
DATA: i_message LIKE solisti1 OCCURS 0 WITH HEADER LINE.

*-- Recievers List
DATA: i_receivers LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

*----------------------------------------------------------------------*
*  SELECTION-SCREEN DEFINITION
*----------------------------------------------------------------------*

*-- Data selection.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_email(42) TYPE c,
            p_bemail(42) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
*  AT SELECTION-SCREEN VALIDATIONS
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.


*----------------------------------------------------------------------*
*  INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.


*----------------------------------------------------------------------*
*  START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.

*-- Get the Spool from the List
  PERFORM get_spool_from_list.

*-- convert spool to pdf
  PERFORM convert_spool_to_pdf.

***-- Compress Data*
**  perform compress_table.*

*-- Brief Description with attachment in email
  i_mess_bod = 'This Email is to Notify TEST Calculations'.
  APPEND i_mess_bod.

**-- Set Sender Type*
  *g_sender_type = 'U'.*  "Sender type INT, gave an error in my system, NOT known, so you might want to use it as 'INT' again.

*-- Send Email
  PERFORM send_email
              TABLES i_mess_bod
               USING p_email
                     'Test Calculations'
                     'PDF'
                     g_attach_title
                     g_attach_name
                     g_sender_type.

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  get_spool_from_list
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_spool_from_list.

  g_jobname = 'ZZ_Y2B_TEST'.

  SELECT * FROM tbtcp
           INTO TABLE i_tbtcp
          WHERE jobname  = g_jobname
            AND progname = g_jobname
*            and sdldate  = sy-datum
            ORDER BY jobname
                     jobcount.

  READ TABLE i_tbtcp INTO wa_tbtcp INDEX 1.
  IF sy-subrc = 0.
    g_spoolid = wa_tbtcp-listident.
  ENDIF.


ENDFORM.                    "get_spool_from_list
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  convert_spool_to_pdf
*&amp;amp;---------------------------------------------------------------------*
*       convert spool id to pdf
*----------------------------------------------------------------------*
FORM convert_spool_to_pdf.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = g_spoolid
      no_dialog                = ' '
*       dst_device             =
*       pdf_destination        =
    IMPORTING
      pdf_bytecount            = g_no_bytes
      pdf_spoolid              = g_pdf_spoolid
*       list_pagecount         =
      btc_jobname              = g_jobname
      btc_jobcount             = g_jobcount
    TABLES
      pdf                      = i_pdf
    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
              .
ENDFORM.                    "convert_spool_to_pdf
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  send_email
*&amp;amp;---------------------------------------------------------------------*
*       Send Email
*----------------------------------------------------------------------*
FORM send_email TABLES i_mess_bod
                 USING f_email
                       f_email_title
                       f_format
                       f_title
                       f_attach_name
                       f_sender_type.

*--  Populate the subject/generic message attributes
  CLEAR w_doc_data.
  READ TABLE i_message INDEX w_cnt.
  w_doc_data-obj_name   = 'ZVTEST73'.
  w_doc_data-obj_descr  = f_title .
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-sensitivty = 'F'.
  w_doc_data-doc_size   = ( w_cnt - 1 ) * 255 + STRLEN( i_message ).

*-- Body of the message
  CLEAR: i_packing_list.
  REFRESH: i_packing_list.
  i_packing_list-transf_bin = space.
  i_packing_list-head_start   = 1.
  i_packing_list-head_num     = 0.
  i_packing_list-body_start   = 1.
  DESCRIBE TABLE i_message LINES i_packing_list-body_num.
  i_packing_list-doc_type     = 'RAW'.
  i_packing_list-obj_langu    = sy-langu.
  APPEND i_packing_list.

* This part was moved down since contents table is still empty here!!!!
***-- Attachment Details*
**  i_packing_list-transf_bin = 'X'.*
**  i_packing_list-head_start   = 1.*
**  i_packing_list-head_num     = 1.*
**  i_packing_list-body_start   = 1.*
**  DESCRIBE TABLE i_contents LINES i_packing_list-body_num.*
**  i_packing_list-doc_type     = f_format.*
**  i_packing_list-obj_name     = 'ZVTEST73'.*
**  i_packing_list-obj_descr    = f_title.*
**  i_packing_list-obj_langu    = sy-langu.*
**  i_packing_list-doc_size     = i_packing_list-body_num * 255.*
**  APPEND i_packing_list.*

*-- Object Header
  i_objhead = f_title.
  APPEND i_objhead.

*-- Contents of Attachment
  CLEAR i_contents.
  REFRESH i_contents.


******** Here is the part I added.
** Convert PDF from 132 to 255.*
  *LOOP AT i_pdf.*
** Replacing space by ~*
    *TRANSLATE i_pdf USING ' ~'.*
    *CONCATENATE w_buffer i_pdf INTO w_buffer.*
  *ENDLOOP.*
** Replacing ~ by space*
  *TRANSLATE w_buffer USING '~ '.*

  *DO.*
    *w_record = w_buffer.*
**   Appending 255 characters as a record*
    *APPEND w_record TO i_record.*
    *SHIFT w_buffer LEFT BY 255 PLACES.*
    *IF w_buffer IS INITIAL.*
      *EXIT.*
    *ENDIF.*
  *ENDDO.*

  *i_contents[] = i_record[].*

**-- Attachment Details*
  *i_packing_list-transf_bin = 'X'.*
  *i_packing_list-head_start   = 1.*
  *i_packing_list-head_num     = 1.*
  *i_packing_list-body_start   = 1.*
  *DESCRIBE TABLE i_contents LINES i_packing_list-body_num.*
  *i_packing_list-doc_type     = f_format.*
  *i_packing_list-obj_name     = 'ZVTEST73'.*
  *i_packing_list-obj_descr    = f_title.*
  *i_packing_list-obj_langu    = sy-langu.*
  *i_packing_list-doc_size     = i_packing_list-body_num * 255.*
  *APPEND i_packing_list.*

** i_contents[] = i_pdf[].*
********

*-- Contents of Description Details
  CLEAR i_message.
  i_message[] = i_mess_bod[].

*-- Add recievers to recipients list for email
  CLEAR i_receivers .
  REFRESH i_receivers.
  i_receivers-receiver = p_email.
  i_receivers-rec_type = 'U'.
  i_receivers-com_type = 'INT'.
  APPEND i_receivers.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
*     sender_address             =
*      sender_address_type        = f_sender_type
      commit_work                = 'X'
*   importing
*     sent_to_all                = w_sent_all
*     new_object_id              =
*     sender_id                  =
    TABLES
      packing_list               = i_packing_list
      object_header              = i_objhead
      contents_bin               = i_contents
      contents_txt               = i_message
*      contents_hex               =
*      object_para                =
*      object_parb                =
      receivers                  = i_receivers
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.

ENDFORM.                    "send_email

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Micky Oestreich on Apr 25, 2008 12:04 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 22:03:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770113#M907190</guid>
      <dc:creator>Sm1tje</dc:creator>
      <dc:date>2008-04-24T22:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Email Attachment (PDF) from SAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770114#M907191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;GREAT!!!! That worked perfectly!!! &lt;/P&gt;&lt;P&gt;Thanks a lot, Micky.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 22:35:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-email-attachment-pdf-from-sap-program/m-p/3770114#M907191</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T22:35:28Z</dc:date>
    </item>
  </channel>
</rss>

