[ABAP] Daten zum Material anzeigen

* siehe auch Report RMMMTREE
PARAMETERS: p_mat TYPE matnr.

START-OF-SELECTION.

* Allgemeine Materialdaten
  SELECT
    FROM mara
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_mara).

* Werksdaten zum Material
  SELECT
    FROM marc
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_marc).

  IF lines( it_marc ) > 0.
* Lagerortdaten zum Material
    SELECT
      FROM mard AS m
      FIELDS *
      FOR ALL ENTRIES IN @it_marc
      WHERE m~matnr EQ @p_mat
        AND m~werks EQ @it_marc-werks
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_mard).
  ENDIF.

* Materialkurztexte
  SELECT
    FROM makt
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_makt).

* STXD SAPscript Text-Datei Header
  SELECT
    FROM stxh
    FIELDS *
    WHERE tdobject EQ 'MATERIAL'
      AND tdname EQ @( |{ p_mat WIDTH = 18 ALPHA = IN }| )
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_stxh).
      
* Reservierung/Sekundärbedarf
  SELECT
    FROM resb
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_resb).

* Bestellanforderung
  SELECT
    FROM eban
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_eban).

* Einkaufsbelegposition
  SELECT
    FROM ekpo
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_ekpo).

  IF lines( it_ekpo ) > 0.
* Einkaufsbelegkopf
    SELECT
      FROM ekko AS e
      FIELDS *
      FOR ALL ENTRIES IN @it_ekpo
      WHERE e~ebeln EQ @it_ekpo-ebeln
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_ekko).
  ENDIF.

* Materialstamm: Standardfelder und spezielle Retail-Felder
  SELECT
    FROM maw1
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_maw1).

  IF lines( it_makt ) > 0.
* Materialstamm-Texte je Mengeneinheit und Text-Id
    SELECT
      FROM mamt AS m
      FIELDS *
      FOR ALL ENTRIES IN @it_makt
      WHERE m~matnr EQ @p_mat
        AND m~spras EQ @it_makt-spras
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_mamt).
  ENDIF.

* Mengeneinheiten zum Material
  SELECT
    FROM marm
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_marm).

  IF lines( it_marm ) > 0.
* Europäische Artikelnummern zum Material
    SELECT
      FROM mean AS m
      FIELDS *
      FOR ALL ENTRIES IN @it_marm
      WHERE m~matnr EQ @p_mat
        AND m~meinh EQ @it_marm-meinh
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_mean).

* Zuordnung von Layoutbausteinen zu Materialien
    SELECT
      FROM malg AS m
      FIELDS *
      FOR ALL ENTRIES IN @it_marm
      WHERE matnr EQ @p_mat
        AND m~meinh EQ @it_marm-meinh
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_malg).
  ENDIF.

* Verkaufsdaten zum Material
  SELECT
    FROM mvke
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_mvke).

* Materialbewertung
  SELECT
    FROM mbew
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_mbwe).

* Materialdaten pro Lagernummer
  SELECT
    FROM mlgn
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_mlgn).

  IF lines( it_mlgn ) > 0.
* Materialdaten pro Lagertyp
    SELECT
      FROM mlgt AS m
      FIELDS *
      FOR ALL ENTRIES IN @it_mlgn
      WHERE m~matnr EQ @p_mat
        AND m~lgnum EQ @it_mlgn-lgnum
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_mlgt).
  ENDIF.

* Einkaufsinfosatz - allgemeine Daten
  SELECT
    FROM eina
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_eina).

  IF lines( it_eina ) > 0.
* Einkaufsinfosatz - Einkaufsorganisationsdaten
    SELECT
      FROM eine AS e
      FIELDS *
      FOR ALL ENTRIES IN @it_eina
      WHERE e~infnr EQ @it_eina-infnr
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_eine).
  ENDIF.

* Materialstammstatus
  SELECT
    FROM msta
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_msta).

* noch offene Materialstaemme
  SELECT
    FROM moff
    FIELDS *
    WHERE matnr EQ @p_mat
      ORDER BY statm
      INTO TABLE @DATA(it_moff).

* Planauftrag
  SELECT
    FROM plaf
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_plaf).

* Kopfsatz für Bedarfssummensätze im MRP
  SELECT
    FROM rqhd
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_rqhd).

* Positionssatz für Bedarfssummensätze im MRP
  SELECT
    FROM rqit
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_rqit).

* Material (Konditionssätze)
  SELECT
    FROM a004
    FIELDS *
    WHERE matnr EQ @p_mat
    ORDER BY PRIMARY KEY
    INTO TABLE @DATA(it_a004).

  IF lines( it_a004 ) > 0.
* Konditionen (Kopf)
    SELECT
      FROM konh
      FIELDS *
      FOR ALL ENTRIES IN @it_a004
      WHERE knumh EQ @it_a004-knumh
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_konh).

* Konditionen (Position)
    SELECT
      FROM konp
      FIELDS *
      FOR ALL ENTRIES IN @it_a004
      WHERE knumh EQ @it_a004-knumh
      ORDER BY PRIMARY KEY
      INTO TABLE @DATA(it_konp).
  ENDIF.

  cl_demo_output=>next_section( 'Materialstamm' ).
  cl_demo_output=>write_data( value = it_mara name = 'MARA (Allgemeine Materialdaten)' ).
  cl_demo_output=>write_data( value = it_marc name = 'MARC (Werksdaten zum Material)' ).
  cl_demo_output=>write_data( value = it_mard name = 'MARD (Lagerortdaten zum Material)').
  cl_demo_output=>next_section( 'Texte' ).
  cl_demo_output=>write_data( value = it_makt name = 'MAKT (Materialkurztexte)').
  cl_demo_output=>write_data( value = it_stxh name = 'STXH (STXD SAPscript Text-Datei Header)').
  cl_demo_output=>next_section( 'Einkauf' ).
  cl_demo_output=>write_data( value = it_resb name = 'RESB (Reservierung/Sekundärbedarf)').
  cl_demo_output=>write_data( value = it_eban name = 'EBAN (Bestellanforderung)').
  cl_demo_output=>write_data( value = it_ekko name = 'EKKO (Einkaufsbelegkopf)').
  cl_demo_output=>write_data( value = it_ekpo name = 'EKPO (Einkaufsbelegposition)').
  cl_demo_output=>next_section( 'Infosatz' ).
  cl_demo_output=>write_data( value = it_eina name = 'EINA (Einkaufsinfosatz - allgemeine Daten)').
  cl_demo_output=>write_data( value = it_eine name = 'EINE (Einkaufsinfosatz - Einkaufsorganisationsdaten)').
  cl_demo_output=>next_section( 'Konditionen' ).
  cl_demo_output=>write_data( value = it_a004 name = 'A004 (Material (Konditionssätze)').
  cl_demo_output=>write_data( value = it_konh name = 'KONH (Konditionen (Kopf))').
  cl_demo_output=>write_data( value = it_konp name = 'KONP (Konditionen (Position))').
  cl_demo_output=>next_section( 'Bewertung' ).
  cl_demo_output=>write_data( value = it_mbwe name = 'MBEW (Materialbewertung)').
  cl_demo_output=>next_section( 'Verkaufsdaten' ).
  cl_demo_output=>write_data( value = it_mvke name = 'MVKE (Verkaufsdaten zum Material)').
  cl_demo_output=>next_section( 'Mengeneinheiten' ).
  cl_demo_output=>write_data( value = it_marm name = 'MARM (Mengeneinheiten zum Material)').
  cl_demo_output=>next_section( 'Materialdaten' ).
  cl_demo_output=>write_data( value = it_mlgn name = 'MLGN (Materialdaten pro Lagernummer)').
  cl_demo_output=>write_data( value = it_mlgt name = 'MLGT (Materialdaten pro Lagertyp)').
  cl_demo_output=>next_section( 'Planaufträge' ).
  cl_demo_output=>write_data( value = it_plaf name = 'PLAF (Planauftrag)').
  cl_demo_output=>next_section( 'MRP' ).
  cl_demo_output=>write_data( value = it_rqhd name = 'RQHD (Kopfsatz für Bedarfssummensätze im MRP)').
  cl_demo_output=>write_data( value = it_rqit name = 'RQIT (Positionssatz für Bedarfssummensätze im MRP)').
  cl_demo_output=>next_section( 'Materialstammstatus' ).
  cl_demo_output=>write_data( value = it_msta name = 'MSTA (Materialstammstatus)').
  cl_demo_output=>write_data( value = it_moff name = 'MOFF (noch offene Materialstaemme)').
  cl_demo_output=>next_section( 'Sonstges' ).
  cl_demo_output=>write_data( value = it_maw1 name = 'MAW1 (Materialstamm: Standardfelder und spezielle Retail-Felder)').
  cl_demo_output=>write_data( value = it_mamt name = 'MAMT (Materialstamm-Texte je Mengeneinheit und Text-Id)').
  cl_demo_output=>write_data( value = it_mean name = 'MEAN (Europäische Artikelnummern zum Material)').
  cl_demo_output=>write_data( value = it_malg name = 'MALG (Zuordnung von Layoutbausteinen zu Materialien)').

*   HTML-Code vom Demo-Output holen
  DATA(lv_html) = cl_demo_output=>get( ).

*   Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING title       = 'Material'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).

* leere Standard-Toolbar ausblenden
  cl_abap_list_layout=>suppress_toolbar( ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.