*---------------------------------------------------------------------*
*       Z _ B J H _ B A P I _ M A T E R I A L _ S A V E D A T A       *
*                                                                     *
*                  Autor: Bernd Haase (BJH Software)                  *
*---------------------------------------------------------------------*
* Beispielprogramm zum Ansprung des BAPI_MATERIAL_SAVEDATA.           *
* In diesem Programm wird eine Materialnummer ale referenz vorgegeben,*
* die auf eine neue kopiert werden soll. Zusätzlich können noch ein   *
* Werk und ein Lagerort mitangegeben werden, welche ebenfalls dann    *
* sofort aufgebaut werden. Sollte zum Werk eine Bewertung vorhanden   *
* sein, wird diese auch kopiert. Gleiches gilt für Maßeinheiten, Mate-*
* rialkurztexte und auch Langtexte in allen Sprachen. Für alle anderen*
* Strukturen sind die Unterprogramme zum Füllen der BAPI-Struktur vor-*
* handen, jedoch werden sie nicht angesprungen                        *
*---------------------------------------------------------------------*
* FB READ_TEXT, Warnstufe BAPI Aufruf, Tbda2, Selection-screen output *
*---------------------------------------------------------------------*
* 19.05.2004 BHaa: Programm erstellt aus Funktion Werteabtausch       *
*---------------------------------------------------------------------*
REPORT  z_bjh_bapi_material_savedata.

INCLUDE <icon>.

* Stammdatentabellen
TABLES:
 makt,  "Materialkurztexte
 mara,  "Allgemeine Materialdaten
 marc,  "Werksdaten zum Material
 mard,  "Lagerortdaten zum Material
 marm,  "Mengeneinheiten zum Material
 mbew,  "Materialbewertung
 mlan,  "Steuerklassifikation zum Material
 mlgn,  "Materialdaten pro Lagernummer
 mlgt,  "Materialdaten pro Lagertyp
 mvke,  "Verkaufsdaten zum Material
 stxh,  "STXD SAPscript Text-Datei Header
 tbda2. "ALE-Nachricht aktiv           6 Stellen im Programm

DATA:
 wa_makt LIKE makt,
 wa_mara LIKE mara,
 wa_marc LIKE marc,
 wa_mard LIKE mard,
 wa_marm LIKE marm,
 wa_mbew LIKE mbew,
 wa_mlan LIKE mlan,
 wa_mlgn LIKE mlgn,
 wa_mlgt LIKE mlgt,
 wa_mvke LIKE mvke,

 itab_makt LIKE SORTED TABLE OF makt WITH UNIQUE KEY matnr spras,
 itab_marm LIKE SORTED TABLE OF marm WITH UNIQUE KEY matnr meinh,
 itab_mlan LIKE SORTED TABLE OF mlan WITH UNIQUE KEY matnr aland.

DATA:
 wa_sichten      LIKE marc-pstat,
 wa_ale_matmas   LIKE tbda2-active,
 zw_text(120)    TYPE c,
 bapi_starten(1) TYPE c.

DATA:
 anzahl(6) TYPE n,
* Anzahl der einzelnen Warnstufen nach BAPI-Aufruf
 anzahl_rot    LIKE anzahl,
 anzahl_gelb   LIKE anzahl,
 anzahl_gruen  LIKE anzahl.

************************
* Fließtext / Langtext *
************************
DATA:
 t_thead LIKE thead OCCURS 1 WITH HEADER LINE,

 BEGIN OF t_lines OCCURS 0.
       INCLUDE STRUCTURE tline.
DATA:
 END OF t_lines,

* Anzeigestruktur für die Ausgabe
 wa_lines LIKE t_lines,

* Rückgabewert, wie der FB den Text bearbeitet hat
 fb_aktion(1) TYPE c,

 BEGIN OF wa_mltx,
   tdname   LIKE thead-tdname,
   tdid     LIKE thead-tdid,
   spras    LIKE thead-tdspras,
   tdformat LIKE tline-tdformat,
   zeile    LIKE tline-tdline,
 END OF wa_mltx,
 itab_mltx LIKE TABLE OF wa_mltx.

*******************
* BAPI Strukturen *
*******************
DATA:
 wa_bapi_basis  LIKE bapimathead,
 wa_bapi_mara   LIKE bapi_mara,
 wa_bapi_mara_x LIKE bapi_marax,
 wa_bapi_marc   LIKE bapi_marc,
 wa_bapi_marc_x LIKE bapi_marcx,
 wa_bapi_mard   LIKE bapi_mard,
 wa_bapi_mard_x LIKE bapi_mardx,
 wa_bapi_mbew   LIKE bapi_mbew,
 wa_bapi_mbew_x LIKE bapi_mbewx,
 wa_bapi_mlgn   LIKE bapi_mlgn,
 wa_bapi_mlgn_x LIKE bapi_mlgnx,
 wa_bapi_mvke   LIKE bapi_mvke,
 wa_bapi_mvke_x LIKE bapi_mvkex,
 wa_bapi_mlgt   LIKE bapi_mlgt,
 wa_bapi_mlgt_x LIKE bapi_mlgtx,
 wa_bapi_return LIKE bapiret2.

*****************
* BAPI Tabellen *
*****************
DATA:
 itab_prot LIKE TABLE OF wa_bapi_return.

DATA:
 BEGIN OF itab_bapi_makt OCCURS 0.
       INCLUDE STRUCTURE bapi_makt.
DATA:
 END OF itab_bapi_makt,

 BEGIN OF itab_bapi_marm OCCURS 0.
       INCLUDE STRUCTURE bapi_marm.
DATA:
 END OF itab_bapi_marm,

 BEGIN OF itab_bapi_marm_x OCCURS 0.
       INCLUDE STRUCTURE bapi_marmx.
DATA:
 END OF itab_bapi_marm_x,

 BEGIN OF itab_bapi_mltx OCCURS 0.
       INCLUDE STRUCTURE bapi_mltx.
DATA:
 END OF itab_bapi_mltx,

 BEGIN OF itab_bapi_mlan OCCURS 0.
       INCLUDE STRUCTURE bapi_mlan.
DATA:
 END OF itab_bapi_mlan,

 BEGIN OF itab_bapi_return OCCURS 0.
       INCLUDE STRUCTURE bapi_matreturn2.
DATA:
 END OF itab_bapi_return.

*---------------------------------------------------------------------*
*                                                                     *
*                 A u s w a h l b i l d s c h i r m                   *
*                                                                     *
*---------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK 901 WITH FRAME TITLE text-901.
PARAMETERS:
 pm_matnr LIKE mara-matnr,
 pm_werks LIKE marc-werks,
 pm_lgort LIKE mard-lgort.
SELECTION-SCREEN: END OF BLOCK 901.

SELECTION-SCREEN: BEGIN OF BLOCK 902 WITH FRAME TITLE text-902.
PARAMETERS:
 pmmatneu LIKE mara-matnr.
SELECTION-SCREEN: END OF BLOCK 902.

* Aktionsrichtung und Fehleranzeigetyp für BAPI-Lauf bestimmen.
SELECTION-SCREEN: BEGIN OF BLOCK a3 WITH FRAME TITLE text-903.
PARAMETERS:
* Aktion. Testlauf mit Statistik oder Echtlauf mit Änderungen
 pmx_test TYPE c RADIOBUTTON GROUP grp3 DEFAULT 'X',
 pmx_echt TYPE c RADIOBUTTON GROUP grp3,
* ALE Nachrichten für Matmas
* Nachrichten IDoc aktiv
 pmalean  TYPE c RADIOBUTTON GROUP grp5 MODIF ID ale,
* Nachrichten IDoc nicht aktiv
 pmaleaus TYPE c RADIOBUTTON GROUP grp5 MODIF ID ale,
* Warnstufenanzeige
 pmx_rot  TYPE c RADIOBUTTON GROUP grp4,
 pmx_gelb TYPE c RADIOBUTTON GROUP grp4 DEFAULT 'X',
 pmxgruen TYPE c RADIOBUTTON GROUP grp4.
SELECTION-SCREEN: END OF BLOCK a3.

INITIALIZATION.
* ALE-Nachricht für Matmas-IDocs prüfen, ob aktiv oder nicht
 PERFORM upro-ale_lesen.

* PBO-Modul für Selektions-Bildschirm. Nachrichtensteuerung
AT SELECTION-SCREEN OUTPUT.
 PERFORM upro-ale_bildschirm.

***********************************************************************
*                                                                     *
*                     P R O G R A M M S T A R T                       *
*                                                                     *
***********************************************************************
START-OF-SELECTION.

* Standard ist, daß der Bapi nicht angestossen wird
 MOVE 'N' TO bapi_starten.

* Material abfragen
 SELECT SINGLE * FROM mara INTO wa_mara
 WHERE matnr = pm_matnr.
 IF sy-subrc <> 0.
* falsche Eingabe. Fehlermeldung mit roter Ampel
   WRITE: / icon_remove_from_selection,
            'Materialnummer', pm_matnr, 'ist unbekannt'.
 ELSE.
   MOVE 'K' TO wa_sichten.

* schonmal die Variablen für die allgemeinen Materialdaten aufbauen
   PERFORM upro-bapi_mara USING wa_sichten.

   IF pm_werks IS INITIAL.
* Kein Werk eingegeben, Bapi kann gestartet werden, es würden nur die
* Materialdaten aufgebaut werden (kopiert).
     MOVE 'J' TO bapi_starten.
   ELSE.
* Material mit Werksbezug abfragen
     SELECT SINGLE * FROM marc INTO wa_marc
     WHERE matnr = pm_matnr
     AND   werks = pm_werks.
     IF sy-subrc <> 0.
* keine Einträge vorhanden. Entweder ist das Material nicht gepflegt
* oder das Werk ist falsch eingegeben. Die genaue Feherlursache wäre
* zwar über die T001W ermittelbar, dient aber nicht dem eigentlichen
* Zweck dieses Beispielprogrammes
       WRITE: / icon_remove_from_selection,
                'Materialnummer', pm_matnr,
                'im Werk', pm_werks, 'ist unbekannt'.
     ELSE.
* Sichten für die neuen erweitern
       CONCATENATE wa_sichten
                   wa_marc-pstat
                   INTO wa_sichten.
* ebenfalls schonmal wieder die Variablen auf die für den Bapi kopieren
       PERFORM upro-bapi_marc USING wa_sichten.

       IF wa_sichten CA 'BG'.
* Eine Bewertung liegt vor. Die erste gültige Bewertung zum Material
* lesen. Der Einfachheit halber wurde auf prüfen der Bewertungsebene
* (Tabelle TCURM) verzichtet und als Bewertungskreis-Einstellung 'Werk'
* vorausgesetzt.
         SELECT SINGLE * FROM mbew INTO wa_mbew
         WHERE matnr = pm_matnr
         AND   bwkey = pm_werks.
         IF sy-subrc <> 0.
* überhaupt keine Bewertung gefunden, Bapi-Ausführung zurücksetzen
           WRITE: / icon_remove_from_selection,
                    'Keine Bewertung zu Materialnummer', pm_matnr,
                    'im Werk', pm_werks.
           MOVE 'N' TO bapi_starten.
         ELSE.
* Felder der Bewertung bereitstellen
           PERFORM upro-bapi_mbew USING wa_sichten.
         ENDIF.
       ENDIF.

       IF pm_lgort IS INITIAL.
* Kein Lagerort eingeben
         MOVE 'J' TO bapi_starten.
       ELSE.
* Material zum Lagerort abfragen
         SELECT SINGLE * FROM mard INTO wa_mard
         WHERE matnr = pm_matnr
         AND   werks = pm_werks
         AND   lgort = pm_lgort.
         IF sy-subrc <> 0.
           WRITE: / icon_remove_from_selection,
                    'Materialnummer', pm_matnr,
                    'im Werk', pm_werks,
                    'zum Lagerort', pm_lgort, 'ist unbekannt'.
         ELSE.
           MOVE 'J' TO bapi_starten.

           CONCATENATE wa_sichten
                       mard-pstat
                       INTO wa_sichten.

           PERFORM upro-bapi_mard USING wa_sichten.
         ENDIF.
       ENDIF.
     ENDIF.
   ENDIF.
 ENDIF.

 IF bapi_starten = 'J'.
   PERFORM upro-lese_marm.
   PERFORM upro-bapi_marm.
   PERFORM upro-lese_kurztexte.
   PERFORM upro-bapi_makt.
   PERFORM upro-lese_langtexte.
   PERFORM upro-bapi_mltx.
   PERFORM upro-bapi_mlan.

   IF pmx_echt = 'X'.
* Protokollierung und ALE-Nachrichten aktivieren oder deaktivieren
     PERFORM upro-ale_aendern.

     PERFORM upro-bapi_material_savedata.

* ALE-Nachrichten in den Ursprungszustand zurücksetzen
     PERFORM upro-ale_original.

     PERFORM upro-echt_ergebnis.
   ENDIF.
 ENDIF.

END-OF-SELECTION.
 EXIT.

***********************************************************************
*
*                         I N C L U D E S
*
***********************************************************************
* keine Includes

*---------------------------------------------------------------------*
*                         A L E _ L E S E N                           *
*---------------------------------------------------------------------*
* Nachrichtensteuerung. Prüfen, ob für das IDoc MATMAS eine Nachrich- *
* tensteuerung aktiv ist. Aktuellen Zustand speichern und für die     *
* Anzeige am Bildschirm (Pushbutton) komplementär (XOR-Logik) die Vor-*
* belegung aufbereiten.                                               *
*---------------------------------------------------------------------*
FORM upro-ale_lesen.

* ALE-Nachricht für Matmas-IDocs prüfen, ob aktiv oder nicht
 SELECT SINGLE active FROM tbda2 INTO wa_ale_matmas
 WHERE mestyp = 'MATMAS'.
 IF sy-subrc <> 0.
   MOVE '-' TO wa_ale_matmas.
 ELSE.
* XOR-Verknüfung, das Gegenteil des aktuellen Status standardmäßig
* vorbesetzen
   CASE wa_ale_matmas.
     WHEN 'X'.
       MOVE ' ' TO pmalean.
       MOVE 'X' TO pmaleaus.
     WHEN ' '.
       MOVE 'X' TO pmalean.
       MOVE ' ' TO pmaleaus.
   ENDCASE.
 ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*                      A L E _ B I L D S C H I R M                    *
*---------------------------------------------------------------------*
* Sollte der Zugriff auf die Nachrichtensteuerungstabelle nicht       *
* erfolgreich gewesen sein, so die Anzeige-Pushbutton zum Aktivieren  *
* oder Deaktivieren unsichtbar schalten.                              *
*---------------------------------------------------------------------*
FORM upro-ale_bildschirm.

 IF wa_ale_matmas = '-'.
* Zugriff auf die Nachrichtendatei für das IDoc Matmas war nicht
* erfolgreich, somit Felder dafür auf unsichtbar setzen
   LOOP AT SCREEN.
     IF screen-group1 = 'ALE'.
       screen-invisible = 1.
       MODIFY SCREEN.
     ENDIF.
   ENDLOOP.
 ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*                        A L E _ A E N D E R N                        *
*---------------------------------------------------------------------*
* vor dem Material ändern (BAPI-Aufruf): Nachrichtensteuerung gemäß   *
* Auswahl der Parameter aktivieren oder deaktivieren.                 *
*---------------------------------------------------------------------*
FORM upro-ale_aendern.

 CASE wa_ale_matmas.
   WHEN 'X'.
     IF pmaleaus = 'X'.
       UPDATE tbda2
       SET    active = ' '
       WHERE  mestyp = 'MATMAS'.
     ENDIF.
   WHEN ' '.
     IF pmalean = 'X'.
       UPDATE tbda2
       SET    active = 'X'
       WHERE  mestyp = 'MATMAS'.
     ENDIF.
 ENDCASE.

ENDFORM.

*---------------------------------------------------------------------*
*                       A L E _ O R I G I N A L                       *
*---------------------------------------------------------------------*
* nach der Materialänderung: Nachrichtensteuerung wieder in den Origi-*
* nalstand zurücksetzen                                               *
*---------------------------------------------------------------------*
FORM upro-ale_original.

 CASE wa_ale_matmas.
   WHEN 'X'.
     IF pmaleaus = 'X'.
       UPDATE tbda2
       SET    active = 'X'
       WHERE  mestyp = 'MATMAS'.
     ENDIF.
   WHEN ' '.
     IF pmalean = 'X'.
       UPDATE tbda2
       SET    active = ' '
       WHERE  mestyp = 'MATMAS'.
     ENDIF.
 ENDCASE.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM upro-lese_marm                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM upro-lese_marm.

 SELECT * FROM marm
 INTO TABLE itab_marm
 WHERE matnr = pm_matnr.

ENDFORM.

*---------------------------------------------------------------------*
*                     L E S E _ K U R Z T E X T E                     *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
FORM upro-lese_kurztexte.

 SELECT * FROM makt
 INTO TABLE itab_makt
 WHERE matnr = pm_matnr.

ENDFORM.

*---------------------------------------------------------------------*
*                     L E S E _ L A N G T E X T E                     *
*---------------------------------------------------------------------*
* zum gewünschten Material nun noch alle Texte suchen und in einer    *
* internen Tabelle vorhalten                                          *
*---------------------------------------------------------------------*
FORM upro-lese_langtexte.

 CLEAR:   itab_mltx, wa_mltx.
 REFRESH: itab_mltx.

* alle Textarten in allen Sprachen
 SELECT tdobject tdname tdid tdspras FROM stxh
 INTO CORRESPONDING FIELDS OF TABLE t_thead
 WHERE tdobject = 'MATERIAL'
 AND   tdname   = pm_matnr.

 IF sy-subrc <> 0.
* keine Texte vorhanden
   CLEAR: t_lines.
 ELSE.
* jeden einzelnen Text bearbeiten und deren Zeilen über einen Funktions-
* baustein einlesen. Alle Texte sind auf Materialebene vorhanden !
   LOOP AT t_thead.
     CALL FUNCTION 'READ_TEXT'
          EXPORTING
               id       = t_thead-tdid
               language = t_thead-tdspras
               name     = t_thead-tdname
               object   = t_thead-tdobject
          TABLES
               lines    = t_lines.

     LOOP AT t_lines INTO wa_lines.
* die einzelnen Textzeilen in interne Tabelle kopieren
       MOVE t_thead-tdname TO wa_mltx-tdname.
       MOVE t_thead-tdid TO wa_mltx-tdid.
       MOVE t_thead-tdspras TO wa_mltx-spras.
       MOVE wa_lines-tdformat TO wa_mltx-tdformat.
       MOVE wa_lines-tdline TO wa_mltx-zeile.
       APPEND wa_mltx TO itab_mltx.
     ENDLOOP.
   ENDLOOP.
 ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*                         B A P I _ M A K T                           *
*---------------------------------------------------------------------*
* Struktur und interne Tabelle für die Kurztexte im BAPI auffüllen.   *
* Im BAPI werden die Kurztexte aller Sprachen für dieses Material     *
* berücksichtigt.                                                     *
*---------------------------------------------------------------------*
FORM upro-bapi_makt.

 CLEAR: itab_bapi_makt. REFRESH: itab_bapi_makt.

 LOOP AT itab_makt INTO wa_makt
 WHERE matnr = wa_mara-matnr.
*   MOVE MAKT-MANDT TO WA_.
*   MOVE MAKT-MATNR TO WA_.
   MOVE wa_makt-spras TO itab_bapi_makt-langu.
   MOVE wa_makt-maktx TO itab_bapi_makt-matl_desc.
*   MOVE MAKT-MAKTG TO WA_.

*   MOVE ??? TO WA_BAPI_MAKT-LANGU_ISO.
*   MOVE ??? TO WA_BAPI_MAKT-DEL_FLAG.

   APPEND itab_bapi_makt.
 ENDLOOP.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M A R A                          *
*---------------------------------------------------------------------*
* Struktur für die allgemeinen Materialdaten füllen. Die internen     *
* Tabellen zum Material (Kurz- und Langtexte, Maßeinheiten und Steuer-*
* schlüssel) werden mitaufgebaut.
*---------------------------------------------------------------------*
* =>] p_material_sichten: 'K'= Grunddatensicht                        *
*---------------------------------------------------------------------*
FORM upro-bapi_mara
    USING p_material_sichten.

 CLEAR: wa_bapi_mara, wa_bapi_mara_x.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_mara TO wa_bapi_mara.

 CLEAR: wa_bapi_basis.

* Basiskopfdaten besetzen und die neue Materialnummer einsetzen
 MOVE pmmatneu TO wa_bapi_basis-material.
 MOVE wa_mara-mbrsh TO wa_bapi_basis-ind_sector.
 MOVE wa_mara-mtart TO wa_bapi_basis-matl_type.

* Sicht "Grunddaten" zulässig schalten. Weitere Sichten werden
* individuell in den Unterebenen dazugeschaltet
 IF p_material_sichten CS 'K'.
   MOVE 'X' TO wa_bapi_basis-basic_view.
 ENDIF.

* MOVE wa_MARA-MANDT TO WA_.
* MOVE wa_MARA-ERSDA TO WA_.
* MOVE wa_MARA-ERNAM TO WA_.
* MOVE wa_MARA-LAEDA TO WA_.
* MOVE wa_MARA-AENAM TO WA_.
* MOVE wa_MARA-VPSTA TO WA_.
* MOVE wa_MARA-PSTAT TO WA_.
 MOVE wa_mara-lvorm TO wa_bapi_mara-del_flag.
 MOVE wa_mara-matkl TO wa_bapi_mara-matl_group.
 MOVE wa_mara-bismt TO wa_bapi_mara-old_mat_no.
 MOVE wa_mara-meins TO wa_bapi_mara-base_uom.
 MOVE wa_mara-bstme TO wa_bapi_mara-po_unit.
 MOVE wa_mara-zeinr TO wa_bapi_mara-document.
 MOVE wa_mara-zeiar TO wa_bapi_mara-doc_type.
 MOVE wa_mara-zeivr TO wa_bapi_mara-doc_vers.
 MOVE wa_mara-zeifo TO wa_bapi_mara-doc_format.
 MOVE wa_mara-aeszn TO wa_bapi_mara-doc_chg_no.
 MOVE wa_mara-blatt TO wa_bapi_mara-page_no.
 MOVE wa_mara-blanz TO wa_bapi_mara-no_sheets.
 MOVE wa_mara-ferth TO wa_bapi_mara-prod_memo.
 MOVE wa_mara-formt TO wa_bapi_mara-pageformat.
 MOVE wa_mara-groes TO wa_bapi_mara-size_dim.
 MOVE wa_mara-wrkst TO wa_bapi_mara-basic_matl.
 MOVE wa_mara-normt TO wa_bapi_mara-std_descr.
 MOVE wa_mara-labor TO wa_bapi_mara-dsn_office.
 MOVE wa_mara-ekwsl TO wa_bapi_mara-pur_valkey.
* MOVE wa_MARA-BRGEW TO WA_.
 MOVE wa_mara-ntgew TO wa_bapi_mara-net_weight.
 MOVE wa_mara-gewei TO wa_bapi_mara-unit_of_wt.
* MOVE wa_MARA-VOLUM TO WA_.
* MOVE wa_MARA-VOLEH TO WA_.
 MOVE wa_mara-behvo TO wa_bapi_mara-container.
 MOVE wa_mara-raube TO wa_bapi_mara-stor_conds.
 MOVE wa_mara-tempb TO wa_bapi_mara-temp_conds.
* MOVE wa_MARA-DISST TO WA_.
 MOVE wa_mara-tragr TO wa_bapi_mara-trans_grp.
 MOVE wa_mara-stoff TO wa_bapi_mara-haz_mat_no.
 MOVE wa_mara-spart TO wa_bapi_mara-division.
 MOVE wa_mara-kunnr TO wa_bapi_mara-competitor.
* MOVE wa_MARA-EANNR TO WA_.
 MOVE wa_mara-wesch TO wa_bapi_mara-qty_gr_gi.
 MOVE wa_mara-bwvor TO wa_bapi_mara-proc_rule.
 MOVE wa_mara-bwscl TO wa_bapi_mara-sup_source.
 MOVE wa_mara-saiso TO wa_bapi_mara-season.
 MOVE wa_mara-etiar TO wa_bapi_mara-label_type.
 MOVE wa_mara-etifo TO wa_bapi_mara-label_form.
* MOVE wa_MARA-ENTAR TO WA_.
* MOVE wa_MARA-EAN11 TO WA_.
* MOVE wa_MARA-NUMTP TO WA_.
* MOVE wa_MARA-LAENG TO WA_.
* MOVE wa_MARA-BREIT TO WA_.
* MOVE wa_MARA-HOEHE TO WA_.
* MOVE wa_MARA-MEABM TO WA_.
 MOVE wa_mara-prdha TO wa_bapi_mara-prod_hier.
* MOVE wa_MARA-AEKLK TO WA_.
 MOVE wa_mara-cadkz TO wa_bapi_mara-cad_id.
 MOVE wa_mara-qmpur TO wa_bapi_mara-qm_procmnt.
 MOVE wa_mara-ergew TO wa_bapi_mara-allowed_wt.
 MOVE wa_mara-ergei TO wa_bapi_mara-pack_wt_un.
 MOVE wa_mara-ervol TO wa_bapi_mara-allwd_vol.
 MOVE wa_mara-ervoe TO wa_bapi_mara-pack_vo_un.
 MOVE wa_mara-gewto TO wa_bapi_mara-wt_tol_lt.
 MOVE wa_mara-volto TO wa_bapi_mara-vol_tol_lt.
 MOVE wa_mara-vabme TO wa_bapi_mara-var_ord_un.
* MOVE wa_MARA-KZREV TO WA_.
* MOVE wa_MARA-KZKFG TO WA_.
 MOVE wa_mara-xchpf TO wa_bapi_mara-batch_mgmt.
 MOVE wa_mara-vhart TO wa_bapi_mara-sh_mat_typ.
 MOVE wa_mara-fuelg TO wa_bapi_mara-fill_level.
 MOVE wa_mara-stfak TO wa_bapi_mara-stack_fact.
 MOVE wa_mara-magrv TO wa_bapi_mara-mat_grp_sm.
 MOVE wa_mara-begru TO wa_bapi_mara-authoritygroup.
* MOVE wa_MARA-DATAB TO WA_.
* MOVE wa_MARA-LIQDT TO WA_.
* MOVE wa_MARA-SAISJ TO WA_.
* MOVE wa_MARA-PLGTP TO WA_.
* MOVE wa_MARA-MLGUT TO WA_.
* MOVE wa_MARA-EXTWG TO WA_.
* MOVE wa_MARA-SATNR TO WA_.
* MOVE wa_MARA-ATTYP TO WA_.
* MOVE wa_MARA-KZKUP TO WA_.
* MOVE wa_MARA-KZNFM TO WA_.
* MOVE wa_MARA-PMATA TO WA_.
 MOVE wa_mara-mstae TO wa_bapi_mara-pur_status.
 MOVE wa_mara-mstav TO wa_bapi_mara-sal_status.
 MOVE wa_mara-mstde TO wa_bapi_mara-pvalidfrom.
 MOVE wa_mara-mstdv TO wa_bapi_mara-svalidfrom.
* MOVE wa_MARA-TAKLV TO WA_.
 MOVE wa_mara-rbnrm TO wa_bapi_mara-catprofile.
 MOVE wa_mara-mhdrz TO wa_bapi_mara-minremlife.
 MOVE wa_mara-mhdhb TO wa_bapi_mara-shelf_life.
 MOVE wa_mara-mhdlp TO wa_bapi_mara-stor_pct.
* MOVE wa_MARA-INHME TO WA_.
* MOVE wa_MARA-INHAL TO WA_.
* MOVE wa_MARA-VPREH TO WA_.
* MOVE wa_MARA-ETIAG TO WA_.
* MOVE wa_MARA-INHBR TO WA_.
* MOVE wa_MARA-CMETH TO WA_.
* MOVE wa_MARA-CUOBF TO WA_.
 MOVE wa_mara-kzumw TO wa_bapi_mara-envt_rlvt.
 MOVE wa_mara-kosch TO wa_bapi_mara-prod_alloc.
* MOVE wa_MARA-SPROF TO WA_.
 MOVE wa_mara-nrfhg TO wa_bapi_mara-qual_dik.
 MOVE wa_mara-mfrpn TO wa_bapi_mara-manu_mat.
 MOVE wa_mara-mfrnr TO wa_bapi_mara-mfr_no.
 MOVE wa_mara-bmatn TO wa_bapi_mara-inv_mat_no.
 MOVE wa_mara-mprof TO wa_bapi_mara-manuf_prof.
* MOVE wa_MARA-KZWSM TO WA_.
* MOVE wa_MARA-SAITY TO WA_.
 MOVE wa_mara-profl TO wa_bapi_mara-hazmatprof.
 MOVE wa_mara-ihivi TO wa_bapi_mara-high_visc.
 MOVE wa_mara-iloos TO wa_bapi_mara-looseorliq.
* MOVE wa_MARA-SERLV TO WA_.
 MOVE wa_mara-kzgvh TO wa_bapi_mara-closed_box.
 MOVE wa_mara-xgchp TO wa_bapi_mara-appd_b_rec.
 MOVE wa_mara-kzeff TO wa_bapi_mara-par_eff.
 MOVE wa_mara-compl TO wa_bapi_mara-matcmpllvl.
 MOVE wa_mara-iprkz TO wa_bapi_mara-period_ind_expiration_date.
 MOVE wa_mara-rdmhd TO wa_bapi_mara-round_up_rule_expiration_date.
 MOVE wa_mara-przus TO wa_bapi_mara-prod_composition_on_packaging.
 MOVE wa_mara-mtpos_mara TO wa_bapi_mara-item_cat.
* MOVE wa_MARA-BFLME TO WA_.
 MOVE wa_mara-matfi TO wa_bapi_mara-material_fixed.
 MOVE wa_mara-cmrel TO wa_bapi_mara-cm_relevance_flag.

*MOVE ??? TO WA_BAPI_MARA-BASE_UOM_ISO.
*MOVE ??? TO WA_BAPI_MARA-PO_UNIT_ISO.
*MOVE ??? TO WA_BAPI_MARA-PACK_WT_UN_ISO.
*MOVE ??? TO WA_BAPI_MARA-PACK_VO_UN_ISO.
*MOVE ??? TO WA_BAPI_MARA-HAZ_MAT_NO_EXTERNAL.
*MOVE ??? TO WA_BAPI_MARA-HAZ_MAT_NO_GUID.
*MOVE ??? TO WA_BAPI_MARA-HAZ_MAT_NO_VERSION.
*MOVE ??? TO WA_BAPI_MARA-INV_MAT_NO_EXTERNAL.
*MOVE ??? TO WA_BAPI_MARA-INV_MAT_NO_GUID.
*MOVE ??? TO WA_BAPI_MARA-INV_MAT_NO_VERSION.

* Änderungen für Materialdaten gewünscht oder zugelassen
 IF p_material_sichten CS 'K'.
* Änderungskennzeichen für alle Felder setzen
   MOVE 0 TO sy-subrc.
   WHILE sy-subrc = 0.
     REPLACE ' ' WITH 'X' INTO wa_bapi_mara_x.
   ENDWHILE.
 ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M A R C                          *
*---------------------------------------------------------------------*
* Materialdaten mit Werksbezug. Die einzelnen Elemente der SAP Struk- *
* tur in die Bapi-Struktur überspielen                                *
*---------------------------------------------------------------------*
FORM upro-bapi_marc
    USING p_material_sichten.

* Sichten für den Werksbezug zurücksetzen
 CLEAR: wa_bapi_basis-purchase_view,
        wa_bapi_basis-mrp_view,
        wa_bapi_basis-work_sched_view.

* allgemeiner Datenblock / Struktur wird erweitert
* Sichten für Disposition und / oder Einkauf zulassen

* A = Arbeistvorbereitung
 IF p_material_sichten CS 'A'.
   MOVE 'X' TO wa_bapi_basis-work_sched_view.
 ENDIF.
* D = Disposicht
 IF p_material_sichten CS 'D'.
   MOVE 'X' TO wa_bapi_basis-mrp_view.
 ENDIF.
* E = Einkaufssicht
 IF p_material_sichten CS 'E'.
   MOVE 'X' TO wa_bapi_basis-purchase_view.
 ENDIF.
* G = Kalkulation
 IF p_material_sichten CS 'G'.
   MOVE 'X' TO wa_bapi_basis-cost_view.
 ENDIF.

* material-/werksbezogenen Daten
 CLEAR: wa_bapi_marc, wa_bapi_marc_x.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_marc TO wa_bapi_marc.

* MOVE WA_MARC-MANDT TO WA_.
* MOVE WA_MARC-MATNR TO WA_.
 MOVE wa_marc-werks TO wa_bapi_marc-plant.
* MOVE WA_MARC-PSTAT TO WA_.
 MOVE wa_marc-lvorm TO wa_bapi_marc-del_flag.
* MOVE WA_MARC-BWTTY TO WA_.
* MOVE WA_MARC-XCHAR TO WA_.
 MOVE wa_marc-mmsta TO wa_bapi_marc-pur_status.
 MOVE wa_marc-mmstd TO wa_bapi_marc-pvalidfrom.
 MOVE wa_marc-maabc TO wa_bapi_marc-abc_id.
 MOVE wa_marc-kzkri TO wa_bapi_marc-crit_part.
 MOVE wa_marc-ekgrp TO wa_bapi_marc-pur_group.
 MOVE wa_marc-ausme TO wa_bapi_marc-issue_unit.
 MOVE wa_marc-dispr TO wa_bapi_marc-mrpprofile.
 MOVE wa_marc-dismm TO wa_bapi_marc-mrp_type.
 MOVE wa_marc-dispo TO wa_bapi_marc-mrp_ctrler.
* MOVE WA_MARC-KZDIE TO WA_.
 MOVE wa_marc-plifz TO wa_bapi_marc-plnd_delry.
 MOVE wa_marc-webaz TO wa_bapi_marc-gr_pr_time.
 MOVE wa_marc-perkz TO wa_bapi_marc-period_ind.
 MOVE wa_marc-ausss TO wa_bapi_marc-assy_scrap.
 MOVE wa_marc-disls TO wa_bapi_marc-lotsizekey.
 MOVE wa_marc-beskz TO wa_bapi_marc-proc_type.
 MOVE wa_marc-sobsl TO wa_bapi_marc-spproctype.
 MOVE wa_marc-minbe TO wa_bapi_marc-reorder_pt.
 MOVE wa_marc-eisbe TO wa_bapi_marc-safety_stk.
 MOVE wa_marc-bstmi TO wa_bapi_marc-minlotsize.
 MOVE wa_marc-bstma TO wa_bapi_marc-maxlotsize.
 MOVE wa_marc-bstfe TO wa_bapi_marc-fixed_lot.
 MOVE wa_marc-bstrf TO wa_bapi_marc-round_val.
 MOVE wa_marc-mabst TO wa_bapi_marc-max_stock.
* MOVE WA_MARC-LOSFX TO WA_.
 MOVE wa_marc-sbdkz TO wa_bapi_marc-dep_req_id.
 MOVE wa_marc-lagpr TO wa_bapi_marc-stor_costs.
 MOVE wa_marc-altsl TO wa_bapi_marc-alt_bom_id.
 MOVE wa_marc-kzaus TO wa_bapi_marc-discontinu.
 MOVE wa_marc-ausdt TO wa_bapi_marc-eff_o_day.
 MOVE wa_marc-nfmat TO wa_bapi_marc-follow_up.
 MOVE wa_marc-kzbed TO wa_bapi_marc-grp_reqmts.
 MOVE wa_marc-miskz TO wa_bapi_marc-mixed_mrp.
 MOVE wa_marc-fhori TO wa_bapi_marc-sm_key.
* MOVE WA_MARC-PFREI TO WA_.
* MOVE WA_MARC-FFREI TO WA_.
 MOVE wa_marc-rgekz TO wa_bapi_marc-backflush.
 MOVE wa_marc-fevor TO wa_bapi_marc-production_scheduler.
 MOVE wa_marc-bearz TO wa_bapi_marc-proc_time.
 MOVE wa_marc-ruezt TO wa_bapi_marc-setuptime.
 MOVE wa_marc-tranz TO wa_bapi_marc-interop.
 MOVE wa_marc-basmg TO wa_bapi_marc-base_qty.
 MOVE wa_marc-dzeit TO wa_bapi_marc-inhseprodt.
 MOVE wa_marc-maxlz TO wa_bapi_marc-stgeperiod.
 MOVE wa_marc-lzeih TO wa_bapi_marc-stge_pd_un.
* MOVE WA_MARC-KZPRO TO WA_.
* MOVE WA_MARC-GPMKZ TO WA_.
 MOVE wa_marc-ueeto TO wa_bapi_marc-over_tol.
 MOVE wa_marc-ueetk TO wa_bapi_marc-unlimited.
 MOVE wa_marc-uneto TO wa_bapi_marc-under_tol.
 MOVE wa_marc-wzeit TO wa_bapi_marc-replentime.
 MOVE wa_marc-atpkz TO wa_bapi_marc-replace_pt.
* MOVE WA_MARC-VZUSL TO WA_.
* MOVE WA_MARC-HERBL TO WA_.
 MOVE wa_marc-insmk TO wa_bapi_marc-ind_post_to_insp_stock.
* MOVE WA_MARC-SPROZ TO WA_.
* MOVE WA_MARC-QUAZT TO WA_.
 MOVE wa_marc-ssqss TO wa_bapi_marc-ctrl_key.
* MOVE WA_MARC-MPDAU TO WA_.
* MOVE WA_MARC-KZPPV TO WA_.
 MOVE wa_marc-kzdkz TO wa_bapi_marc-doc_reqd.
* MOVE WA_MARC-WSTGH TO WA_.
 MOVE wa_marc-prfrq TO wa_bapi_marc-insp_int.
* MOVE WA_MARC-NKMPR TO WA_.
* MOVE WA_MARC-UMLMC TO WA_.
 MOVE wa_marc-ladgr TO wa_bapi_marc-loadinggrp.
 MOVE wa_marc-xchpf TO wa_bapi_marc-batch_mgmt.
 MOVE wa_marc-usequ TO wa_bapi_marc-quotausage.
 MOVE wa_marc-lgrad TO wa_bapi_marc-serv_level.
 MOVE wa_marc-auftl TO wa_bapi_marc-split_ind.
* MOVE WA_MARC-PLVAR TO WA_.
* MOVE WA_MARC-OTYPE TO WA_.
* MOVE WA_MARC-OBJID TO WA_.
 MOVE wa_marc-mtvfp TO wa_bapi_marc-availcheck.
 MOVE wa_marc-periv TO wa_bapi_marc-fy_variant.
 MOVE wa_marc-kzkfk TO wa_bapi_marc-corr_fact.
 MOVE wa_marc-vrvez TO wa_bapi_marc-setup_time.
 MOVE wa_marc-vbamg TO wa_bapi_marc-base_qty_plan.
 MOVE wa_marc-vbeaz TO wa_bapi_marc-ship_proc_time.
* MOVE WA_MARC-LIZYK TO WA_.
 MOVE wa_marc-bwscl TO wa_bapi_marc-sup_source.
 MOVE wa_marc-kautb TO wa_bapi_marc-auto_p_ord.
 MOVE wa_marc-kordb TO wa_bapi_marc-sourcelist.
 MOVE wa_marc-stawn TO wa_bapi_marc-comm_code.
 MOVE wa_marc-herkl TO wa_bapi_marc-countryori.
 MOVE wa_marc-herkr TO wa_bapi_marc-regionorig.
 MOVE wa_marc-expme TO wa_bapi_marc-comm_co_un.
 MOVE wa_marc-mtver TO wa_bapi_marc-expimpgrp.
 MOVE wa_marc-prctr TO wa_bapi_marc-profit_ctr.
* MOVE WA_MARC-TRAME TO WA_.
 MOVE wa_marc-mrppp TO wa_bapi_marc-ppc_pl_cal.
 MOVE wa_marc-sauft TO wa_bapi_marc-rep_manuf.
 MOVE wa_marc-fxhor TO wa_bapi_marc-pl_ti_fnce.
 MOVE wa_marc-vrmod TO wa_bapi_marc-consummode.
 MOVE wa_marc-vint1 TO wa_bapi_marc-bwd_cons.
 MOVE wa_marc-vint2 TO wa_bapi_marc-fwd_cons.
* MOVE WA_MARC-VERKZ TO WA_.
 MOVE wa_marc-stlal TO wa_bapi_marc-alternative_bom.
 MOVE wa_marc-stlan TO wa_bapi_marc-bom_usage.
 MOVE wa_marc-plnnr TO wa_bapi_marc-planlistgrp.
 MOVE wa_marc-aplal TO wa_bapi_marc-planlistcnt.
 MOVE wa_marc-losgr TO wa_bapi_marc-lot_size.
 MOVE wa_marc-sobsk TO wa_bapi_marc-specprocty.
 MOVE wa_marc-frtme TO wa_bapi_marc-prod_unit.
 MOVE wa_marc-lgpro TO wa_bapi_marc-iss_st_loc.
 MOVE wa_marc-disgr TO wa_bapi_marc-mrp_group.
 MOVE wa_marc-kausf TO wa_bapi_marc-comp_scrap.
 MOVE wa_marc-qzgtp TO wa_bapi_marc-cert_type.
* MOVE WA_MARC-QMATV TO WA_.
 MOVE wa_marc-takzt TO wa_bapi_marc-cycle_time.
 MOVE wa_marc-rwpro TO wa_bapi_marc-covprofile.
* MOVE WA_MARC-COPAM TO WA_.
 MOVE wa_marc-abcin TO wa_bapi_marc-cc_ph_inv.
 MOVE wa_marc-awsls TO wa_bapi_marc-variance_key.
 MOVE wa_marc-sernp TO wa_bapi_marc-serno_prof.
* MOVE WA_MARC-CUOBJ TO WA_.
* MOVE WA_MARC-STDPD TO WA_.
 MOVE wa_marc-sfepr TO wa_bapi_marc-repmanprof.
 MOVE wa_marc-xmcng TO wa_bapi_marc-neg_stocks.
 MOVE wa_marc-qssys TO wa_bapi_marc-qm_rgmts.
 MOVE wa_marc-lfrhy TO wa_bapi_marc-plng_cycle.
 MOVE wa_marc-rdprf TO wa_bapi_marc-round_prof.
 MOVE wa_marc-vrbmt TO wa_bapi_marc-refmatcons.
* MOVE WA_MARC-VRBWK TO WA_.
 MOVE wa_marc-vrbdt TO wa_bapi_marc-d_to_ref_m.
 MOVE wa_marc-vrbfk TO wa_bapi_marc-mult_ref_m.
 MOVE wa_marc-autru TO wa_bapi_marc-auto_reset.
* MOVE WA_MARC-PREFE TO WA_.
 MOVE wa_marc-prenc TO wa_bapi_marc-ex_cert_id.
 MOVE wa_marc-preno TO wa_bapi_marc-ex_cert_no_new.
 MOVE wa_marc-prend TO wa_bapi_marc-ex_cert_dt.
* MOVE WA_MARC-PRENE TO WA_.
* MOVE WA_MARC-PRENG TO WA_.
 MOVE wa_marc-itark TO wa_bapi_marc-milit_id.
* MOVE WA_MARC-SERVG TO WA_.
 MOVE wa_marc-kzkup TO wa_bapi_marc-co_product.
 MOVE wa_marc-strgr TO wa_bapi_marc-plan_strgp.
* MOVE WA_MARC-CUOBV TO WA_.
 MOVE wa_marc-lgfsb TO wa_bapi_marc-sloc_exprc.
 MOVE wa_marc-schgt TO wa_bapi_marc-bulk_mat.
 MOVE wa_marc-ccfix TO wa_bapi_marc-cc_fixed.
 MOVE wa_marc-eprio TO wa_bapi_marc-determ_grp.
 MOVE wa_marc-qmata TO wa_bapi_marc-qm_authgrp.
* MOVE WA_MARC-RESVP TO WA_.
 MOVE wa_marc-plnty TO wa_bapi_marc-task_list_type.
* MOVE WA_MARC-UOMGR TO WA_.
* MOVE WA_MARC-UMRSL TO WA_.
* MOVE WA_MARC-ABFAC TO WA_.
 MOVE wa_marc-sfcpf TO wa_bapi_marc-prodprof.
 MOVE wa_marc-shflg TO wa_bapi_marc-safty_t_id.
 MOVE wa_marc-shzet TO wa_bapi_marc-safetytime.
 MOVE wa_marc-mdach TO wa_bapi_marc-plord_ctrl.
 MOVE wa_marc-kzech TO wa_bapi_marc-batchentry.
 MOVE wa_marc-megru TO wa_bapi_marc-unit_group.
 MOVE wa_marc-mfrgr TO wa_bapi_marc-matfrgtgrp.
* MOVE WA_MARC-VKUMC TO WA_.
* MOVE WA_MARC-VKTRW TO WA_.
* MOVE WA_MARC-KZAGL TO WA_.
 MOVE wa_marc-fvidk TO wa_bapi_marc-prodverscs.
 MOVE wa_marc-fxpru TO wa_bapi_marc-fxd_price.
 MOVE wa_marc-loggr TO wa_bapi_marc-handlg_grp.
 MOVE wa_marc-fprfm TO wa_bapi_marc-distr_prof.
* MOVE WA_MARC-GLGMG TO WA_.
* MOVE WA_MARC-VKGLG TO WA_.
 MOVE wa_marc-indus TO wa_bapi_marc-mat_cfop.
 MOVE wa_marc-mownr TO wa_bapi_marc-eu_list_no.
 MOVE wa_marc-mogru TO wa_bapi_marc-eu_mat_grp.
 MOVE wa_marc-casnr TO wa_bapi_marc-cas_no.
 MOVE wa_marc-gpnum TO wa_bapi_marc-prodcom_no.
 MOVE wa_marc-steuc TO wa_bapi_marc-ctrl_code.
 MOVE wa_marc-fabkz TO wa_bapi_marc-jit_relvt.
 MOVE wa_marc-matgr TO wa_bapi_marc-mat_grp_trans.
 MOVE wa_marc-vspvb TO wa_bapi_marc-supply_area.
 MOVE wa_marc-dplfs TO wa_bapi_marc-fair_share_rule.
 MOVE wa_marc-dplpu TO wa_bapi_marc-push_distrib.
 MOVE wa_marc-dplho TO wa_bapi_marc-deploy_horiz.
 MOVE wa_marc-minls TO wa_bapi_marc-min_lot_size.
 MOVE wa_marc-maxls TO wa_bapi_marc-max_lot_size.
 MOVE wa_marc-fixls TO wa_bapi_marc-fix_lot_size.
 MOVE wa_marc-ltinc TO wa_bapi_marc-lot_increment.
* MOVE WA_MARC-COMPL TO WA_.
 MOVE wa_marc-convt TO wa_bapi_marc-prod_conv_type.
 MOVE wa_marc-shpro TO wa_bapi_marc-period_profile_safety_time.
 MOVE wa_marc-ahdis TO wa_bapi_marc-mrp_relevancy_dep_requirements.
* MOVE WA_MARC-DIBER TO WA_.
 MOVE wa_marc-kzpsp TO wa_bapi_marc-avail_check_all_proj_segments.
 MOVE wa_marc-ocmpf TO wa_bapi_marc-overallprf.
* MOVE WA_MARC-APOKZ TO WA_.
* MOVE WA_MARC-MCRUE TO WA_.
* MOVE WA_MARC-LFMON TO WA_.
* MOVE WA_MARC-LFGJA TO WA_.
 MOVE wa_marc-eislo TO wa_bapi_marc-min_safety_stk.
 MOVE wa_marc-ncost TO wa_bapi_marc-no_costing.

* MOVE WA_ ??? TO WA_BAPI_MARC-ISSUE_UNIT_ISO.
* MOVE WA_ ??? TO WA_BAPI_MARC-ORD_COSTS.
* MOVE WA_ ??? TO WA_BAPI_MARC-STGE_PD_UN_ISO.
* MOVE WA_ ??? TO WA_BAPI_MARC-COUNTRYORI_ISO.
* MOVE WA_ ??? TO WA_BAPI_MARC-COMM_CO_UN_ISO.
* MOVE WA_ ??? TO WA_BAPI_MARC-PROD_UNIT_ISO.
* MOVE WA_ ??? TO WA_BAPI_MARC-FOLLOW_UP_EXTERNAL.
* MOVE WA_ ??? TO WA_BAPI_MARC-FOLLOW_UP_GUID.
* MOVE WA_ ??? TO WA_BAPI_MARC-FOLLOW_UP_VERSION.
* MOVE WA_ ??? TO WA_BAPI_MARC-REFMATCONS_EXTERNAL.
* MOVE WA_ ??? TO WA_BAPI_MARC-REFMATCONS_GUID.
* MOVE WA_ ??? TO WA_BAPI_MARC-REFMATCONS_VERSION.

* Änderungen für Materialdaten gewünscht oder zugelassen
* A C H T U N G: der Einfachheithalber keine Differenzierung zwischen
* Einkauf- und Disposicht
 IF p_material_sichten CS 'A'
 OR p_material_sichten CS 'D'
 OR p_material_sichten CS 'E'
 OR p_material_sichten CS 'G'.
* Änderungskennzeichen für alle Felder setzen
   MOVE 0 TO sy-subrc.
   WHILE sy-subrc = 0.
     REPLACE ' ' WITH 'X' INTO wa_bapi_marc_x.
   ENDWHILE.
 ENDIF.
 MOVE wa_marc-werks TO wa_bapi_marc_x-plant.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M A R D                          *
*---------------------------------------------------------------------*
* =>] lagersicht: 'X'= Änderung der Felder gewünscht                  *
*                 ' '= keine Änderung, Struktur zur Verfügung stellen *
*---------------------------------------------------------------------*
FORM upro-bapi_mard
    USING p_material_sichten.

 IF p_material_sichten CS 'L'.
* allgemeiner Datenblock
* Sicht für Lager zulassen
   MOVE 'X' TO wa_bapi_basis-storage_view.
 ENDIF.

* lagerortsbezogene Daten
 CLEAR: wa_bapi_mard, wa_bapi_mard_x.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_mard TO wa_bapi_mard.

* MOVE WA_MARD-MANDT TO WA_.
* MOVE WA_MARD-MATNR TO WA_.
 MOVE wa_mard-werks TO wa_bapi_mard-plant.
 MOVE wa_mard-lgort TO wa_bapi_mard-stge_loc.
* MOVE WA_MARD-PSTAT TO WA_.
 MOVE wa_mard-lvorm TO wa_bapi_mard-del_flag.
* MOVE WA_MARD-LFGJA TO WA_.
* MOVE WA_MARD-LFMON TO WA_.
* MOVE WA_MARD-SPERR TO WA_.
* MOVE WA_MARD-LABST TO WA_.
* MOVE WA_MARD-UMLME TO WA_.
* MOVE WA_MARD-INSME TO WA_.
* MOVE WA_MARD-EINME TO WA_.
* MOVE WA_MARD-SPEME TO WA_.
* MOVE WA_MARD-RETME TO WA_.
* MOVE WA_MARD-VMLAB TO WA_.
* MOVE WA_MARD-VMUML TO WA_.
* MOVE WA_MARD-VMINS TO WA_.
* MOVE WA_MARD-VMEIN TO WA_.
* MOVE WA_MARD-VMSPE TO WA_.
* MOVE WA_MARD-VMRET TO WA_.
* MOVE WA_MARD-KZILL TO WA_.
* MOVE WA_MARD-KZILQ TO WA_.
* MOVE WA_MARD-KZILE TO WA_.
* MOVE WA_MARD-KZILS TO WA_.
* MOVE WA_MARD-KZVLL TO WA_.
* MOVE WA_MARD-KZVLQ TO WA_.
* MOVE WA_MARD-KZVLE TO WA_.
* MOVE WA_MARD-KZVLS TO WA_.
 MOVE wa_mard-diskz TO wa_bapi_mard-mrp_ind.
 MOVE wa_mard-lsobs TO wa_bapi_mard-spec_proc.
 MOVE wa_mard-lminb TO wa_bapi_mard-reorder_pt.
 MOVE wa_mard-lbstf TO wa_bapi_mard-repl_qty.
* MOVE WA_MARD-HERKL TO WA_.
* MOVE WA_MARD-EXPPG TO WA_.
* MOVE WA_MARD-EXVER TO WA_.
 MOVE wa_mard-lgpbe TO wa_bapi_mard-stge_bin.
* MOVE WA_MARD-KLABS TO WA_.
* MOVE WA_MARD-KINSM TO WA_.
* MOVE WA_MARD-KEINM TO WA_.
* MOVE WA_MARD-KSPEM TO WA_.
* MOVE WA_MARD-DLINL TO WA_.
* MOVE WA_MARD-PRCTL TO WA_.
* MOVE WA_MARD-ERSDA TO WA_.
* MOVE WA_MARD-VKLAB TO WA_.
* MOVE WA_MARD-VKUML TO WA_.
 MOVE wa_mard-lwmkb TO wa_bapi_mard-pickg_area.
 MOVE wa_mard-bskrf TO wa_bapi_mard-inv_corr_fac.
* MOVE WA_MARD-MDRUE TO WA_.
* MOVE WA_MARD-MDJIN TO WA_.

* Änderungen für Materialdaten gewünscht oder zugelassen
 IF p_material_sichten CS 'L'.
* Änderungskennzeichen für alle Felder setzen
   MOVE 0 TO sy-subrc.
   WHILE sy-subrc = 0.
     REPLACE ' ' WITH 'X' INTO wa_bapi_mard_x.
   ENDWHILE.
 ENDIF.
 MOVE wa_mard-werks TO wa_bapi_mard_x-plant.
 MOVE wa_mard-lgort TO wa_bapi_mard_x-stge_loc.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M A R M                          *
*---------------------------------------------------------------------*
* Maßeinheiten zum Material. Interne Tabelle aufbauen und zur Verfü-  *
* gung. Gilt für alle Umrechnungen der Maßeinheiten dieses Materiales *
*---------------------------------------------------------------------*
FORM upro-bapi_marm.

 CLEAR:   itab_bapi_marm, itab_bapi_marm_x.
 REFRESH: itab_bapi_marm, itab_bapi_marm_x.

 LOOP AT itab_marm INTO wa_marm
 WHERE matnr = wa_mara-matnr.
   CLEAR: itab_bapi_marm, itab_bapi_marm_x.

*   MOVE wa_MARM-MANDT TO ITAB_.
*   MOVE wa_MARM-MATNR TO ITAB_.
   MOVE wa_marm-meinh TO itab_bapi_marm-alt_unit.
   MOVE wa_marm-umrez TO itab_bapi_marm-numerator.
   MOVE wa_marm-umren TO itab_bapi_marm-denominatr.
*   MOVE wa_MARM-EANNR TO ITAB_.
   MOVE wa_marm-ean11 TO itab_bapi_marm-ean_upc.
   MOVE wa_marm-numtp TO itab_bapi_marm-ean_cat.
   MOVE wa_marm-laeng TO itab_bapi_marm-length.
   MOVE wa_marm-breit TO itab_bapi_marm-width.
   MOVE wa_marm-hoehe TO itab_bapi_marm-height.
   MOVE wa_marm-meabm TO itab_bapi_marm-unit_dim.
   MOVE wa_marm-volum TO itab_bapi_marm-volume.
   MOVE wa_marm-voleh TO itab_bapi_marm-volumeunit.
   MOVE wa_marm-brgew TO itab_bapi_marm-gross_wt.
   MOVE wa_marm-gewei TO itab_bapi_marm-unit_of_wt.
   MOVE wa_marm-mesub TO itab_bapi_marm-sub_uom.
*   MOVE wa_MARM-ATINN TO ITAB_.
*   MOVE wa_MARM-MESRT TO ITAB_.
*   MOVE wa_MARM-XFHDW TO ITAB_.
*   MOVE wa_MARM-XBEWW TO ITAB_.
*   MOVE wa_MARM-KZWSO TO ITAB_.
*   MOVE wa_MARM-MSEHI TO ITAB_.
*   MOVE wa_MARM-BFLME_MARM TO ITAB_.

*   MOVE ??? TO ITAB_BAPI_MARM-ALT_UNIT_ISO.
*   MOVE ??? TO ITAB_BAPI_MARM-UNIT_DIM_ISO.
*   MOVE ??? TO ITAB_BAPI_MARM-VOLUMEUNIT_ISO.
*   MOVE ??? TO ITAB_BAPI_MARM-UNIT_OF_WT_ISO.
*   MOVE ??? TO ITAB_BAPI_MARM-DEL_FLAG.
*   MOVE ??? TO ITAB_BAPI_MARM-SUB_UOM_ISO.

   APPEND itab_bapi_marm.

* Änderungskennzeichen für alle Felder setzen
   MOVE 0 TO sy-subrc.
   WHILE sy-subrc = 0.
     REPLACE ' ' WITH 'X' INTO itab_bapi_marm_x.
   ENDWHILE.
   MOVE wa_marm-meinh TO itab_bapi_marm_x-alt_unit.

   CLEAR: itab_bapi_marm_x-alt_unit_iso.

   APPEND itab_bapi_marm_x.
 ENDLOOP.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M B E W                          *
*---------------------------------------------------------------------*
* Materialbewertungen                                                 *
*---------------------------------------------------------------------*
FORM upro-bapi_mbew USING p_material_sichten.

* allgemeiner Datenblock
* Sicht für Bewertung / Buchhaltung zulassen
 IF p_material_sichten CS 'B'.
   MOVE 'X' TO wa_bapi_basis-account_view.
 ENDIF.
* Sicht für Kalkulation zulassen
 IF p_material_sichten CS 'G'.
   MOVE 'X' TO wa_bapi_basis-cost_view.
 ENDIF.

* bewertungsbezogene Daten
 CLEAR: wa_bapi_mbew, wa_bapi_mbew_x.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_mbew TO wa_bapi_mbew.

 MOVE wa_mbew-bwkey TO wa_bapi_mbew-val_area.
 MOVE wa_mbew-bwtar TO wa_bapi_mbew-val_type.
 MOVE wa_mbew-lvorm TO wa_bapi_mbew-del_flag.
* MOVE WA_MBEW-LBKUM TO WA_.
* MOVE WA_MBEW-SALK3 TO WA_.
 MOVE wa_mbew-vprsv TO wa_bapi_mbew-price_ctrl.
* MOVE WA_MBEW-VERPR TO WA_.
* MOVE WA_MBEW-STPRS TO WA_.
 MOVE wa_mbew-peinh TO wa_bapi_mbew-price_unit.
 MOVE wa_mbew-bklas TO wa_bapi_mbew-val_class.
* MOVE WA_MBEW-SALKV TO WA_.
* MOVE WA_MBEW-VMKUM TO WA_.
* MOVE WA_MBEW-VMSAL TO WA_.
 MOVE wa_mbew-vmvpr TO wa_bapi_mbew-pr_ctrl_pp.
* MOVE WA_MBEW-VMVER TO WA_.
* MOVE WA_MBEW-VMSTP TO WA_.
 MOVE wa_mbew-vmpei TO wa_bapi_mbew-pr_unit_pp.
 MOVE wa_mbew-vmbkl TO wa_bapi_mbew-vclass_pp.
* MOVE WA_MBEW-VMSAV TO WA_.
* MOVE WA_MBEW-VJKUM TO WA_.
* MOVE WA_MBEW-VJSAL TO WA_.
 MOVE wa_mbew-vjvpr TO wa_bapi_mbew-pr_ctrl_py.
* MOVE WA_MBEW-VJVER TO WA_.
* MOVE WA_MBEW-VJSTP TO WA_.
 MOVE wa_mbew-vjpei TO wa_bapi_mbew-pr_unit_py.
 MOVE wa_mbew-vjbkl TO wa_bapi_mbew-vclass_py.
* MOVE WA_MBEW-VJSAV TO WA_.
* MOVE WA_MBEW-LFGJA TO WA_.
* MOVE WA_MBEW-LFMON TO WA_.
 MOVE wa_mbew-bwtty TO wa_bapi_mbew-val_cat.
* MOVE WA_MBEW-STPRV TO WA_.
* MOVE WA_MBEW-LAEPR TO WA_.
* MOVE WA_MBEW-ZKPRS TO WA_.
 MOVE wa_mbew-zkdat TO wa_bapi_mbew-valid_from.
* MOVE WA_MBEW-BWPRS TO WA_.
* MOVE WA_MBEW-BWPRH TO WA_.
* MOVE WA_MBEW-VJBWS TO WA_.
* MOVE WA_MBEW-VJBWH TO WA_.
* MOVE WA_MBEW-VVJSL TO WA_.
* MOVE WA_MBEW-VVJLB TO WA_.
* MOVE WA_MBEW-VVMLB TO WA_.
* MOVE WA_MBEW-VVSAL TO WA_.
* MOVE WA_MBEW-ZPLPR TO WA_.
* MOVE WA_MBEW-ZPLP1 TO WA_.
* MOVE WA_MBEW-ZPLP2 TO WA_.
* MOVE WA_MBEW-ZPLP3 TO WA_.
 MOVE wa_mbew-zpld1 TO wa_bapi_mbew-plndprdate1.
 MOVE wa_mbew-zpld2 TO wa_bapi_mbew-plndprdate2.
 MOVE wa_mbew-zpld3 TO wa_bapi_mbew-plndprdate3.
* MOVE WA_MBEW-PPERZ TO WA_.
* MOVE WA_MBEW-PPERL TO WA_.
* MOVE WA_MBEW-PPERV TO WA_.
* MOVE WA_MBEW-KALKZ TO WA_.
* MOVE WA_MBEW-KALKL TO WA_.
* MOVE WA_MBEW-KALKV TO WA_.
* MOVE WA_MBEW-KALSC TO WA_.
 MOVE wa_mbew-xlifo TO wa_bapi_mbew-lifo_fifo.
 MOVE wa_mbew-mypol TO wa_bapi_mbew-poolnumber.
* MOVE WA_MBEW-BWPH1 TO WA_.
* MOVE WA_MBEW-BWPS1 TO WA_.
 MOVE wa_mbew-abwkz TO wa_bapi_mbew-deval_ind.
* MOVE WA_MBEW-PSTAT TO WA_.
* MOVE WA_MBEW-KALN1 TO WA_.
* MOVE WA_MBEW-KALNR TO WA_.
* MOVE WA_MBEW-BWVA1 TO WA_.
* MOVE WA_MBEW-BWVA2 TO WA_.
* MOVE WA_MBEW-BWVA3 TO WA_.
* MOVE WA_MBEW-VERS1 TO WA_.
* MOVE WA_MBEW-VERS2 TO WA_.
* MOVE WA_MBEW-VERS3 TO WA_.
 MOVE wa_mbew-hrkft TO wa_bapi_mbew-orig_group.
 MOVE wa_mbew-kosgr TO wa_bapi_mbew-overhead_grp.
* MOVE WA_MBEW-PPRDZ TO WA_.
* MOVE WA_MBEW-PPRDL TO WA_.
* MOVE WA_MBEW-PPRDV TO WA_.
* MOVE WA_MBEW-PDATZ TO WA_.
* MOVE WA_MBEW-PDATL TO WA_.
* MOVE WA_MBEW-PDATV TO WA_.
 MOVE wa_mbew-ekalr TO wa_bapi_mbew-qty_struct.
* MOVE WA_MBEW-VPLPR TO WA_.
 MOVE wa_mbew-mlmaa TO wa_bapi_mbew-ml_active.
 MOVE wa_mbew-mlast TO wa_bapi_mbew-ml_settle.
* MOVE WA_MBEW-LPLPR TO WA_.
* MOVE WA_MBEW-VKSAL TO WA_.
 MOVE wa_mbew-hkmat TO wa_bapi_mbew-orig_mat.
* MOVE WA_MBEW-SPERW TO WA_.
* MOVE WA_MBEW-KZIWL TO WA_.
* MOVE WA_MBEW-WLINL TO WA_.
* MOVE WA_MBEW-ABCIW TO WA_.
* MOVE WA_MBEW-BWSPA TO WA_.
* MOVE WA_MBEW-LPLPX TO WA_.
* MOVE WA_MBEW-VPLPX TO WA_.
* MOVE WA_MBEW-FPLPX TO WA_.
* MOVE WA_MBEW-LBWST TO WA_.
* MOVE WA_MBEW-VBWST TO WA_.
* MOVE WA_MBEW-FBWST TO WA_.
 MOVE wa_mbew-eklas TO wa_bapi_mbew-vm_so_stk.
 MOVE wa_mbew-qklas TO wa_bapi_mbew-vm_p_stock.
 MOVE wa_mbew-mtuse TO wa_bapi_mbew-matl_usage.
 MOVE wa_mbew-mtorg TO wa_bapi_mbew-mat_origin.
 MOVE wa_mbew-ownpr TO wa_bapi_mbew-in_house.
* MOVE WA_MBEW-XBEWM TO WA_.
 MOVE wa_mbew-bwpei TO wa_bapi_mbew-tax_cml_un.
* MOVE WA_MBEW-MBRUE TO WA_.
* MOVE WA_MBEW-OKLAS TO WA_.

* MOVE WA_ ??? TO WA_BAPI_MBEW-MOVING_PR.
* MOVE WA_ ??? TO WA_BAPI_MBEW-STD_PRICE.
* MOVE WA_ ??? TO WA_BAPI_MBEW-MOV_PR_PP.
* MOVE WA_ ??? TO WA_BAPI_MBEW-STD_PR_PP.
* MOVE WA_ ??? TO WA_BAPI_MBEW-MOV_PR_PY.
* MOVE WA_ ??? TO WA_BAPI_MBEW-STD_PR_PY.
* MOVE WA_ ??? TO WA_BAPI_MBEW-FUTURE_PR.
* MOVE WA_ ??? TO WA_BAPI_MBEW-TAXPRICE_1.
* MOVE WA_ ??? TO WA_BAPI_MBEW-COMMPRICE1.
* MOVE WA_ ??? TO WA_BAPI_MBEW-TAXPRICE_3.
* MOVE WA_ ??? TO WA_BAPI_MBEW-COMMPRICE3.
* MOVE WA_ ??? TO WA_BAPI_MBEW-PLND_PRICE.
* MOVE WA_ ??? TO WA_BAPI_MBEW-PLNDPRICE1.
* MOVE WA_ ??? TO WA_BAPI_MBEW-PLNDPRICE2.
* MOVE WA_ ??? TO WA_BAPI_MBEW-PLNDPRICE3.
* MOVE WA_ ??? TO WA_BAPI_MBEW-TAXPRICE_2.
* MOVE WA_ ??? TO WA_BAPI_MBEW-COMMPRICE2.

* Änderungen für Materialdaten gewünscht oder zugelassen
 IF p_material_sichten CS 'B'
 OR p_material_sichten CS 'G'.
* Änderungskennzeichen für alle Felder setzen
   MOVE 0 TO sy-subrc.
   WHILE sy-subrc = 0.
     REPLACE ' ' WITH 'X' INTO wa_bapi_mbew_x.
   ENDWHILE.
 ENDIF.
 MOVE wa_mbew-bwkey TO wa_bapi_mbew_x-val_area.
 MOVE wa_mbew-bwtar TO wa_bapi_mbew_x-val_type.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M L A N                          *
*---------------------------------------------------------------------*
* Steuerklassifikation zum Material. Interne Tabelle aufbauen und zur *
* Verfügung. Gilt für alle Klassifikationen dieses Materiales         *
*---------------------------------------------------------------------*
FORM upro-bapi_mlan.

 CLEAR:   itab_bapi_mlan.
 REFRESH: itab_bapi_mlan.

 LOOP AT itab_mlan INTO wa_mlan WHERE matnr = wa_mara-matnr.
   CLEAR: itab_bapi_mlan.

   MOVE wa_mlan-aland TO itab_bapi_mlan-depcountry.
   MOVE wa_mlan-taxm1 TO itab_bapi_mlan-taxclass_1.
   MOVE wa_mlan-taxm2 TO itab_bapi_mlan-taxclass_2.
   MOVE wa_mlan-taxm3 TO itab_bapi_mlan-taxclass_3.
   MOVE wa_mlan-taxm4 TO itab_bapi_mlan-taxclass_4.
   MOVE wa_mlan-taxm5 TO itab_bapi_mlan-taxclass_5.
   MOVE wa_mlan-taxm6 TO itab_bapi_mlan-taxclass_6.
   MOVE wa_mlan-taxm7 TO itab_bapi_mlan-taxclass_7.
   MOVE wa_mlan-taxm8 TO itab_bapi_mlan-taxclass_8.
   MOVE wa_mlan-taxm9 TO itab_bapi_mlan-taxclass_9.
   MOVE wa_mlan-taxim TO itab_bapi_mlan-tax_ind.

*   MOVE WA_??? TO ITAB_BAPI_MLAN-DEPCOUNTRY_ISO.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_1.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_2.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_3.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_4.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_5.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_6.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_7.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_8.
*   MOVE WA_??? TO ITAB_BAPI_MLAN-TAX_TYPE_9.

   APPEND itab_bapi_mlan.
 ENDLOOP.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M L G N                          *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
FORM upro-bapi_mlgn.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_mlgn TO wa_bapi_mlgn.

 MOVE wa_mlgn-lgnum TO wa_bapi_mlgn-whse_no.
 MOVE wa_mlgn-lvorm TO wa_bapi_mlgn-del_flag.
 MOVE wa_mlgn-lgbkz TO wa_bapi_mlgn-stgesector.
 MOVE wa_mlgn-ltkze TO wa_bapi_mlgn-placement.
 MOVE wa_mlgn-ltkza TO wa_bapi_mlgn-withdrawal.
 MOVE wa_mlgn-lhmg1 TO wa_bapi_mlgn-l_equip_1.
 MOVE wa_mlgn-lhmg2 TO wa_bapi_mlgn-l_equip_2.
 MOVE wa_mlgn-lhmg3 TO wa_bapi_mlgn-l_equip_3.
 MOVE wa_mlgn-lhme1 TO wa_bapi_mlgn-leq_unit_1.
 MOVE wa_mlgn-lhme2 TO wa_bapi_mlgn-leq_unit_2.
 MOVE wa_mlgn-lhme3 TO wa_bapi_mlgn-leq_unit_3.
 MOVE wa_mlgn-lety1 TO wa_bapi_mlgn-unittype_1.
 MOVE wa_mlgn-lety2 TO wa_bapi_mlgn-unittype_2.
 MOVE wa_mlgn-lety3 TO wa_bapi_mlgn-unittype_3.
 MOVE wa_mlgn-lvsme TO wa_bapi_mlgn-wm_unit.
 MOVE wa_mlgn-kzzul TO wa_bapi_mlgn-add_to_stk.
 MOVE wa_mlgn-block TO wa_bapi_mlgn-block_stge.
 MOVE wa_mlgn-kzmbf TO wa_bapi_mlgn-msg_to_im.
 MOVE wa_mlgn-bsskz TO wa_bapi_mlgn-spec_mvmt.
 MOVE wa_mlgn-mkapv TO wa_bapi_mlgn-capy_usage.
 MOVE wa_mlgn-bezme TO wa_bapi_mlgn-procure_un.
 MOVE wa_mlgn-plkpt TO wa_bapi_mlgn-stge_type.
 MOVE wa_mlgn-vomem TO wa_bapi_mlgn-ref_unit.
* MOVE WA_MLGN-L2SKR TO WA_.

* MOVE WA_ ??? TO WA_BAPI_MLGN-LEQ_UNIT_1_ISO.
* MOVE WA_ ??? TO WA_BAPI_MLGN-LEQ_UNIT_2_ISO.
* MOVE WA_ ??? TO WA_BAPI_MLGN-LEQ_UNIT_3_ISO.
* MOVE WA_ ??? TO WA_BAPI_MLGN-WM_UNIT_ISO.
* MOVE WA_ ??? TO WA_BAPI_MLGN-PROCURE_UN_ISO.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M L G T                          *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
FORM upro-bapi_mlgt.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_mlgt TO wa_bapi_mlgt.

 MOVE wa_mlgt-lgnum TO wa_bapi_mlgt-whse_no.
 MOVE wa_mlgt-lgtyp TO wa_bapi_mlgt-stge_type.
 MOVE wa_mlgt-lvorm TO wa_bapi_mlgt-del_flag.
 MOVE wa_mlgt-lgpla TO wa_bapi_mlgt-stge_bin.
 MOVE wa_mlgt-lpmax TO wa_bapi_mlgt-max_sb_qty.
 MOVE wa_mlgt-lpmin TO wa_bapi_mlgt-min_sb_qty.
 MOVE wa_mlgt-mamng TO wa_bapi_mlgt-ctrl_qty.
 MOVE wa_mlgt-nsmng TO wa_bapi_mlgt-replen_qty.
 MOVE wa_mlgt-kober TO wa_bapi_mlgt-pick_area.
 MOVE wa_mlgt-rdmng TO wa_bapi_mlgt-round_qty.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M V K E                          *
*---------------------------------------------------------------------*
*                                                                     *
*---------------------------------------------------------------------*
FORM upro-bapi_mvke.

* so werden kundeneigene Strukturen mit übertragen
 MOVE-CORRESPONDING wa_mvke TO wa_bapi_mvke.

 MOVE wa_mvke-vkorg TO wa_bapi_mvke-sales_org.
 MOVE wa_mvke-vtweg TO wa_bapi_mvke-distr_chan.
 MOVE wa_mvke-lvorm TO wa_bapi_mvke-del_flag.
 MOVE wa_mvke-versg TO wa_bapi_mvke-matl_stats.
 MOVE wa_mvke-bonus TO wa_bapi_mvke-rebate_grp.
 MOVE wa_mvke-provg TO wa_bapi_mvke-comm_group.
 MOVE wa_mvke-sktof TO wa_bapi_mvke-cash_disc.
 MOVE wa_mvke-vmsta TO wa_bapi_mvke-sal_status.
 MOVE wa_mvke-vmstd TO wa_bapi_mvke-valid_from.
 MOVE wa_mvke-aumng TO wa_bapi_mvke-min_order.
 MOVE wa_mvke-lfmng TO wa_bapi_mvke-min_dely.
 MOVE wa_mvke-efmng TO wa_bapi_mvke-min_mto.
 MOVE wa_mvke-scmng TO wa_bapi_mvke-dely_unit.
 MOVE wa_mvke-schme TO wa_bapi_mvke-dely_uom.
 MOVE wa_mvke-vrkme TO wa_bapi_mvke-sales_unit.
 MOVE wa_mvke-mtpos TO wa_bapi_mvke-item_cat.
 MOVE wa_mvke-dwerk TO wa_bapi_mvke-delyg_plnt.
 MOVE wa_mvke-prodh TO wa_bapi_mvke-prod_hier.
 MOVE wa_mvke-pmatn TO wa_bapi_mvke-pr_ref_mat.
 MOVE wa_mvke-kondm TO wa_bapi_mvke-mat_pr_grp.
 MOVE wa_mvke-ktgrm TO wa_bapi_mvke-acct_assgt.
 MOVE wa_mvke-mvgr1 TO wa_bapi_mvke-matl_grp_1.
 MOVE wa_mvke-mvgr2 TO wa_bapi_mvke-matl_grp_2.
 MOVE wa_mvke-mvgr3 TO wa_bapi_mvke-matl_grp_3.
 MOVE wa_mvke-mvgr4 TO wa_bapi_mvke-matl_grp_4.
 MOVE wa_mvke-mvgr5 TO wa_bapi_mvke-matl_grp_5.
* MOVE WA_MVKE-SSTUF TO WA_.
* MOVE WA_MVKE-PFLKS TO WA_.
* MOVE WA_MVKE-LSTFL TO WA_.
* MOVE WA_MVKE-LSTVZ TO WA_.
* MOVE WA_MVKE-LSTAK TO WA_.
* MOVE WA_MVKE-LDVFL TO WA_.
* MOVE WA_MVKE-LDBFL TO WA_.
* MOVE WA_MVKE-LDVZL TO WA_.
* MOVE WA_MVKE-LDBZL TO WA_.
* MOVE WA_MVKE-VDVFL TO WA_.
* MOVE WA_MVKE-VDBFL TO WA_.
* MOVE WA_MVKE-VDVZL TO WA_.
* MOVE WA_MVKE-VDBZL TO WA_.
 MOVE wa_mvke-prat1 TO wa_bapi_mvke-prod_att_1.
 MOVE wa_mvke-prat2 TO wa_bapi_mvke-prod_att_2.
 MOVE wa_mvke-prat3 TO wa_bapi_mvke-prod_att_3.
 MOVE wa_mvke-prat4 TO wa_bapi_mvke-prod_att_4.
 MOVE wa_mvke-prat5 TO wa_bapi_mvke-prod_att_5.
 MOVE wa_mvke-prat6 TO wa_bapi_mvke-prod_att_6.
 MOVE wa_mvke-prat7 TO wa_bapi_mvke-prod_att_7.
 MOVE wa_mvke-prat8 TO wa_bapi_mvke-prod_att_8.
 MOVE wa_mvke-prat9 TO wa_bapi_mvke-prod_att_9.
 MOVE wa_mvke-prata TO wa_bapi_mvke-prod_att10.
 MOVE wa_mvke-rdprf TO wa_bapi_mvke-round_prof.
 MOVE wa_mvke-megru TO wa_bapi_mvke-unit_group.
* MOVE WA_MVKE-LFMAX TO WA_.
* MOVE WA_MVKE-RJART TO WA_.
* MOVE WA_MVKE-PBIND TO WA_.
 MOVE wa_mvke-vavme TO wa_bapi_mvke-var_sales_un.
* MOVE WA_MVKE-MATKC TO WA_.
* MOVE WA_MVKE-PVMSO TO WA_.

* MOVE WA_ ??? TO WA_BAPI_MVKE-DELY_UOM_ISO.
* MOVE WA_ ??? TO WA_BAPI_MVKE-SALES_UNIT_ISO.
* MOVE WA_ ??? TO WA_BAPI_MVKE-PR_REF_MAT_EXTERNAL.
* MOVE WA_ ??? TO WA_BAPI_MVKE-PR_REF_MAT_GUID.
* MOVE WA_ ??? TO WA_BAPI_MVKE-PR_REF_MAT_VERSION.

ENDFORM.

*---------------------------------------------------------------------*
*                          B A P I _ M L T X                          *
*---------------------------------------------------------------------*
* Die Langtexte werden nich im BAPI verarbeitet ! Es ist notwendig,   *
* sie zum Material über einen eigenen Funktionsbaustein anzulegen.    *
*---------------------------------------------------------------------*
* Alle Langtexte (Grundtexte, Prüftexte, Einkaufsbestelltexte, interne*
* Vermerke) aller Sprachen zum dem aktuell im Zugriff befindlichen    *
* Material werden angelegt oder upgedatet.                            *
*---------------------------------------------------------------------*
FORM upro-bapi_mltx.

 LOOP AT itab_mltx INTO wa_mltx
 WHERE tdname = pm_matnr.
   MOVE 'MATERIAL'       TO itab_bapi_mltx-applobject.
   MOVE pmmatneu         TO itab_bapi_mltx-text_name.
   MOVE wa_mltx-tdid     TO itab_bapi_mltx-text_id.
   MOVE wa_mltx-spras    TO itab_bapi_mltx-langu.
*   move wa_mltx-         to itab_bapi_mltx-LANGU_ISO.
   MOVE wa_mltx-tdformat TO itab_bapi_mltx-format_col.
   MOVE wa_mltx-zeile    TO itab_bapi_mltx-text_line.
*   move wa_mltx-         to itab_bapi_mltx-DEL_FLAG.

   APPEND itab_bapi_mltx.
 ENDLOOP.

ENDFORM.

*---------------------------------------------------------------------*
*            B A P I _ M A T E R I A L _ S A V E D A T A              *
*---------------------------------------------------------------------*
* Aufruf des BAPI-Bausteines für Änderungen am Material. Die internen *
* Tabellen und Strukturen werden über die anderen Unterprogramme auf- *
* gebaut und zur Verfügung gestellt. Die Standardrückmeldung (ob      *
* erfolgreich oder mit Fehler) wird in die Fehlerprotokolltabelle     *
* zurückübertragen.                                                   *
*---------------------------------------------------------------------*
FORM upro-bapi_material_savedata.

 CLEAR:   itab_bapi_return.
 REFRESH: itab_bapi_return.

* BAPI aufrufen
 CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
     EXPORTING
          headdata             = wa_bapi_basis
          clientdata           = wa_bapi_mara
          clientdatax          = wa_bapi_mara_x
          plantdata            = wa_bapi_marc
          plantdatax           = wa_bapi_marc_x
*          FORECASTPARAMETERS   =
*          FORECASTPARAMETERSX  =
*          PLANNINGDATA         =
*          PLANNINGDATAX        =
          storagelocationdata  = wa_bapi_mard
          storagelocationdatax = wa_bapi_mard_x
          valuationdata        = wa_bapi_mbew
          valuationdatax       = wa_bapi_mbew_x
          warehousenumberdata  = wa_bapi_mlgn
          warehousenumberdatax = wa_bapi_mlgn_x
          salesdata            = wa_bapi_mvke
          salesdatax           = wa_bapi_mvke_x
          storagetypedata      = wa_bapi_mlgt
          storagetypedatax     = wa_bapi_mlgt_x
*          FLAG_ONLINE          = ' '
     IMPORTING
          return               = wa_bapi_return
     TABLES
          materialdescription  = itab_bapi_makt
          unitsofmeasure       = itab_bapi_marm
          unitsofmeasurex      = itab_bapi_marm_x
*          INTERNATIONALARTNOS  =
          materiallongtext     = itab_bapi_mltx
          taxclassifications   = itab_bapi_mlan
          returnmessages       = itab_bapi_return
*          PRTDATA              =
*          PRTDATAX             =
*          EXTENSIONIN          =
*          EXTENSIONINX         =
  .
* Commit Work muß sein, damit die Materialdatenänderung aktiv ist
* wenn das Material erfolgreich abgeändert wurde
 IF wa_bapi_return-type = 'S'.
   COMMIT WORK.
 ENDIF.

* Materialnummer, Werk, Lagerort  mit in der Fehlerprotokollstruktur
* speichern, um einfachere Möglichkeiten der Kontrolle zu haben
 MOVE wa_bapi_basis-material TO wa_bapi_return-parameter.
 MOVE ':'                    TO wa_bapi_return-parameter+19(1).
 MOVE wa_bapi_marc-plant     TO wa_bapi_return-parameter+21(4).
 MOVE ':'                    TO wa_bapi_return-parameter+26(1).
 MOVE wa_bapi_mard-stge_loc  TO wa_bapi_return-parameter+28(4).

* kein Werk (Sicht Disposition oder ähnliche) vorhanden, aber die
* Sichten Buchhaltung oder Kalkulation wurden bearbeitet, dann
* alternativ an die Stelle des Werkes den Bewertungskreis einpflegen
 IF wa_bapi_marc-plant IS INITIAL
 AND ( wa_bapi_basis-account_view = 'X'
    OR wa_bapi_basis-cost_view    = 'X' ).
   MOVE wa_bapi_mbew-val_area TO wa_bapi_return-parameter+21(4).
 ENDIF.

* Standardmeldung in anterne Fehlerprotokolltabelle anhängen
 APPEND wa_bapi_return TO itab_prot.

ENDFORM.

*---------------------------------------------------------------------*
*                      E C H T _ E R G E B N I S                      *
*---------------------------------------------------------------------*
* BAPI-Lauf auswerten. Alle Meldungen für das Speichern auf Datei     *
* vorbereiten und wenn gewünscht am Bildschirm anzeigen. Dabei beach- *
* ten, welche Warnstufen angezeigt werden sollen.                     *
*---------------------------------------------------------------------*
FORM upro-echt_ergebnis.

 CLEAR: anzahl_rot, anzahl_gelb, anzahl_gruen.

 LOOP AT itab_prot INTO wa_bapi_return.
* interne Tabelle für Dateischreiben vorbereiten
*    MOVE wa_bapi_return-parameter       TO wa_out-matnr.
*    MOVE wa_bapi_return-parameter+21(4) TO wa_out-werks.
*    MOVE wa_bapi_return-type            TO wa_out-type.
*    MOVE wa_bapi_return-id              TO wa_out-id.
*    MOVE wa_bapi_return-number          TO wa_out-number.
*    MOVE wa_bapi_return-message         TO wa_out-message.
*    MOVE wa_out                         TO ds_out-satz.
*    APPEND ds_out TO dstab_out.

* Meldungen am Bildschirm anzeigen, gemäß Stufe Ampel am Bildschirm
* bringen, jedoch Warnstufe beachten, welche gewünscht wurde beim
* Einstieg
   CONCATENATE wa_bapi_return-parameter
               wa_bapi_return-message
               INTO zw_text SEPARATED BY ' '.

   CASE wa_bapi_return-type.
     WHEN 'A'.
       ADD 1 TO anzahl_rot.
       WRITE AT: /1 icon_defect AS ICON,
                  7 zw_text.
     WHEN 'E'.
       ADD 1 TO anzahl_rot.
       WRITE AT: /1 icon_red_light AS ICON,
                  7 zw_text.
     WHEN 'W'.
       ADD 1 TO anzahl_gelb.
       IF pmx_gelb = 'X'
       OR pmxgruen = 'X'.
         WRITE AT: /1 icon_yellow_light AS ICON,
                    7 zw_text.
       ENDIF.
     WHEN 'S'.
       ADD 1 TO anzahl_gruen.
       IF pmxgruen = 'X'.
         WRITE AT: /1 icon_green_light AS ICON,
                    7 zw_text.
       ENDIF.
   ENDCASE.
 ENDLOOP.

* Gesamtanzahl der Meldungen anzeigen, welche niedriger sind als die
* gewünschte Warnstufe
 SKIP 1.

 IF pmx_gelb = ' '
 AND anzahl_gelb > 0.
   WRITE AT: /1 icon_yellow_light AS ICON,
              7 anzahl_gelb,
             14 'Materialen mit Warnung.'.
 ENDIF.
 IF pmxgruen = ' '
 AND anzahl_gruen > 0.
   WRITE AT: /1 icon_green_light AS ICON,
              7 anzahl_gruen,
             14 'fehlerfreie Durchläufe'.
 ENDIF.

ENDFORM.

***** Ende *****
* Copyright BJH Software, Datei überarbeitet am: 23.7.2005