ABAP2XLSX: Unterschied zwischen den Versionen

Aus SAP Wiki ツ
M1ch3lde (Diskussion | Beiträge)
Die Seite wurde neu angelegt: „Kategorie:GitHub_AddOns Der Vorteil gegenüber den Standardmitteln OLE und DOI ist, dass es performanter und mit den neuesten MS Excel Version und Dateityp…“
 
M1ch3lde (Diskussion | Beiträge)
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
[[Kategorie:GitHub_AddOns]]
[[Kategorie:GitHub_AddOns]]
[[Kategorie:Clean-Core-Level_C]]
Der Vorteil gegenüber den Standardmitteln OLE und DOI ist, dass es performanter und mit den neuesten MS Excel Version und Dateitypen wie .xlsx und mit Calc OpenOffice läuft.
Der Vorteil gegenüber den Standardmitteln OLE und DOI ist, dass es performanter und mit den neuesten MS Excel Version und Dateitypen wie .xlsx und mit Calc OpenOffice läuft.


Zeile 6: Zeile 7:
== Installation ==  
== Installation ==  


Der [https://github.com/sapmentors/abap2xlsx.git Nugget] muss mit dem Programm [https://raw.githubusercontent.com/abapGit/build/master/zabapgit.abap ZABAPGIT] online oder offline installiert werden.
Der [https://github.com/sapmentors/abap2xlsx.git Nugget] muss mit dem Programm [https://raw.githubusercontent.com/abapGit/build/main/zabapgit_standalone.prog.abap ZABAPGIT] online oder offline installiert werden.


Ggf. sind einige Anpassungen an den Klassen und Methoden notwendig.
Ggf. sind einige Anpassungen an den Klassen und Methoden notwendig.
Zeile 15: Zeile 16:
CREATE EXCEL
CREATE EXCEL
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
<syntaxhighlight lang="abap" line start="1">
   "IT_DATASETS
   "IT_DATASETS
   "EO_EXCEL TYPE REF TO  
   "EO_EXCEL TYPE REF TO  
Zeile 394: Zeile 396:
   lo_worksheet->zif_excel_sheet_properties~set_style( lo_style_bckgrnd_guid ). "Gitterlinien ausblenden
   lo_worksheet->zif_excel_sheet_properties~set_style( lo_style_bckgrnd_guid ). "Gitterlinien ausblenden
   lo_worksheet->freeze_panes( ip_num_rows = 5 ).                              "die ersten Zeilen einfrieren
   lo_worksheet->freeze_panes( ip_num_rows = 5 ).                              "die ersten Zeilen einfrieren
   lo_worksheet->set_title( 'Bestandsabgleich_MEK_LDL' ).                                    "Name des Arbeitsblattes setzen
   lo_worksheet->set_title( 'Bestandsabgleich' ).                                    "Name des Arbeitsblattes setzen
   lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmdd ).
   lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmdd ).
   lo_worksheet->sheet_setup->vertical_centered  = abap_true.
   lo_worksheet->sheet_setup->vertical_centered  = abap_true.
Zeile 590: Zeile 592:
   
   
  *  Erste Zeile zusammenfassen (mergen) und ausgeben
  *  Erste Zeile zusammenfassen (mergen) und ausgeben
   lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'Bestandsabgleich - MEK / LDL' ip_style = lv_style_first_line_guid ).
   lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'Bestandsabgleich' ip_style = lv_style_first_line_guid ).
   lo_worksheet->set_merge( ip_row = 1 ip_column_start = 'A' ip_column_end = 'O' ).
   lo_worksheet->set_merge( ip_row = 1 ip_column_start = 'A' ip_column_end = 'O' ).
   
   
Zeile 698: Zeile 700:
   
   
  ENDMETHOD.
  ENDMETHOD.
</syntaxhighlight>
</div>
</div>
</div>
</div>
Zeile 704: Zeile 707:
LOCAL CLASSES FOR SENDING
LOCAL CLASSES FOR SENDING
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
<syntaxhighlight lang="abap" line start="1">
  "EXPORTING it_datasets = lt_vergleich IMPORTING eo_excel = lo_excel
  "EXPORTING it_datasets = lt_vergleich IMPORTING eo_excel = lo_excel
  CLASS lcl_output DEFINITION CREATE PRIVATE.
  CLASS lcl_output DEFINITION CREATE PRIVATE.
Zeile 767: Zeile 771:
   
   
  **  Mailtext aufbereiten
  **  Mailtext aufbereiten
     APPEND ' ' TO main_text.
     APPEND ' ' TO main_text.  
*    APPEND 'Folgendermaßen sind die Werte zu interpretieren:' TO main_text. "#EC NOTEXT
*    APPEND 'Beispiel: Differenz 3 => SAP System hat 3 Mehrbestand | Differenz -3 => RRS WMS hat 3 Mehrbestand.' TO main_text.
*    APPEND 'E-Mail Empfänger können zentral über die Verteilerliste "SAP_LSP_DIFF" angepasst werden.' TO main_text.
     TRY.
     TRY.
  * Create send request
  * Create send request
Zeile 838: Zeile 838:
   ENDMETHOD.                    "send_email
   ENDMETHOD.                    "send_email
  ENDCLASS.
  ENDCLASS.
</syntaxhighlight>
</div>
</div>
</div>
</div>
Zeile 844: Zeile 845:
OUTPUT IN GRID
OUTPUT IN GRID
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
<syntaxhighlight lang="abap" line start="1">
   METHOD create_output_stock_rec_in_alv.
   METHOD create_output_stock_rec_in_alv.
   
   
Zeile 1.012: Zeile 1.014:
     lo_alv->display( ).
     lo_alv->display( ).
   ENDMETHOD.
   ENDMETHOD.
</syntaxhighlight>
</div>
</div>
</div>
</div>

Aktuelle Version vom 18. Januar 2026, 19:39 Uhr

Der Vorteil gegenüber den Standardmitteln OLE und DOI ist, dass es performanter und mit den neuesten MS Excel Version und Dateitypen wie .xlsx und mit Calc OpenOffice läuft.

Mehr Vorteile und Übersicht über dieses AddOn kann hier nachgelesen werden.

Installation

Der Nugget muss mit dem Programm ZABAPGIT online oder offline installiert werden.

Ggf. sind einige Anpassungen an den Klassen und Methoden notwendig.

Codeschnipsel

CREATE EXCEL

   "IT_DATASETS
   "EO_EXCEL TYPE REF TO 
   METHOD create_send_xlsx.
   CHECK lines( it_datasets ) > 0.
 
  DATA:
    lo_excel                   TYPE REF TO zcl_excel,
    lo_worksheet               TYPE REF TO zcl_excel_worksheet,
    lo_autofilter              TYPE REF TO zcl_excel_autofilter,
    row_dimension              TYPE REF TO zcl_excel_worksheet_rowdimensi,
    column_dimension           TYPE REF TO zcl_excel_column,
    "column_dimension           TYPE REF TO zcl_excel_worksheet_columndime,
    lo_border_none             TYPE REF TO zcl_excel_style_border,
    lo_border_blue             TYPE REF TO zcl_excel_style_border,
    lo_style_bckgrnd           TYPE REF TO zcl_excel_style,
    lo_style_bckgrnd_guid      TYPE zexcel_cell_style,
    lo_style_first_line        TYPE REF TO zcl_excel_style,
    lv_style_first_line_guid   TYPE zexcel_cell_style,
    lo_style_head_line_l       TYPE REF TO zcl_excel_style,
    lv_style_head_line_l_guid  TYPE zexcel_cell_style,
    lo_style_head_line_c       TYPE REF TO zcl_excel_style,
    lv_style_head_line_c_guid  TYPE zexcel_cell_style,
    lo_style_center            TYPE REF TO zcl_excel_style,
    lv_style_center_guid       TYPE zexcel_cell_style,
 
    lo_border_dark             TYPE REF TO zcl_excel_style_border,
    lo_border_left             TYPE REF TO zcl_excel_style_border,
    lo_border_right            TYPE REF TO zcl_excel_style_border,
    lo_border_down_1           TYPE REF TO zcl_excel_style_border,
    lo_border_down_2           TYPE REF TO zcl_excel_style_border,
    lo_style_normal_c          TYPE REF TO zcl_excel_style,
    lo_style_normal_c_red      TYPE REF TO zcl_excel_style,
    lo_style_normal_l          TYPE REF TO zcl_excel_style,
    lo_style_grau_c            TYPE REF TO zcl_excel_style,
    lo_style_grau_l            TYPE REF TO zcl_excel_style,
    lo_style_grey              TYPE REF TO zcl_excel_style,
    lo_style_blau_a            TYPE REF TO zcl_excel_style,
    lo_style_oran_a            TYPE REF TO zcl_excel_style,
    lo_style_rothell            TYPE REF TO zcl_excel_style,
    lo_style_blau_b            TYPE REF TO zcl_excel_style,
    lo_style_blau_c            TYPE REF TO zcl_excel_style,
    lo_style_green_b           TYPE REF TO zcl_excel_style,
    lo_style_green_c           TYPE REF TO zcl_excel_style,
    lo_style_rot_c             TYPE REF TO zcl_excel_style,
    lo_style_braun_1           TYPE REF TO zcl_excel_style,
    lo_style_braun_2           TYPE REF TO zcl_excel_style,
    lo_style_braun_3           TYPE REF TO zcl_excel_style,
    lo_style_braun_4           TYPE REF TO zcl_excel_style,
    lo_style_normal_c_guid     TYPE zexcel_cell_style,
    lo_style_normal_c_red_guid TYPE zexcel_cell_style,
    lo_style_normal_l_guid     TYPE zexcel_cell_style,
    lo_style_grau_c_guid       TYPE zexcel_cell_style,
    lo_style_oran_a_guid       TYPE zexcel_cell_style,
    lo_style_rothell_a_guid       TYPE zexcel_cell_style,
    lo_style_grau_l_guid       TYPE zexcel_cell_style,
    lo_style_grey_guid         TYPE zexcel_cell_style,
    lo_style_blau_a_guid       TYPE zexcel_cell_style,
    lo_style_blau_b_guid       TYPE zexcel_cell_style,
    lo_style_blau_c_guid       TYPE zexcel_cell_style,
    lo_style_green_b_guid      TYPE zexcel_cell_style,
    lo_style_green_c_guid      TYPE zexcel_cell_style,
    lo_style_rot_c_guid        TYPE zexcel_cell_style,
    lo_style_braun_1_guid      TYPE zexcel_cell_style,
    lo_style_braun_2_guid      TYPE zexcel_cell_style,
    lo_style_braun_3_guid      TYPE zexcel_cell_style,
    lo_style_braun_4_guid      TYPE zexcel_cell_style,
    lv_borders                 TYPE zexcel_s_cstyle_borders,
    lv_xborders                TYPE zexcel_s_cstylex_borders,
    lv_borders_down            TYPE zexcel_s_cstyle_border,
    lv_xborders_down           TYPE zexcel_s_cstylex_border.
 
  DATA:
    lv_row       TYPE i,
    lv_row_a     TYPE i,
    lv_row_b     TYPE i,
    lv_col       TYPE zexcel_cell_column VALUE 1,
    lv_col_str   TYPE zexcel_cell_column_alpha,
    lv_zahl_char TYPE char10,
    lv_time_char TYPE char5.
 
  DATA: ls_area     TYPE zexcel_s_autofilter_area.
        "ls_datasets TYPE zabgleich_ldl_t.
 
  
  "DATA: ls_out    TYPE zoos_neu.
  DATA: lv_ignore TYPE char01.
  DATA: lv_tabix  TYPE sytabix.
 
 * ======================================================================
 *   Im Vorfeld die Ausgabestruktur erstellen
 * ======================================================================
  DATA: lv_struk         TYPE tabname VALUE 'zabgleich_LDL'.
  DATA: gt_fcat TYPE lvc_t_fcat,
        gs_fcat LIKE LINE OF gt_fcat.
  FIELD-SYMBOLS: <fcat>  TYPE lvc_s_fcat.
  FIELD-SYMBOLS: <value> TYPE any.
 
 * Mit dem FuBa schon einmal den Grundaufbau des Feldctalogs erstellen
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = lv_struk
      i_client_never_display = 'X'
      i_bypassing_buffer     = 'X'
    CHANGING
      ct_fieldcat            = gt_fcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
 
  CREATE OBJECT lo_excel.
 
 *   Für die Gitterlinien innerhalb der Tabelle
  CREATE OBJECT lo_border_dark.
  lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black.
  lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin.
 
  CREATE OBJECT lo_border_left.
  lo_border_left->border_color-rgb = zcl_excel_style_color=>c_black.
  lo_border_left->border_style = zcl_excel_style_border=>c_border_thin.
 
  CREATE OBJECT lo_border_right.
  lo_border_right->border_color-rgb = zcl_excel_style_color=>c_black.
  lo_border_right->border_style = zcl_excel_style_border=>c_border_thin.
 
  CREATE OBJECT lo_border_down_1.
  lo_border_down_1->border_color-rgb = zcl_excel_style_color=>c_black.
  lo_border_down_1->border_style = zcl_excel_style_border=>c_border_thin.
 
  CREATE OBJECT lo_border_down_2.
  lo_border_down_2->border_color-rgb = zcl_excel_style_color=>c_black.
  lo_border_down_2->border_style = zcl_excel_style_border=>c_border_thick.
 
 * ======================================================================
 *   Für das gesamte Blatt --> Hintergrund auf Weiß setzen (ohne Gitterlinien)
 * ======================================================================
  lo_style_bckgrnd = lo_excel->add_new_style( ).
  lo_style_bckgrnd->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_bckgrnd->fill->fgcolor-rgb  = zcl_excel_style_color=>c_white.
  lo_style_bckgrnd_guid = lo_style_bckgrnd->get_guid( ).
 
 * ======================================================================
 *   Für die erste Zeile
 * ======================================================================
  lo_style_first_line = lo_excel->add_new_style( ).
  lo_style_first_line->font->bold = abap_true.
  lo_style_first_line->font->size = 18.
  lo_style_first_line->font->italic = abap_false.
  lo_style_first_line->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_first_line->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_first_line->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_first_line->fill->fgcolor-theme  = zcl_excel_style_color=>c_theme_dark1.
  lv_style_first_line_guid = lo_style_first_line->get_guid( ).
 
 * ======================================================================
 *   Style für Tabellen-Überschriften generieren
 * ======================================================================
 *   Ausrichtung - zentriert (horizontal + vertikal)
  lo_style_head_line_c = lo_excel->add_new_style( ).
  lo_style_head_line_c->font->bold = abap_true.
  lo_style_head_line_c->font->size = 11.
  lo_style_head_line_c->font->italic = abap_false.
  lo_style_head_line_c->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_head_line_c->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_head_line_c->alignment->vertical   = zcl_excel_style_alignment=>c_vertical_center.
  lo_style_head_line_c->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_head_line_c->fill->fgcolor-theme  = zcl_excel_style_color=>c_theme_dark2.
  lv_style_head_line_c_guid = lo_style_head_line_c->get_guid( ).
 
 *   Ausrichtung - linksbündig
  lo_style_head_line_l = lo_excel->add_new_style( ).
  lo_style_head_line_l->font->bold = abap_true.
  lo_style_head_line_l->font->size = 11.
  lo_style_head_line_l->font->italic = abap_false.
  lo_style_head_line_l->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_head_line_l->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_left.
  lo_style_head_line_l->alignment->vertical   = zcl_excel_style_alignment=>c_vertical_center.
  lo_style_head_line_l->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_head_line_l->fill->fgcolor-theme  = zcl_excel_style_color=>c_theme_dark2.
  lv_style_head_line_l_guid = lo_style_head_line_l->get_guid( ).
 
 * ======================================================================
 *   Style für Tabellen-Inhalte generieren
 * ======================================================================
 
 *   Normal - zentriert
  lo_style_normal_c = lo_excel->add_new_style( ).
  lo_style_normal_c->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_normal_c->font->bold = abap_false.
  lo_style_normal_c->borders->down       = lo_border_down_1.
  lo_style_normal_c->borders->left       = lo_border_left.
  lo_style_normal_c->borders->right      = lo_border_right.
  lo_style_normal_c_guid = lo_style_normal_c->get_guid( ).
 *
 *   Normal - zentriert und Schrift in ROT
  lo_style_normal_c_red = lo_excel->add_new_style( ).
  lo_style_normal_c_red->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_normal_c_red->font->bold  = abap_false.
  lo_style_normal_c_red->font->color-rgb = zcl_excel_style_color=>c_red.
  lo_style_normal_c_red->borders->down       = lo_border_down_1.
  lo_style_normal_c_red->borders->left       = lo_border_left.
  lo_style_normal_c_red->borders->right      = lo_border_right.
  lo_style_normal_c_red_guid = lo_style_normal_c_red->get_guid( ).
 
 *   Normal - linksbündig
  lo_style_normal_l = lo_excel->add_new_style( ).
  lo_style_normal_l->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_left.
  lo_style_normal_l->font->bold = abap_false.
 *   lo_style_normal_l->borders->allborders = lo_border_dark.
  lo_style_normal_l->borders->down       = lo_border_down_1.
  lo_style_normal_l->borders->left       = lo_border_left.
  lo_style_normal_l->borders->right      = lo_border_right.
  lo_style_normal_l_guid = lo_style_normal_l->get_guid( ).
 
 *   Grau hinterlegt - zentriert
  lo_style_grau_c = lo_excel->add_new_style( ).
  lo_style_grau_c->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_grau_c->font->bold = abap_false.
 *   lo_style_grau_c->borders->allborders = lo_border_dark.
  lo_style_grau_c->borders->down       = lo_border_down_1.
  lo_style_grau_c->borders->left       = lo_border_left.
  lo_style_grau_c->borders->right      = lo_border_right.
  lo_style_grau_c->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_grau_c->fill->fgcolor-theme  = zcl_excel_style_color=>c_theme_dark2.
  lo_style_grau_c_guid = lo_style_grau_c->get_guid( ).
 
 *   Grau hinterlegt - linksbündig
  lo_style_grau_l = lo_excel->add_new_style( ).
  lo_style_grau_l->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_left.
  lo_style_grau_l->font->bold = abap_false.
 *   lo_style_grau_l->borders->allborders = lo_border_dark.
  lo_style_grau_l->borders->down       = lo_border_down_1.
  lo_style_grau_l->borders->left       = lo_border_left.
  lo_style_grau_l->borders->right      = lo_border_right.
  lo_style_grau_l->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_grau_l->fill->fgcolor-theme  = zcl_excel_style_color=>c_theme_dark2.
  lo_style_grau_l_guid = lo_style_grau_l->get_guid( ).
 
 *   Blau A hinterlegt - zentriert
  lo_style_blau_a   = lo_excel->add_new_style( ).
  lo_style_blau_a->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_blau_a->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_blau_a->fill->fgcolor-rgb  = 'FF4F81BD'.
 *   lo_style_blau_A->borders->allborders = lo_border_dark.
  lo_style_blau_a->borders->down       = lo_border_down_1.
  lo_style_blau_a->borders->left       = lo_border_left.
  lo_style_blau_a->borders->right      = lo_border_right.
  lo_style_blau_a->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_blau_a_guid = lo_style_blau_a->get_guid( ).
 
 *   Blau B hinterlegt - zentriert
  lo_style_blau_b   = lo_excel->add_new_style( ).
  lo_style_blau_b->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_blau_b->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_blau_b->fill->fgcolor-rgb  = 'FF95B3D7'.
 *   lo_style_blau_B->borders->allborders = lo_border_dark.
  lo_style_blau_b->borders->down       = lo_border_down_1.
  lo_style_blau_b->borders->left       = lo_border_left.
  lo_style_blau_b->borders->right      = lo_border_right.
  lo_style_blau_b->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_blau_b_guid = lo_style_blau_b->get_guid( ).
 
 *   Blau C hinterlegt - zentriert
  lo_style_blau_c   = lo_excel->add_new_style( ).
  lo_style_blau_c->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_blau_c->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_blau_c->fill->fgcolor-rgb  = 'FFDCE6F1'.
 *   lo_style_blau_C->borders->allborders = lo_border_dark.
  lo_style_blau_c->borders->down       = lo_border_down_1.
  lo_style_blau_c->borders->left       = lo_border_left.
  lo_style_blau_c->borders->right      = lo_border_right.
 *    lo_style_blau_C->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_blau_c->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_blau_c_guid = lo_style_blau_c->get_guid( ).
 
 *   Rot C hinterlegt - zentriert
  lo_style_rot_c   = lo_excel->add_new_style( ).
  lo_style_rot_c->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_rot_c->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_rot_c->fill->fgcolor-rgb  = 'FFCD5C5C'.
 *   lo_style_rot_C->borders->allborders = lo_border_dark.
  lo_style_rot_c->borders->down       = lo_border_down_1.
  lo_style_rot_c->borders->left       = lo_border_left.
  lo_style_rot_c->borders->right      = lo_border_right.
 *    lo_style_rot_C->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_rot_c->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_rot_c_guid = lo_style_rot_c->get_guid( ).
 
 *   Grün B hinterlegt - zentriert
  lo_style_green_b   = lo_excel->add_new_style( ).
  lo_style_green_b->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_green_b->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_green_b->fill->fgcolor-rgb  = 'FF3CB371'. "Dunkleresgrün
 *   lo_style_rot_C->borders->allborders = lo_border_dark.
  lo_style_green_b->borders->down       = lo_border_down_1.
  lo_style_green_b->borders->left       = lo_border_left.
  lo_style_green_b->borders->right      = lo_border_right.
 *    lo_style_rot_C->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_green_b->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_green_b_guid = lo_style_green_b->get_guid( ).
 
 *   Grau B hinterlegt - zentriert
  lo_style_grey = lo_excel->add_new_style( ).
  lo_style_grey->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_grey->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_grey->fill->fgcolor-rgb  = 'FFA9A9A9'. "Dunkelgrau
 *   lo_style_rot_C->borders->allborders = lo_border_dark.
  lo_style_grey->borders->down       = lo_border_down_1.
  lo_style_grey->borders->left       = lo_border_left.
  lo_style_grey->borders->right      = lo_border_right.
 *    lo_style_rot_C->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_grey->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_grey_guid = lo_style_grey->get_guid( ).
 
 *   Grün C hinterlegt - zentriert
  lo_style_green_c   = lo_excel->add_new_style( ).
  lo_style_green_c->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_green_c->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_green_c->fill->fgcolor-rgb  = 'FF90EE90'. "Helleresgrün
 *   lo_style_rot_C->borders->allborders = lo_border_dark.
  lo_style_green_c->borders->down       = lo_border_down_1.
  lo_style_green_c->borders->left       = lo_border_left.
  lo_style_green_c->borders->right      = lo_border_right.
 *    lo_style_rot_C->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_green_c->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_green_c_guid = lo_style_green_c->get_guid( ).
 
 *   Braun 1 hinterlegt - zentriert
  lo_style_braun_1  = lo_excel->add_new_style( ).
  lo_style_braun_1->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_braun_1->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_braun_1->fill->fgcolor-rgb  = 'FFC0504D'.
 *   lo_style_braun_1->borders->allborders = lo_border_dark.
  lo_style_braun_1->borders->down       = lo_border_down_1.
  lo_style_braun_1->borders->left       = lo_border_left.
  lo_style_braun_1->borders->right      = lo_border_right.
  lo_style_braun_1->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_braun_1_guid = lo_style_braun_1->get_guid( ).
 
 *   Braun 2 hinterlegt - zentriert
  lo_style_braun_2  = lo_excel->add_new_style( ).
  lo_style_braun_2->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_braun_2->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_braun_2->fill->fgcolor-rgb  = 'FFDA9694'.
 *   lo_style_braun_2->borders->allborders = lo_border_dark.
  lo_style_braun_2->borders->down       = lo_border_down_1.
  lo_style_braun_2->borders->left       = lo_border_left.
  lo_style_braun_2->borders->right      = lo_border_right.
  lo_style_braun_2->font->color-rgb = zcl_excel_style_color=>c_white.
  lo_style_braun_2_guid = lo_style_braun_2->get_guid( ).
 
 * Orange A hinterlegt - zentriert
  lo_style_oran_a   = lo_excel->add_new_style( ).
  lo_style_oran_a->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_oran_a->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_oran_a->fill->fgcolor-rgb  = 'FFFFA500'.
 *   lo_style_blau_A->borders->allborders = lo_border_dark.
  lo_style_oran_a->borders->down       = lo_border_down_1.
  lo_style_oran_a->borders->left       = lo_border_left.
  lo_style_oran_a->borders->right      = lo_border_right.
  lo_style_oran_a->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_oran_a_guid = lo_style_oran_a->get_guid( ).
 
 * Hellrot A hinterlegt - zentriert
  lo_style_rothell   = lo_excel->add_new_style( ).
  lo_style_rothell->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center.
  lo_style_rothell->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
  lo_style_rothell->fill->fgcolor-rgb  = 'FFF08080'.
 *   lo_style_blau_A->borders->allborders = lo_border_dark.
  lo_style_rothell->borders->down       = lo_border_down_1.
  lo_style_rothell->borders->left       = lo_border_left.
  lo_style_rothell->borders->right      = lo_border_right.
  lo_style_rothell->font->color-rgb = zcl_excel_style_color=>c_black.
  lo_style_rothell_a_guid = lo_style_rothell->get_guid( ).
 
 *   Get active sheet
  lo_worksheet = lo_excel->get_active_worksheet( ).
  lo_worksheet->zif_excel_sheet_properties~set_style( lo_style_bckgrnd_guid ). "Gitterlinien ausblenden
  lo_worksheet->freeze_panes( ip_num_rows = 5 ).                               "die ersten Zeilen einfrieren
  lo_worksheet->set_title( 'Bestandsabgleich' ).                                     "Name des Arbeitsblattes setzen
  lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmdd ).
  lo_worksheet->sheet_setup->vertical_centered   = abap_true.
  lo_worksheet->sheet_setup->horizontal_centered = abap_true.
  lo_worksheet->sheet_setup->fit_to_page         = abap_true.
  lo_worksheet->sheet_setup->fit_to_height       = 1.
  lo_worksheet->sheet_setup->fit_to_width        = 1.
  lo_worksheet->sheet_setup->orientation         = zcl_excel_sheet_setup=>c_orientation_landscape.
 
 * Start der Ausgabe bei Zeile 6
  lv_row = 5.
  lv_row_a = 6. "Erste Zeile, die ge-merged werden soll!
  LOOP AT it_datasets INTO DATA(ls_datasets).
    lv_row = lv_row + 1.
    lv_col = 1.  "Ausgabe soll beginnen in Spalte A --> wird gleich gewandelt!
    LOOP AT gt_fcat ASSIGNING <fcat>.
 
 *       Von Zahl in Buchstabe für die Spalte wandeln
        lv_col_str = zcl_excel_common=>convert_column2alpha( lv_col ).
 
        CASE <fcat>-fieldname.
          WHEN 'MANDT'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-mandt
                                    ip_style  = lo_style_blau_c_guid ).
          WHEN 'MATNR'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-matnr
                                    ip_style  = lo_style_blau_c_guid ).
          WHEN 'WERKS'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-werks
                                    ip_style  = lo_style_blau_c_guid ).
 
           WHEN 'LGORT'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-lgort
                                    ip_style  = lo_style_blau_c_guid ).
 
          WHEN 'MAKTX'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-maktx
                                    ip_style  = lo_style_blau_c_guid ).
          WHEN 'ERDAT'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-erdat
                                    ip_style  = lo_style_blau_c_guid ).
 
          WHEN 'SAP_LABST'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-sap_labst
                                    ip_style  = lo_style_green_c_guid ).
 
          WHEN 'SAP_INSME'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-sap_insme
                                    ip_style  = lo_style_green_c_guid ).
 
         WHEN 'SAP_SPEME'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-sap_speme
                                    ip_style  = lo_style_green_c_guid ).
 
          WHEN 'DIFF_LABST'.
            IF ls_datasets-diff_labst > 0.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_labst
                                     ip_style  = lo_style_rot_c_guid ).
            ELSEIF ls_datasets-diff_labst < 0.
             lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_labst
                                    ip_style  = lo_style_rothell_a_guid ).
            ELSE.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_labst
                                    ip_style  = lo_style_grau_c_guid ).
            ENDIF.
 
          WHEN 'DIFF_INSME'.
            IF ls_datasets-diff_insme > 0.
             lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_insme
                                     ip_style  = lo_style_rot_c_guid ).
            ELSEIF ls_datasets-diff_insme < 0.
             lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_insme
                                     ip_style  = lo_style_rothell_a_guid ).
            ELSE.
           lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_insme
                                    ip_style  = lo_style_grau_c_guid ).
            ENDIF.
 
         WHEN 'DIFF_SPEME'.
          IF ls_datasets-diff_speme > 0.
           lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_speme
                                     ip_style  = lo_style_rot_c_guid ).
          ELSEIF ls_datasets-diff_speme < 0.
             lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_speme
                                     ip_style  = lo_style_rothell_a_guid ).
          ELSE.
          lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-diff_speme
                                    ip_style  = lo_style_grau_c_guid ).
          ENDIF.
         WHEN 'LDL_LABST'.
          lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-ldl_labst
                                    ip_style  = lo_style_oran_a_guid ).

         WHEN 'LDL_INSME'.
          lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-ldl_insme
                                    ip_style  = lo_style_oran_a_guid ).

         WHEN 'LDL_SPEME'.
            lo_worksheet->set_cell( ip_row    = lv_row
                                    ip_column = lv_col_str
                                    ip_value  = ls_datasets-ldl_speme
                                    ip_style  = lo_style_oran_a_guid ).
 
        ENDCASE.
 
      lv_col = lv_col + 1.
    ENDLOOP.
  ENDLOOP.

 **   Vor der eigentlichen Ausgabe noch Autosize durchführen!
 **    column_dimension = lo_worksheet->get_column( 'A' ).
 **    column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'B' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'C' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 **    column_dimension = lo_worksheet->get_column( 'D' ).
 **    column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'E' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 **    column_dimension = lo_worksheet->get_column( 'F' ).
 **    column_dimension->set_auto_size( ip_auto_size = abap_true ).
 **    column_dimension = lo_worksheet->get_column( 'G' ).
 **    column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'H' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'I' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'J' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'K' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'L' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'M' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'N' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'O' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'P' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'Q' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'R' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 *  column_dimension = lo_worksheet->get_column( 'S' ).
 *  column_dimension->set_auto_size( ip_auto_size = abap_true ).
 
 *   ====================================================================
 *   Die Überschriftenzeile erst im Nachgang setzen, da bei der
 *   Zusammenfassung von Zellen, die automatische Breitenanpassung
 *   nicht mehr funktioniert!
 *   ====================================================================
 
 *   Erste Zeile zusammenfassen (mergen) und ausgeben
  lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'Bestandsabgleich' ip_style = lv_style_first_line_guid ).
  lo_worksheet->set_merge( ip_row = 1 ip_column_start = 'A' ip_column_end = 'O' ).
 
 *   Status + Datum setzen + mergen
  lo_worksheet->set_cell( ip_column = 'A' ip_row = 2 ip_value = 'Stand:' ).
  lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = sy-datum  ip_style = lo_style_normal_c_guid ).
  "  lo_worksheet->set_merge( ip_row = 2 ip_column_start = 'B' ip_column_end = 'C' ).
 
 *  Systeminfos
  lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'System:' ).
  lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = sy-sysid  ip_style = lo_style_normal_c_guid ).
 *  lo_worksheet->set_merge( ip_row = 3 ip_column_start = 'B' ip_column_end = 'C' ).
 
 *   Nachträglich den Rahmen aus der Zelle entfernen
  lv_xborders-allborders-border_style = abap_true.
  lv_borders-allborders-border_style = zcl_excel_style_border=>c_border_none.
  lo_worksheet->change_cell_style(  ip_column     = 'B'
                                    ip_row        =  2
                                    ip_xborders   =  lv_xborders
                                    ip_borders    =  lv_borders ).
 
  lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'A' ).
  lo_worksheet->set_cell(  ip_row = 4 ip_column = 'A' ip_value = 'Mandt'       ip_style = lv_style_head_line_c_guid ).
  column_dimension = lo_worksheet->get_column( ip_column = 'A' ).
  column_dimension->set_width( ip_width = 10 ).
 
  lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'B' ).
  lo_worksheet->set_cell(  ip_row = 4 ip_column = 'B' ip_value = 'Material'        ip_style = lv_style_head_line_c_guid ).
  column_dimension = lo_worksheet->get_column( ip_column = 'B' ).
  column_dimension->set_width( ip_width = 10 ).
 
  lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'C' ).
  lo_worksheet->set_cell(  ip_row = 4 ip_column = 'C' ip_value = 'Plant'        ip_style = lv_style_head_line_c_guid ).
  column_dimension = lo_worksheet->get_column( ip_column = 'C' ).
  column_dimension->set_width( ip_width = 10 ).
 *
  lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'D' ).
  lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = 'Storage Loction' ip_style = lv_style_head_line_c_guid ).
  column_dimension = lo_worksheet->get_column( ip_column = 'D' ).
  column_dimension->set_width( ip_width = 20 ).
 
  lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'E' ).
  lo_worksheet->set_cell(  ip_row = 4 ip_column = 'E' ip_value = 'Shortext' ip_style = lv_style_head_line_c_guid ).
  column_dimension = lo_worksheet->get_column( ip_column = 'E' ).
  column_dimension->set_width( ip_width = 50 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'F' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'F' ip_value = 'Submitted Date' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'F' ).
    column_dimension->set_width( ip_width = 17 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'G' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'G' ip_value = 'SAP Available' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'G' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'H' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'H' ip_value = 'Diff Available' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'H' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'I' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'I' ip_value = 'LDL Available' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'I' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'J' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'J' ip_value = 'SAP Q-Stock ' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'J' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'K' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'K' ip_value = 'Diff Q-Stock' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'K' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'L' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'L' ip_value = 'LDL Q-Stock' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'L' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'M' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'M' ip_value = 'SAP Blocked' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'M' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'N' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'N' ip_value = 'Diff Blocked' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'N' ).
    column_dimension->set_width( ip_width = 20 ).
 
    lo_worksheet->set_merge( ip_row = 4 ip_row_to =  5  ip_column_start = 'O' ).
    lo_worksheet->set_cell(  ip_row = 4 ip_column = 'O' ip_value = 'LDL Blocked' ip_style = lv_style_head_line_c_guid ).
    column_dimension = lo_worksheet->get_column( ip_column = 'O' ).
    column_dimension->set_width( ip_width = 20 ).
 
  lo_autofilter = lo_excel->add_new_autofilter( io_sheet = lo_worksheet ) .
 
  ls_area-row_start = 4.
  ls_area-col_start = 1.
  ls_area-row_end = lo_worksheet->get_highest_row( ).
  ls_area-col_end = lo_worksheet->get_highest_column( ).
  lo_autofilter->set_filter_area( is_area = ls_area ).
 
  eo_excel = lo_excel.
  "lcl_output=>output( lo_excel ).
 
 ENDMETHOD.

LOCAL CLASSES FOR SENDING

 "EXPORTING it_datasets = lt_vergleich IMPORTING eo_excel = lo_excel
 CLASS lcl_output DEFINITION CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS: output         IMPORTING cl_excel TYPE REF TO zcl_excel.
 
  PRIVATE SECTION.
    METHODS: send_email.
 
    DATA: xdata     TYPE xstring,             " Will be used for sending as email
          t_rawdata TYPE solix_tab,           " Will be used for downloading or open directly
          bytecount TYPE i.                   " Will be used for downloading or open directly
 ENDCLASS.                    "lcl_output DEFINITION
 CLASS lcl_output IMPLEMENTATION.
  METHOD output.
 
    DATA: cl_output TYPE REF TO lcl_output,
          cl_writer TYPE REF TO zif_excel_writer.
 
    CREATE OBJECT cl_output.
    CREATE OBJECT cl_writer TYPE zcl_excel_writer_2007.
    cl_output->xdata = cl_writer->write_file( cl_excel ).
 
    cl_output->t_rawdata = cl_bcs_convert=>xstring_to_solix( iv_xstring  = cl_output->xdata ).
    cl_output->bytecount = xstrlen( cl_output->xdata ).
    cl_output->send_email( ).
  ENDMETHOD.                    "output
  METHOD send_email.
 * Needed to send emails
    DATA: bcs_exception            TYPE REF TO cx_bcs,
          errortext                TYPE string,
          cl_send_request          TYPE REF TO cl_bcs,
          cl_document              TYPE REF TO cl_document_bcs,
          cl_recipient             TYPE REF TO if_recipient_bcs,
          cl_sender                TYPE REF TO cl_cam_address_bcs,
          t_attachment_header      TYPE soli_tab,
          wa_attachment_header     LIKE LINE OF t_attachment_header,
          attachment_subject       TYPE sood-objdes,
          sood_bytecount           TYPE sood-objlen,
          mail_title               TYPE so_obj_des,
          t_mailtext               TYPE soli_tab,
          wa_mailtext              LIKE LINE OF t_mailtext,
          send_to                  TYPE adr6-smtp_addr,
          sent                     TYPE os_boolean,
          main_text                TYPE bcsy_text,
          lv_status_attr           TYPE bcs_rqst,
          lv_distributionlist_name TYPE soobjinfi1-obj_name.
 
    lv_distributionlist_name = zkl_ldl_bestandsabgleich=>distribution_list.
 
    DATA: lt_dli_tab   TYPE STANDARD TABLE OF sodlienti1,
          lv_stmp_addr TYPE ad_smtpadr.
    FIELD-SYMBOLS: <ls_dli_data> TYPE sodlienti1.
 
 *    DATA: lt_notify TYPE STANDARD TABLE OF zcof_notify.
 *    FIELD-SYMBOLS: <notify> TYPE zcof_notify.
 
    DATA: lv_datum TYPE char10.
 
 *   Betreffzeile
    WRITE sy-datum TO lv_datum DD/MM/YYYY.
    CONCATENATE 'Bestandsabgleich |' lv_datum '-' sy-sysid INTO mail_title SEPARATED BY space.
 
 **   Mailtext aufbereiten
    APPEND ' ' TO main_text. 
    TRY.
 * Create send request
        cl_send_request = cl_bcs=>create_persistent( ).
 
 *       No automatic reply
        lv_status_attr = 'N'.
        cl_send_request->set_status_attributes( i_requested_status = lv_status_attr ).
 
        cl_document = cl_document_bcs=>create_document( i_type    = 'RAW' "#EC NOTEXT
                                                        i_text    = main_text
                                                        i_subject = mail_title ).
 
 * Add attachment to document
 * since the new excelfiles have an 4-character extension .xlsx but the attachment-type only holds 3 charactes .xls,
 * we have to specify the real filename via attachment header
 * Use attachment_type xls to have SAP display attachment with the excel-icon
        CONCATENATE 'Bestandsabgleich_' sy-datum '.XLSX' INTO attachment_subject.
 
        CONCATENATE '&SO_FILENAME=' attachment_subject INTO wa_attachment_header.
        APPEND wa_attachment_header TO t_attachment_header.
 
 * Attachment
        sood_bytecount = bytecount.  " next method expects sood_bytecount instead of any positive integer *sigh*
        cl_document->add_attachment(  i_attachment_type    = 'XLS' "#EC NOTEXT
                                      i_attachment_subject = attachment_subject
                                      i_attachment_size    = sood_bytecount
                                      i_att_content_hex    = t_rawdata
                                      i_attachment_header  = t_attachment_header ).
 
 * add document to send request
        cl_send_request->set_document( cl_document ).
 
 * add recipient(s)
        "Create recipient object
        CALL FUNCTION 'SO_DLI_READ_API1'
          EXPORTING
            dli_name                   = lv_distributionlist_name
            shared_dli                 = 'X'
          TABLES
            dli_entries                = lt_dli_tab
          EXCEPTIONS
            dli_not_exist              = 1
            operation_no_authorization = 2
            parameter_error            = 3
            x_error                    = 4
            OTHERS                     = 5.
 
        LOOP AT lt_dli_tab ASSIGNING <ls_dli_data>.
          lv_stmp_addr = <ls_dli_data>-member_adr.
          cl_recipient = cl_cam_address_bcs=>create_internet_address( lv_stmp_addr ).
 
          "Add recipient object to send request
          cl_send_request->add_recipient( cl_recipient ).
          CLEAR: cl_recipient.
        ENDLOOP.
 
 * Send E-Mail
        sent = cl_send_request->send( i_with_error_screen = 'X' ).
        COMMIT WORK.
      CATCH cx_bcs INTO bcs_exception.
        errortext = bcs_exception->if_message~get_text( ).
        MESSAGE errortext TYPE 'I'.
 
    ENDTRY.
  ENDMETHOD.                    "send_email
 ENDCLASS.

OUTPUT IN GRID

  METHOD create_output_stock_rec_in_alv.
 
    DATA: lo_alv           TYPE REF TO cl_salv_table,
          lo_layout        TYPE REF TO cl_salv_layout, " Benutzerspezifische
          lv_layout_key    TYPE salv_s_layout_key,
          lo_functions     TYPE REF TO cl_salv_functions_list,
          lo_columns       TYPE REF TO cl_salv_columns_table,
          lo_column        TYPE REF TO cl_salv_column_table,
          lo_display       TYPE REF TO cl_salv_display_settings,
          ls_fuer_zelleinf TYPE lvc_s_scol,
          ls_farbcodierung TYPE lvc_s_colo,
          lt_ausgabe       TYPE zabgleich_ldl_t,
          lt_dd03l         TYPE TABLE OF dd03l. " LAyouts aktivieren
 
    lt_ausgabe = it_ausgabe.
    SELECT fieldname FROM dd03l INTO TABLE lt_dd03l WHERE tabname = 'ZABGLEICH_LDL'.
 
    cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
                            CHANGING t_table = lt_ausgabe ).
 
    lv_layout_key-report = sy-repid.
    lo_layout = lo_alv->get_layout( ).
    lo_layout->set_key( lv_layout_key ).
    lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
 
    lo_functions = lo_alv->get_functions( ).
    lo_functions->set_all( abap_true ).
    lo_columns = lo_alv->get_columns( ).
    lo_columns->set_optimize( abap_true ).
 
    LOOP AT lt_ausgabe INTO DATA(ls_ausgabe).
 
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'MANDT'.
      ls_fuer_zelleinf-color-col = 1.
      ls_fuer_zelleinf-color-int = 1.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'MATNR'.
      ls_fuer_zelleinf-color-col = 1.
      ls_fuer_zelleinf-color-int = 1.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'WERKS'.
      ls_fuer_zelleinf-color-col = 1.
      ls_fuer_zelleinf-color-int = 1.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'LGORT'.
      ls_fuer_zelleinf-color-col = 1.
      ls_fuer_zelleinf-color-int = 1.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'MAKTX'.
      ls_fuer_zelleinf-color-col = 1.
      ls_fuer_zelleinf-color-int = 1.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'ERDAT'.
      ls_fuer_zelleinf-color-col = 1.
      ls_fuer_zelleinf-color-int = 1.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
 
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'SAP_LABST'.
      ls_fuer_zelleinf-color-col = 5. "grün
      ls_fuer_zelleinf-color-int = 0.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'SAP_INSME'.
      ls_fuer_zelleinf-color-col = 3.
      ls_fuer_zelleinf-color-int = 0.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'SAP_SPEME'.
      ls_fuer_zelleinf-color-col = 7.
      ls_fuer_zelleinf-color-int = 0.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
 
      CLEAR ls_fuer_zelleinf.
      IF ls_ausgabe-diff_labst > '0'.
        ls_fuer_zelleinf-fname = 'DIFF_LABST'.
        ls_fuer_zelleinf-color-col = 6.
        ls_fuer_zelleinf-color-int = 1.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ELSEIF ls_ausgabe-diff_labst < '0'.
        ls_fuer_zelleinf-fname = 'DIFF_LABST'.
        ls_fuer_zelleinf-color-col = 6.
        ls_fuer_zelleinf-color-int = 0.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ELSE.
        ls_fuer_zelleinf-fname = 'DIFF_LABST'.
        ls_fuer_zelleinf-color-col = 5.
        ls_fuer_zelleinf-color-int = 0.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ENDIF.
 
      IF ls_ausgabe-diff_insme > '0'.
        ls_fuer_zelleinf-fname = 'DIFF_INSME'.
        ls_fuer_zelleinf-color-col = 6.
        ls_fuer_zelleinf-color-int = 1.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ELSEIF ls_ausgabe-diff_insme < '0'.
        ls_fuer_zelleinf-fname = 'DIFF_INSME'.
        ls_fuer_zelleinf-color-col = 6.
        ls_fuer_zelleinf-color-int = 0.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ELSE.
        ls_fuer_zelleinf-fname = 'DIFF_INSME'.
        ls_fuer_zelleinf-color-col = 3.
        ls_fuer_zelleinf-color-int = 0.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ENDIF.
      IF ls_ausgabe-diff_speme > '0'.
        ls_fuer_zelleinf-fname = 'DIFF_SPEME'.
        ls_fuer_zelleinf-color-col = 6.
        ls_fuer_zelleinf-color-int = 1.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ELSEIF ls_ausgabe-diff_speme < '0'.
        ls_fuer_zelleinf-fname = 'DIFF_SPEME'.
        ls_fuer_zelleinf-color-col = 6.
        ls_fuer_zelleinf-color-int = 0.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ELSE.
        ls_fuer_zelleinf-fname = 'DIFF_SPEME'.
        ls_fuer_zelleinf-color-col = 7.
        ls_fuer_zelleinf-color-int = 0.
        APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
      ENDIF.
 
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'LDL_LABST'.
      ls_fuer_zelleinf-color-col = 5.
      ls_fuer_zelleinf-color-int = 0.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
 
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'LDL_INSME'.
      ls_fuer_zelleinf-color-col = 3.
      ls_fuer_zelleinf-color-int = 0.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
 
      CLEAR ls_fuer_zelleinf.
      ls_fuer_zelleinf-fname = 'LDL_SPEME'.
      ls_fuer_zelleinf-color-col = 7.
      ls_fuer_zelleinf-color-int = 0.
      APPEND ls_fuer_zelleinf  TO ls_ausgabe-farbe.
 
      MODIFY lt_ausgabe FROM ls_ausgabe.
 
    ENDLOOP.
 
    lo_columns->set_color_column( 'FARBE' ).
 
    lo_display = lo_alv->get_display_settings( ).
    lo_display->set_horizontal_lines( abap_true ).
    lo_display->set_vertical_lines( cl_salv_display_settings=>true ).
    lo_display->set_list_header( value = TEXT-001 ).
    lo_display->set_striped_pattern( abap_true ).
 
    DATA: gr_events TYPE REF TO zkl_ldl_bestandsabgleich.
    DATA: lr_events TYPE REF TO cl_salv_events_table.
    lr_events = lo_alv->get_event( ).
    CREATE OBJECT gr_events.
    SET HANDLER gr_events->on_double_click FOR lr_events.
 
    lo_alv->display( ).
  ENDMETHOD.

Quellen / Credits / Copyrights