[52805] in SAPr3-news

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

Re: Re: interne Tabelle als excel per email versenden

daemon@ATHENA.MIT.EDU (jspranz)
Thu Dec 23 10:37:45 2004

To: sapr3-news@mit.edu
Date: 23 Dec 2004 16:23:24 GMT
From: "jspranz" <jspranz@gmx.de>
Message-ID: <cqerds$4d0$1@news-intl.excite.it>

Vielen Dank für die Antwort(en)....

Es handelt sich dabei um eine Prüfliste, d.h. es werden entsprechende Prüfungen
am System mit verschiedenen Reports durchgeführt. 

Die Reports kann man einzeln aufrufen und dann kommt eine Liste oder eine
ALV-Liste raus. 

Ich möchte aber nicht, daß die Benutzer diese täglich aufrufen müssen, sondern
da das umständlich ist (täglich) und performance frißt, möchte ich daß das
abends im Hintergrund läuft. 

Eigentlich ist aber die Kontrolle der Jobs auch zu aufwendig. 
Es kommt vielleicht Wochen nichts raus und dann außnmahmsweise wieder als
Ausnahme doch etwas raus....
Eigentlich wäre es viel besser, wenn die interne Tabelle(n) nicht in einer
Liste oder ALV ausgegeben sondern als e-mail versendet werden würden. 
Das ganze macht noch mehr Sinn, wenn die e-mail nur für nicht leere interne
Tabellen versendet werden. 

Dafür kommt html in Frage - das habe ich einigermaßen mit
Individualprogrmamierung hinbekommen (ein Standard-Fuba wäre allerdings um
einiges besser...)

Eine CSV-Tabelle wäre auch nicht schlecht. 

EXCEL mit optimierter Zeilenbreite und vielleicht auch noch optisch
entsprechend aussehen (wie Excel-Ausgabe in ALV) wäre auch nicht schlecht...

Vielleicht hat doch noch jemand einen Tip. 

Bis jetzt sieht der Funktionsbaustein für HTML so aus:

====================================================================

FUNCTION Z_MAIL_ITAB_AS_HTML_APPEND.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     REFERENCE(I_BETREFF) TYPE  STRING
*"     REFERENCE(I_ANHANGSBEZEICHNUNG) TYPE  STRING OPTIONAL
*"     REFERENCE(IT_FIELDCAT) TYPE  SLIS_T_FIELDCAT_ALV OPTIONAL
*"     REFERENCE(I_SUPPRESS_MESSAGES) TYPE  XFELD OPTIONAL
*"  TABLES
*"      T_MAILTEXT
*"      T_APPENDTXT
*"      T_RECEIVER
*"  EXCEPTIONS
*"      MAILSENDERROR
*"----------------------------------------------------------------------
  DATA: ls_fieldcat TYPE slis_fieldcat_alv.
  DATA: packing_list LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
  DATA: object_header LIKE solisti1 OCCURS 1 WITH HEADER LINE.
  DATA: contents_txt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
  DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
  DATA: reclist_copy LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
  DATA: document_data LIKE sodocchgi1.
  DATA: mailtext_lines LIKE sy-tabix.
  DATA: gesamt_lines LIKE sy-tabix.
  DATA: mailappend_lines LIKE sy-tabix.
*  DATA: user_address LIKE sousradri1 OCCURS 0 WITH HEADER LINE.
  DATA: sent_to_all LIKE sonv-flag.
  DATA: i_doctype TYPE  so_obj_tp.
  DATA: act_rec(15) TYPE n.
* Dokumententyp
  i_doctype = 'RAW'.


* Erstellen des zu versendenden Dokuments
  document_data-obj_name = 'Email'.
* Betreff setzen
  document_data-obj_descr = i_betreff.

* Text der Mail hinzufügen
  contents_txt[] = t_mailtext[].
  DESCRIBE TABLE contents_txt LINES mailtext_lines.
***  READ TABLE contents_txt INDEX tab_lines.
***  document_data-doc_size = tab_lines * 255.

* Anlage einlesen
  contents_txt = '<html> <body bgcolor=white text = white>'.
  APPEND contents_txt.

  contents_txt = '<table border=5 bordercolor=black>'.  "Rand um Tabelle
  APPEND contents_txt.

*                                               T a b e l l e n k o p f
  contents_txt = '<tr bgcolor=#D81E05>'.
  APPEND contents_txt.

  LOOP AT it_fieldcat INTO ls_fieldcat where no_out <> 'X'.
    IF ls_fieldcat-inttype = 'C'.
      contents_txt = '<th align=left>'.
    ELSE.
      contents_txt = '<th align=right>'.
    ENDIF.
    APPEND contents_txt.
    contents_txt = ls_fieldcat-seltext_l.
    IF contents_txt IS INITIAL. "ohne wird space vom Browser ignoriert
      contents_txt = '&nbsp;'.
    ENDIF.
    APPEND contents_txt.
    contents_txt = '</th>'.
    APPEND contents_txt.
  ENDLOOP.
  contents_txt = '</tr>'.
  APPEND contents_txt.

*                                       " T a b e l l e n k ö r p e r
  FIELD-SYMBOLS: <fs_line> TYPE ANY.
  FIELD-SYMBOLS: <fs_value> TYPE ANY.
  LOOP AT t_appendtxt ASSIGNING <fs_line>.
    contents_txt = '<tr bgcolor=#0C1C8C>'.
    APPEND contents_txt.
    LOOP AT it_fieldcat INTO ls_fieldcat where no_out <> 'X'.
      ASSIGN COMPONENT sy-tabix OF STRUCTURE <fs_line> TO <fs_value>.
      IF sy-subrc = 0.
        IF ls_fieldcat-inttype = 'C'.
          contents_txt = '<td align=left>'.
        ELSE.
          contents_txt = '<td align=right>'.
        ENDIF.
        APPEND contents_txt.
        WRITE <fs_value> TO contents_txt.
        IF contents_txt IS INITIAL.        "ohne wird space
          contents_txt = '&nbsp;'.         "vom Browser ignoriert
        ENDIF.
        APPEND contents_txt.
        contents_txt = '</td>'.
        APPEND contents_txt.
      ELSE.
        contents_txt = '<td>'.
        APPEND contents_txt.
        contents_txt = '</td>'.
        APPEND contents_txt.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
*
  contents_txt = '</table>'.                  "Abschluß der Tabelle
  APPEND contents_txt.
  CONCATENATE
      '<p><img src=https://....'
       'login.gif'
     into contents_txt.
  concatenate
     contents_txt
     'alt=blabla'
   INTO
     contents_txt
     SEPARATED BY space.
  APPEND contents_txt.
  contents_txt = '</body></html> '.
  APPEND contents_txt.

  DESCRIBE TABLE contents_txt LINES gesamt_lines.
  mailappend_lines = gesamt_lines - mailtext_lines.


* erstellen des eintrags zum komprimierten dokument
  CLEAR packing_list-transf_bin.
  packing_list-head_start = 1.
  packing_list-head_num = 0.
  packing_list-body_start = 1.
*  packing_list-body_num = tab_lines.
  packing_list-body_num = mailtext_lines.
  packing_list-doc_type = i_doctype. "'RAW'.
  APPEND packing_list.


* Erstellen des Eintrags zur komprimierten Anlage
*  packing_list-transf_bin = 'X'.
  packing_list-head_start = 1.
  packing_list-head_num = 0.                                "war mal 1
*  packing_list-body_start = 1.
  packing_list-body_start = mailtext_lines + 1.
*  packing_list-body_num = tab_lines.
  packing_list-body_num = mailappend_lines.
*  packing_list-doc_type = i_doctype.
  packing_list-doc_type = 'HTM'. "war Eintrag in TA SCOT
*                                  "Konvertierung" notwendig
*  packing_list-doc_type = 'URL'.

  packing_list-obj_name = 'Anhang'.
  packing_list-obj_descr = i_anhangsbezeichnung.
*  packing_list-doc_size = tab_lines * 255.
  packing_list-doc_size = mailappend_lines * 255.

  APPEND packing_list.

* Füllen der Empfängerliste
  LOOP AT t_receiver.
    reclist-receiver = t_receiver.
    reclist-rec_type = 'U'.
    APPEND reclist.
  ENDLOOP.

* Kopie der Empfängerliste erstellen
  reclist_copy[] = reclist[].

* Versenden des Dokuments
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = sent_to_all
    TABLES
      packing_list               = packing_list
      object_header              = object_header
      contents_txt               = contents_txt
      receivers                  = reclist
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      OTHERS                     = 99.

* Meldungen ausgeben wenn gefordert
  CASE sy-subrc.
    WHEN 0.
      CHECK i_suppress_messages IS INITIAL.
      LOOP AT reclist.
        READ TABLE reclist_copy INDEX sy-tabix.
        IF reclist-retrn_code = 0.
          WRITE: / 'E-Mail', i_betreff, 'wurde an' ,
                   reclist_copy-receiver(48), 'gesendet'.
        ELSE.
          WRITE: / 'E-Mail', i_betreff, 'an',
                   reclist_copy-receiver(48),
                   'konnte nicht gesendet werden.'.
        ENDIF.
      ENDLOOP.
    WHEN 1.
      WRITE: 'Fehler: zu viele Empfänger'.
      RAISE mailsenderror..
    WHEN 2.
      WRITE: 'Fehler: Document nicht gesendet'.
      RAISE mailsenderror.
    WHEN 3.
      WRITE: 'Fehler: Documententyp existiert nicht'.
      RAISE mailsenderror.
    WHEN 4.
      WRITE: 'Fehler: Operation nicht berechtigt'.
      RAISE mailsenderror.
    WHEN OTHERS.
      WRITE: 'Fehler: andere Fehler'.
      RAISE mailsenderror.
  ENDCASE.


===================================================================

Für eine CSV-Datei könnte es ungefähr so funktionieren, ist aber auch noch
nicht optimal, da die Spalten in Excel dann zu schmal angezeigt werden. 
Wenn man diese dann optimiert dann aber wieder zu breit, da jede Spalte ca 255
Zeichen lang ist....

FUNCTION Z_MAIL_ITAB_AS_CSV_APPEND.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     REFERENCE(I_BETREFF) TYPE  STRING
*"     REFERENCE(I_ANHANGSBEZEICHNUNG) TYPE  STRING OPTIONAL
*"     REFERENCE(IT_FIELDCAT) TYPE  SLIS_T_FIELDCAT_ALV OPTIONAL
*"     REFERENCE(I_SUPPRESS_MESSAGES) TYPE  XFELD OPTIONAL
*"  TABLES
*"      T_MAILTEXT
*"      T_APPENDTXT
*"      T_RECEIVER
*"  EXCEPTIONS
*"      MAILSENDERROR
*"----------------------------------------------------------------------


  DATA: ls_fieldcat TYPE slis_fieldcat_alv.
  DATA: packing_list LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
  DATA: object_header LIKE solisti1 OCCURS 1 WITH HEADER LINE.
  DATA: contents_txt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
  DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
  DATA: reclist_copy LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
  DATA: document_data LIKE sodocchgi1.
  DATA: mailtext_lines LIKE sy-tabix.
  DATA: gesamt_lines LIKE sy-tabix.
  DATA: mailappend_lines LIKE sy-tabix.
*  DATA: user_address LIKE sousradri1 OCCURS 0 WITH HEADER LINE.
  DATA: sent_to_all LIKE sonv-flag.
  DATA: i_doctype TYPE  so_obj_tp.
  DATA: act_rec(15) TYPE n.
* Dokumententyp
  i_doctype = 'RAW'.

*
* Ermitteln Zeilenumbruch
*
  gv_zeilenumbruch = cl_abap_char_utilities=>cr_lf.
*
* Feldlänge von contents_txt
  data contents_txt_Len  type i.
  data contents_txt_Len1 type i.
  data contents_txt_len2 type i.
  data contents_txt_Len3 type i.
  data contents_txt_len4 type i.
  describe field contents_txt length contents_txt_len in character mode.
  contents_txt_len1 = contents_txt_len - 1.
  contents_txt_len2 = contents_txt_len - 2.
  contents_txt_len3 = contents_txt_len - 3.
  contents_txt_len4 = contents_txt_len - 4.

* Erstellen des zu versendenden Dokuments
  document_data-obj_name = 'Email'.
* Betreff setzen
  document_data-obj_descr = i_betreff.

* Text der Mail hinzufügen
  contents_txt[] = t_mailtext[].
  DESCRIBE TABLE contents_txt LINES mailtext_lines.
*  READ TABLE contents_txt INDEX tab_lines.
*  document_data-doc_size = tab_lines * 255.

* Anlage einlesen
*                                           T a b e l l e n k o p f
  data: gv_last_inttype like ls_fieldcat-inttype.
  clear gv_last_inttype.
  clear contents_txt.
  LOOP AT it_fieldcat INTO ls_fieldcat where no_out <> 'X'.
* Anführungszeichen ersetzen, da für Konstante verwendet
    translate ls_fieldcat-seltext_l using '" '.
    translate ls_fieldcat-seltext_l using ',.'.

* Letztes Feld abschließen
*    IF gv_last_inttype = 'C'.
    if sy-tabix > 1.
***      concatenate contents_txt '"' into contents_txt.
      WRITE ',' to contents_txt+contents_txt_len1(1).
      append contents_txt.
      clear contents_txt.
    endif.
* Anfang Feld
***    concatenate contents_txt '"' into contents_txt.
* Feldinhalt
    concatenate contents_txt ls_fieldcat-seltext_l into contents_txt.
  ENDLOOP.
* Für letztes Feld abschließendes Hochkomma
  if sy-subrc = 0.
***    WRITE '"' to contents_txt+contents_txt_len3(1).
    WRITE gv_zeilenumbruch to contents_txt+contents_txt_len2(+2).
    append contents_txt.
  endif.

*                                       " T a b e l l e n k ö r p e r
  FIELD-SYMBOLS: <fs_line> TYPE ANY.
  FIELD-SYMBOLS: <fs_value> TYPE ANY.
  clear contents_txt.
  clear gv_last_inttype.
  LOOP AT t_appendtxt ASSIGNING <fs_line>.
    LOOP AT it_fieldcat INTO ls_fieldcat where no_out <> 'X'.
      ASSIGN COMPONENT sy-tabix OF STRUCTURE <fs_line> TO <fs_value>.
      IF sy-subrc = 0.
* Anführungszeichen ersetzen, da für Konstante verwendet
        IF ls_fieldcat-inttype = 'C'.
          translate <fs_value> using '" '.
          translate <fs_value> using ',.'.
        endif.
* Letztes Feld abschließen
        if sy-tabix > 1.
          IF gv_last_inttype = 'C'.
***            concatenate contents_txt '"' into contents_txt.
          endif.
          concatenate contents_txt ',' into contents_txt.
        endif.
* Anfang Feld
        if ls_fieldcat-inttype = 'C'.
***          concatenate contents_txt '"' into contents_txt.
        endif.
        gv_last_inttype = ls_fieldcat-inttype.
* Feldinhalt
        data: lv_text(255).
        lv_text = <fs_value>.
        concatenate contents_txt  lv_text into contents_txt.
        append contents_txt.
        clear contents_txt.
      ENDIF.
    ENDLOOP.
    IF gv_last_inttype = 'C'.
***      WRITE '"' to contents_txt+contents_txt_len3(1).
    endif.
    WRITE gv_zeilenumbruch to contents_txt+contents_txt_len2(+2).
    append contents_txt.
    clear contents_txt.
  ENDLOOP.

  DESCRIBE TABLE contents_txt LINES gesamt_lines.
  mailappend_lines = gesamt_lines - mailtext_lines.


* erstellen des eintrags zum komprimierten dokument
  CLEAR packing_list-transf_bin.
  packing_list-head_start = 1.
  packing_list-head_num = 0.
  packing_list-body_start = 1.
*  packing_list-body_num = tab_lines.
  packing_list-body_num = mailtext_lines.
  packing_list-doc_type = i_doctype. "'RAW'.
  APPEND packing_list.


* Erstellen des Eintrags zur komprimierten Anlage
*  packing_list-transf_bin = 'X'.
  packing_list-head_start = 1.
  packing_list-head_num = 0.                                "war mal 1
*  packing_list-body_start = 1.
  packing_list-body_start = mailtext_lines + 1.
*  packing_list-body_num = tab_lines.
  packing_list-body_num = mailappend_lines.
*  packing_list-doc_type = i_doctype.
  packing_list-doc_type = 'CSV'. "war Eintrag in TA SCOT
*                                  "Konvertierung" notwendig
*  packing_list-doc_type = 'URL'.

  packing_list-obj_name = 'Anhang'.
  packing_list-obj_descr = i_anhangsbezeichnung.
*  packing_list-doc_size = tab_lines * 255.
  packing_list-doc_size = mailappend_lines * 255.

  APPEND packing_list.

* Füllen der Empfängerliste
  LOOP AT t_receiver.
    reclist-receiver = t_receiver.
    reclist-rec_type = 'U'.
    APPEND reclist.
  ENDLOOP.

* Kopie der Empfängerliste erstellen
  reclist_copy[] = reclist[].

* Versenden des Dokuments
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = sent_to_all
    TABLES
      packing_list               = packing_list
      object_header              = object_header
      contents_txt               = contents_txt
      receivers                  = reclist
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      OTHERS                     = 99.

* Meldungen ausgeben wenn gefordert
  CASE sy-subrc.
    WHEN 0.
      CHECK i_suppress_messages IS INITIAL.
      LOOP AT reclist.
        READ TABLE reclist_copy INDEX sy-tabix.
        IF reclist-retrn_code = 0.
          WRITE: / 'E-Mail', i_betreff, 'wurde an' ,
                   reclist_copy-receiver(48), 'gesendet'.
        ELSE.
          WRITE: / 'E-Mail', i_betreff, 'an',
                   reclist_copy-receiver(48),
                   'konnte nicht gesendet werden.'.
        ENDIF.
      ENDLOOP.
    WHEN 1.
      WRITE: 'Fehler: zu viele Empfänger'.
      RAISE mailsenderror..
    WHEN 2.
      WRITE: 'Fehler: Document nicht gesendet'.
      RAISE mailsenderror.
    WHEN 3.
      WRITE: 'Fehler: Documententyp existiert nicht'.
      RAISE mailsenderror.
    WHEN 4.
      WRITE: 'Fehler: Operation nicht berechtigt'.
      RAISE mailsenderror.
    WHEN OTHERS.
      WRITE: 'Fehler: andere Fehler'.
      RAISE mailsenderror.
  ENDCASE.

ENDFUNCTION.






Gerd Rother <grother@nurfuerspam.de> ha scritto nel messaggio
<32veuqF3qfkahU1@individual.net>
>
> jspranz wrote:
> [..]
> > ich hätte gerne einen Funktionsbaustein, der mir eine excel-Tabelle als
> > e-mail verschickt.
> >
> [..] 
> > 
> > Ich würde gerne einfach die interne Tabelle übergeben.
> [..] 
> Hallo,
> Die Struktur der internen Tabelle kannst Du als Parameter
> (DDIC-Strukturname) oder als Tabelle (z. B. RSTI_T_DFI) übergeben - am
> besten FB DDIF_FIELDINFO_GET benutzen.
> zunächst muß man den Download auf den PC machen - über Excel. Das geht am
> besten mit einem Excel-OLE-Object (CREATE OBJECT 'Excel.Application').
> Mittels der Methoden des OLE-Objektes wird die interne Tabelle in ein
> Excel-Workbook gespeichert. Am schnellsten geschieht dies spaltenweise via
> Clipboard (Funktionsbaustein CLPB_EXPORT).
> Als Methoden (bzw. Eigenschaften) des Excel-Objekte benutzt Du die
> Excel-VB-Methoden und Objekte. Kleiner Tip: erst einmal in Excel mit
> angeschalteten Macro-Recorder das machen was Du von dem
> Download-Funktionsbaustein erwartest (inkl. Speichern der Datei). Dann das
> erzeugte Makro in die Methoden-Aufrufe im ABAP übertragen.
> Damit ist Teil 1 fertig - die Excel-Datei liegt irgendwo auf dem PC.
> Zum Verschicken per e-Mail benutzt Du die Funktionsbausteine
> SO_OBJECT_UPLOAD (um die Excel-Datei binär wieder nach SAP zu bekommen),
> SO_ATTACHMENT_INSERT und SO_OBJECT_SEND. Falls Du hier Probleme hast,
> einfach mal beim Senden einer solchen e-Mail den Performance-Trace (ohne
> Aggregation) mitlaufen lassen, oder Break-Points in den Funktionsbausteinen
> setzen und dann die Parameter anschauen.
> Ach, das ganze geht latürnich nur im Online - im Batch oder RFC fällt das
> logischerweise auf die Nase.
> Viele Grüße
> Gerd Rother
> -- 
> gerd.....rother.....at....gmx.....net

-----------------------------------------
Beitrag via Excite Newsgroups gepostet.
http://www.excite.de/newsgroup



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