[58402] in SAPr3-news

home help back first fref pref prev next nref lref last post

Re: Versenden bestehender Datei (App.server) per SAP-Mail

daemon@ATHENA.MIT.EDU (Peter Kloster)
Wed Nov 8 12:19:32 2006

To: sapr3-news@mit.edu
Date: Wed, 08 Nov 2006 18:11:29 +0100
From: Peter Kloster <pktrash@gmx.de>
Message-ID: <eit3e8$s3k$03$1@news.t-online.com>

Alfred Bayer schrieb:
> Hallo beisammen.
>
> Eine Kollegin steht vor der Aufgabe, eine Datei, die von einem ABAP auf den
> Applicationserver gestellt wird, per E-Mail (SAPMail) automatisiert zu
> versenden.
>
> Gibt's da bereits einen passenden Funktionsbaustein dafür oder muss man das
> in mehreren Schritten abhoppeln?

Ja und Ja:-)

Der Fuba, der eine Datei per Attachment versenden kann, heißt:
   SO_NEW_DOCUMENT_ATT_SEND_API1

> Wie würdet Ihr das machen?

Upload, evtl. Convert und Send.
Vor einiger Zeit hatte ich mal ein Beispiel als PDF-Attachment aus
SAPscript. Es erklärt aber, wie die Mail mit Subject, Body und Receiver
aufgebaut werden muss:

*********************************************************************

*...
tables:  itcpo.
*...
*--- Ausgabe als OTF
data:    i_otfout like soli occurs 0 with header line.
*--- Ausgabe als PDF
data:    len_out   like sood-objlen,
         i_pdfout  like solisti1   occurs 0 with header line.

*--- fuer Mailversand
data:    i_reci    like somlreci1  occurs 0 with header line,
         i_cotxt   like solisti1   occurs 0 with header line,
         i_plist   like sopcklsti1 occurs 0 with header line,
         i_ohead   like solisti1   occurs 0 with header line,
         doc_data  like sodocchgi1,
         outbox    like sonv-flag value '',
         anz1      like sy-tabix,
         anz2      like sy-tabix,
         object    like  solisti1.

*...
*... das uebliche Geraffel
*...

  perform open_form.

*...
*... Verarbeitung und Fuellen des Fomrulars
*...

  perform close_form.
  perform convert_otf2pdf.


*-------------------------------------------------------------------*
*       Formular oeffnen
*-------------------------------------------------------------------*
form open_form.

  clear itcpo.

* fuellen der Spoolparameter
  itcpo-tdautority = ...
  itcpo-tdreceiver = sy-uname.
* ...
* ...
* ...
  itcpo-tddest     = ....          " Drucker wegen Aufbereitung!
  itcpo-tdgetotf   = 'X'.          " Ausgabe als Tabelle vorbereiten

  call function 'OPEN_FORM'
       exporting  device   = 'PRINTER'
                  dialog   = ' '
                  form     = pform     " Formularname
                  language = sy-langu
                  options  = itcpo
       exceptions others   = 7.

  if sy-subrc <> 0.
*   ...
  endif.

endform.
*
*-------------------------------------------------------------------*
*       Formular schliessen
*-------------------------------------------------------------------*
form close_form.

  call function 'CLOSE_FORM'
       tables
         otfdata = i_otfout
       exceptions others = 1.

  if sy-subrc <> 0.
*   ...
  endif.

endform.
*
*-------------------------------------------------------------------*
*       OTF nach PDF konvertieren
*-------------------------------------------------------------------*
form convert_otf2pdf.

  clear:   ...
  refresh: ...

  call function 'SX_OBJECT_CONVERT_OTF_PDF'
       exporting
            format_src      = 'OTF'
            format_dst      = 'TIF'   " !!!
            devtype         = ''
            len_in          = ''
        importing
            len_out         = len_out
        tables
            content_in      = i_otfout    "OTF-Daten
            content_out     = i_pdfout    "PDF-Daten
        exceptions
            err_conv_failed = 1
            others          = 2.

  if sy-subrc <> 0.
*   ...
  endif.

* Empfänger bestimmen
  i_reci-receiver = 'email-Adresse@des.empfaengers'.
  i_reci-rec_type = 'U'.
  append i_reci.
* weitere Mailempfänger
  i_reci-receiver = 'chef@des.empfaengers'.
  i_reci-rec_type = 'U'.
  append i_reci.

* Mailbody aufbauen
  i_cotxt = 'Blubber 1'. append i_cotxt.
  i_cotxt = 'Blubber 2'. append i_cotxt.
  i_cotxt = 'Blubber 3'. append i_cotxt.
  i_cotxt = 'Blubber 4'. append i_cotxt.
  i_cotxt = 'Blubber 5'. append i_cotxt.

  describe table i_cotxt lines anz1.
  clear i_plist.
  i_plist-head_start = 1.
  i_plist-head_num   = 0.
  i_plist-body_start = 1.
  i_plist-body_num   = anz1.
  i_plist-doc_type   = 'RAW'.
  append i_plist.

* Mail-Anhang aufbauen
  describe table i_pdfout lines anz2.
  concatenate object '.pdf' into i_ohead.
  translate i_ohead to lower case.
  append i_ohead.
  clear i_plist.
  i_plist-transf_bin = 'X'.
  i_plist-head_start = 1.
  i_plist-head_num   = 1.
  i_plist-body_start = 1.
  i_plist-body_num   = anz2.
  i_plist-doc_type   = 'PDF'.
  i_plist-obj_name   = object.
  i_plist-doc_size   = len_out.
  append i_plist.

* Dokumentdaten bestimmen
  doc_data-obj_name   = 'URGENT'.
  doc_data-obj_descr  = 'TITEL'.
  doc_data-sensitivty = 'P'.
  doc_data-doc_size   = ( anz1 - 1 ) * 255 + strlen( i_cotxt ).

* Mail mit Anhang (PDF-Datei) senden
  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       exporting
            document_data              = doc_data
            put_in_outbox              = outbox
       tables
            packing_list               = i_plist
            object_header              = i_ohead
            contents_bin               = i_pdfout
            contents_txt               = i_cotxt
            receivers                  = i_reci
       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.
  if sy-subrc <> 0.
*   ...
  endif.

endform.
*
*********************************************************************

HTH,
.pk

home help back first fref pref prev next nref lref last post