*---------------------------------------------------------------------*
*               Z _ B J H _ B A P I _ P O _ C R E A T E 1             *
*                                                                     *
*                   Autor: Bernd Haase (BJH Software)                 *
*---------------------------------------------------------------------*
* Beispiel für Ansteuern des Bapis "BAPI_PO_CREATE1" (Enjoy-Version). *
* Programm simuliert das Kopieren einer bestehenden Bestellung. Alle  *
* Programmparts sind in Classic ABAP geschrieben !!! Das Programm     *
* liest für das Beispiel eine andere Bestellung ein, kopiert diese in *
* die entsprechenden Felder und Tabellen, die der BAPI verarbeiten    *
* soll. Nach Durchlauf des Bapis kann der Status angezeigt werden,    *
* zur grafischen Unterstützung mit einer Ampel.                       *
*---------------------------------------------------------------------*
* BAPI_PO_CREATE1, Warnstufe BAPI                                     *
*---------------------------------------------------------------------*
* 28.10.2003 BHaa: Programm erstellt                                  *
* 27.09.2004 BHaa: Warnstufen beim Bapi-Ergebnis                  V1.1*
*---------------------------------------------------------------------*
REPORT  z_bjh_bapi_po_create1 .

INCLUDE <icon>.

TABLES:
 ekko,    "Einkaufsbelegkopf
 ekpo,    "Einkaufsbelegposition
 eket,    "Lieferplaneinteilungen
 konv.    "Konditionen (Vorgangsdaten)

DATA:
 wa_ekko LIKE ekko,
 wa_ekpo LIKE ekpo,
 wa_eket LIKE eket,
 wa_konv LIKE konv,

 anzahl TYPE n,
* Anzahl der einzelnen Warnstufen nach BAPI-Aufruf
 anzahl_rot    LIKE anzahl,
 anzahl_gelb   LIKE anzahl,
 anzahl_gruen  LIKE anzahl,

 zw_datum LIKE eket-eindt,
 zw_text(100) TYPE c.

*********************
* BAPI - Strukturen *
*********************
DATA:
* Felder, Tabellen und Strukturen für das Bapi
 wa_bapi_return LIKE bapiret2,

* Strukturen mit X am Ende = Änderungsflagstrukturen
 wa_bapi_ekko   LIKE bapimepoheader,
 wa_bapi_ekko_x LIKE bapimepoheaderx,

 wa_bapi_ekpo   LIKE bapimepoitem,
 wa_bapi_ekpo_x LIKE bapimepoitemx,

 wa_bapi_eket   LIKE bapimeposchedule,
 wa_bapi_eket_x LIKE bapimeposchedulx,

 wa_bapi_konv   LIKE bapimepocond,
 wa_bapi_konv_x LIKE bapimepocondx,

 z_eket LIKE eket-etenr,
 z_konv LIKE bapimepocond-cond_st_no,
 wa_fehlerhaft(1) TYPE c,

* Übergabetabellen an das Bapi, muß den Occurs-Aufbau haben, die
* Deklaration als like table of funktioniert nicht
* Bapi Tabellen sind immer 2 Tabellen ! 1=Wertefelder, 2=Änderungsflag
 BEGIN OF itab_bapi_ekpo OCCURS 0.
       INCLUDE STRUCTURE bapimepoitem.
DATA:
 END OF itab_bapi_ekpo,

 BEGIN OF itab_bapi_ekpo_x  OCCURS 0.
       INCLUDE STRUCTURE bapimepoitemx.
DATA:
 END OF itab_bapi_ekpo_x,

 BEGIN OF itab_bapi_eket OCCURS 0.
       INCLUDE STRUCTURE bapimeposchedule.
DATA:
 END OF itab_bapi_eket,

 BEGIN OF itab_bapi_eket_x OCCURS 0.
       INCLUDE STRUCTURE bapimeposchedulx.
DATA:
 END OF itab_bapi_eket_x,

 BEGIN OF itab_bapi_konv OCCURS 0.
       INCLUDE STRUCTURE bapimepocond.
DATA:
 END OF itab_bapi_konv,

 BEGIN OF itab_bapi_konv_x OCCURS 0.
       INCLUDE STRUCTURE bapimepocondx.
DATA:
 END OF itab_bapi_konv_x,

 BEGIN OF itab_bapi_return OCCURS 0.
       INCLUDE STRUCTURE bapiret2.
DATA:
 END OF itab_bapi_return.
* Ende Tabellen für das Bapi

*---------------------------------------------------------------------*
*                                                                     *
*                 A u s w a h l b i l d s c h i r m                   *
*                                                                     *
*---------------------------------------------------------------------*
* Bestellnummer und Auswahl der Aktionen
SELECTION-SCREEN: BEGIN OF BLOCK a1 WITH FRAME TITLE text-901.
PARAMETERS:
* Basisbestellung
 pmebeln     LIKE ekko-ebeln.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) text-s06 FOR FIELD pmmeld.
* Meldungen anzeigen oder nicht
PARAMETERS pmmeld  TYPE c DEFAULT 'X' AS CHECKBOX.
SELECTION-SCREEN END OF LINE.

PARAMETERS:
* Variablen (Eröffnungsdatum) neu berechnen oder nicht
 pmdatneu(1) TYPE c DEFAULT 'J',
* Variablen (Datum Lieferungen) neu berechnen oder nicht
 pmdatlf(1)  TYPE c DEFAULT 'J'.
SELECTION-SCREEN: END OF BLOCK a1.

* Fehler anzeigen. Alle Meldungen oder nur Fehler und Warnungen
SELECTION-SCREEN: BEGIN OF BLOCK a2 WITH FRAME TITLE text-902.
PARAMETERS:
* Programmlauf, Aktionsumfang bestimmen
* Testlauf oder Echtlauf mit Update und Commit
 pmx_echt TYPE c RADIOBUTTON GROUP grp1,
 pmx_test TYPE c RADIOBUTTON GROUP grp1 DEFAULT 'X',
* Warnstufenanzeige
 pmx_rot  TYPE c RADIOBUTTON GROUP grp2,
 pmx_gelb TYPE c RADIOBUTTON GROUP grp2 DEFAULT 'X',
 pmxgruen TYPE c RADIOBUTTON GROUP grp2.
SELECTION-SCREEN: END OF BLOCK a2.

INITIALIZATION.
 CLEAR: wa_bapi_ekko_x,
        itab_bapi_ekpo, itab_bapi_ekpo_x,
        itab_bapi_eket, itab_bapi_eket_x,
        itab_bapi_return, anzahl.

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

* Kopfdaten der ausgewählten / gewünschten Bestellung einlesen
 SELECT * FROM ekko INTO wa_ekko
 WHERE ebeln = pmebeln.
   PERFORM upro-bapi_ekko.

* Positionsdaten einzeln einlesen
   SELECT * FROM ekpo INTO wa_ekpo
   WHERE ebeln = wa_ekko-ebeln.
     MOVE 0 TO: z_eket, z_konv.

* Einteilungen zur aktuellen Position einlesen
* und diese in die Bapi-Tabelle überspielen
     SELECT * FROM eket INTO wa_eket
     WHERE ebeln = wa_ekko-ebeln
     AND ebelp = wa_ekpo-ebelp.
       PERFORM upro-bapi_eket.
     ENDSELECT.

* Konditionen zur aktuellen Position einlesen
* und diese in die Bapi-Tabelle überspielen
* Konditionssatznummer wird zentral im Datenkopf gepflegt !!!
     SELECT * FROM konv INTO wa_konv
     WHERE knumv = wa_ekko-knumv
     AND kposn = wa_ekpo-ebelp.
       PERFORM upro-bapi_konv.
     ENDSELECT.

* Positionsdaten in die Bapi-Tabelle überspielen
     PERFORM upro-bapi_ekpo.

     ADD 1 TO anzahl.

   ENDSELECT.

* Fehlermeldung, Bestellung ohne Positionen
   IF sy-subrc <> 0.
    WRITE: / 'Keine Positionen zur Bestellung ', pmebeln, 'vorhanden.'.
   ENDIF.
 ENDSELECT.

* Fehlermeldung, falls falsche Nummer eingegeben wurde
 IF sy-subrc <> 0.
   WRITE: / 'Die Bestellung ', pmebeln, 'existiert nicht.'.
 ENDIF.

* Positionen wurden gefunden. BAPI aufrufen
 IF anzahl > 0.
   PERFORM upro-bapi_po_create1
           TABLES   itab_bapi_return
                    itab_bapi_ekpo itab_bapi_ekpo_x
                    itab_bapi_eket itab_bapi_eket_x
                    itab_bapi_konv itab_bapi_konv_x
           USING    wa_bapi_ekko   wa_bapi_ekko_x
                    pmx_test
           CHANGING wa_fehlerhaft
                    wa_ekko-ebeln.

   PERFORM upro-bapi_ergebnis.

 ENDIF.

*---------------------------------------------------------------------*
*                                                                     *
*              U P R O - B A P I _ P O _ C R E A T E 1                *
*                                                                     *
*---------------------------------------------------------------------*
*             Funktionsbaustein und Variablenversorgung               *
*                                                                     *
* Allgemeines Upr für verschiedenartige Verwendungen. Wichtig ist nur *
* die Einhaltung der Übergabeparameter. Diese müssen global definiert *
* sein, es erfolgt in den Aufbautabellen keine Übergabe der Parameter *
* nur das Upros für den Funktionsaufruf enthält welche !              *
*---------------------------------------------------------------------*
* Upro für Struktur Bapi <=> Ddic über z_bjh_tabellenabgleich         *
*---------------------------------------------------------------------*

*---------------------------------------------------------------------*
*                         B A P I _ E K K O                           *
*---------------------------------------------------------------------*
* Bestellung. Kopfdaten. Alle Felder der BAPI-Struktur im Vergleich zu*
* den Felder der EKKO. Nicht gebrauchte Felder der BAPI-Struktur sind *
* als Kommentar angezeigt, nicht gebrauchte der EKKO jedoch nicht.    *
*---------------------------------------------------------------------*
FORM upro-bapi_ekko.

*MOVE EKKO-MANDT TO WA_BAPI_EKKO__.
*  MOVE wa_ekko-ebeln TO wa_bapi_ekko-po_number.
 CLEAR: wa_bapi_ekko-po_number.

 MOVE wa_ekko-bukrs TO wa_bapi_ekko-comp_code.
 MOVE wa_ekko-bsart TO wa_bapi_ekko-doc_type.
 MOVE wa_ekko-loekz TO wa_bapi_ekko-delete_ind.
 MOVE wa_ekko-statu TO wa_bapi_ekko-status.
* Datum, welches nutzen. Wenn keine Neuberechnung kann die Warnung
* auftreten, Bestelldatum liegt in der Vergangenheit
 IF pmdatneu = 'J'.
   MOVE sy-datum      TO wa_bapi_ekko-creat_date.
 ELSE.
   MOVE wa_ekko-aedat TO wa_bapi_ekko-creat_date.
 ENDIF.
 MOVE wa_ekko-ernam TO wa_bapi_ekko-created_by.
 MOVE wa_ekko-pincr TO wa_bapi_ekko-item_intvl.
 MOVE wa_ekko-lifnr TO wa_bapi_ekko-vendor.
 MOVE wa_ekko-spras TO wa_bapi_ekko-langu.
 MOVE 'DE'          TO wa_bapi_ekko-langu_iso.
 MOVE wa_ekko-zterm TO wa_bapi_ekko-pmnttrms.
 MOVE wa_ekko-zbd1t TO wa_bapi_ekko-dscnt1_to.
 MOVE wa_ekko-zbd2t TO wa_bapi_ekko-dscnt2_to.
 MOVE wa_ekko-zbd3t TO wa_bapi_ekko-dscnt3_to.
 MOVE wa_ekko-zbd1p TO wa_bapi_ekko-dsct_pct1.
 MOVE wa_ekko-zbd2p TO wa_bapi_ekko-dsct_pct2.
 MOVE wa_ekko-ekorg TO wa_bapi_ekko-purch_org.
 MOVE wa_ekko-ekgrp TO wa_bapi_ekko-pur_group.
 MOVE wa_ekko-waers TO wa_bapi_ekko-currency.
*MOVE BAPIMEPOHEADER-CURRENCY_ISO TO.
 MOVE wa_ekko-wkurs TO wa_bapi_ekko-exch_rate.
 MOVE wa_ekko-kufix TO wa_bapi_ekko-ex_rate_fx.
 IF pmdatneu = 'J'.
   wa_bapi_ekko-doc_date = sy-datum.
 ELSE.
   MOVE wa_ekko-bedat TO wa_bapi_ekko-doc_date.
 ENDIF.
 MOVE wa_ekko-kdatb TO wa_bapi_ekko-vper_start.
 MOVE wa_ekko-kdate TO wa_bapi_ekko-vper_end.
 MOVE wa_ekko-gwldt TO wa_bapi_ekko-warranty.
*MOVE BAPIMEPOHEADER-QUOTATION TO.
 MOVE wa_ekko-ihran TO wa_bapi_ekko-quot_date.
 MOVE wa_ekko-ihrez TO wa_bapi_ekko-ref_1.
 MOVE wa_ekko-verkf TO wa_bapi_ekko-sales_pers.
 MOVE wa_ekko-telf1 TO wa_bapi_ekko-telephone.
 MOVE wa_ekko-llief TO wa_bapi_ekko-suppl_vend.
 MOVE wa_ekko-kunnr TO wa_bapi_ekko-customer.
 MOVE wa_ekko-weakt TO wa_bapi_ekko-gr_message.
 MOVE wa_ekko-reswk TO wa_bapi_ekko-suppl_plnt.
 MOVE wa_ekko-inco1 TO wa_bapi_ekko-incoterms1.
 MOVE wa_ekko-inco2 TO wa_bapi_ekko-incoterms2.
 MOVE wa_ekko-submi TO wa_bapi_ekko-collect_no.
 MOVE wa_ekko-lifre TO wa_bapi_ekko-diff_inv.
 MOVE wa_ekko-unsez TO wa_bapi_ekko-our_ref.
 MOVE wa_ekko-logsy TO wa_bapi_ekko-logsystem.
 MOVE wa_ekko-upinc TO wa_bapi_ekko-subitemint.
 MOVE wa_ekko-frgke TO wa_bapi_ekko-po_rel_ind.
 MOVE wa_ekko-frgzu TO wa_bapi_ekko-rel_status.
 MOVE wa_ekko-stceg_l TO wa_bapi_ekko-vat_cntry.
*MOVE BAPIMEPOHEADER-REASON_CANCEL TO.

* alle Felder der BAPI-Struktur auf geändert setzen
 CLEAR: wa_bapi_ekko_x, sy-subrc.
 WHILE sy-subrc = 0.
   REPLACE ' ' WITH 'X' INTO wa_bapi_ekko_x.
 ENDWHILE.

ENDFORM.

*---------------------------------------------------------------------*
*                         B A P I _ E K P O                           *
*---------------------------------------------------------------------*
* allgemeine Positionsdaten. Erklärung siehe Kopfdaten                *
*---------------------------------------------------------------------*
FORM upro-bapi_ekpo.

 MOVE wa_ekpo-ebelp TO wa_bapi_ekpo-po_item.
 MOVE wa_ekpo-loekz TO wa_bapi_ekpo-delete_ind.
 MOVE wa_ekpo-txz01 TO wa_bapi_ekpo-short_text.
 MOVE wa_ekpo-matnr TO wa_bapi_ekpo-material.
 MOVE wa_ekpo-ematn TO wa_bapi_ekpo-ematerial.
*MOVE BAPIMEPOITEM-MATERIAL_EXTERNAL TO ..
*MOVE BAPIMEPOITEM-MATERIAL_GUID TO ..
*MOVE BAPIMEPOITEM-MATERIAL_VERSION TO ..
 MOVE wa_ekpo-werks TO wa_bapi_ekpo-plant.
 MOVE wa_ekpo-lgort TO wa_bapi_ekpo-stge_loc.
 MOVE wa_ekpo-bednr TO wa_bapi_ekpo-trackingno.
 MOVE wa_ekpo-matkl TO wa_bapi_ekpo-matl_group.
 MOVE wa_ekpo-infnr TO wa_bapi_ekpo-info_rec.
 MOVE wa_ekpo-idnlf TO wa_bapi_ekpo-vend_mat.
 MOVE wa_ekpo-menge TO wa_bapi_ekpo-quantity.
 MOVE wa_ekpo-meins TO wa_bapi_ekpo-po_unit.
*MOVE BAPIMEPOITEM-PO_UNIT_ISO TO ..
 MOVE wa_ekpo-bprme TO wa_bapi_ekpo-orderpr_un.
*MOVE BAPIMEPOITEM-ORDERPR_UN_ISO TO ..
 MOVE wa_ekpo-bpumz TO wa_bapi_ekpo-conv_num1.
 MOVE wa_ekpo-bpumn TO wa_bapi_ekpo-conv_den1.
* Nettopreis in Belegwährung (Einzelpreis)
 MOVE wa_ekpo-netpr TO wa_bapi_ekpo-net_price.
 MOVE wa_ekpo-peinh TO wa_bapi_ekpo-price_unit.
 MOVE wa_ekpo-webaz TO wa_bapi_ekpo-gr_pr_time.
 MOVE wa_ekpo-mwskz TO wa_bapi_ekpo-tax_code.
 MOVE wa_ekpo-bonus TO wa_bapi_ekpo-bon_grp1.
 MOVE wa_ekpo-insmk TO wa_bapi_ekpo-qual_insp.
 MOVE wa_ekpo-spinf TO wa_bapi_ekpo-info_upd.
 MOVE wa_ekpo-prsdr TO wa_bapi_ekpo-prnt_price.
 MOVE wa_ekpo-schpr TO wa_bapi_ekpo-est_price.
 MOVE wa_ekpo-mahn1 TO wa_bapi_ekpo-reminder1.
 MOVE wa_ekpo-mahn2 TO wa_bapi_ekpo-reminder2.
 MOVE wa_ekpo-mahn3 TO wa_bapi_ekpo-reminder3.
 MOVE wa_ekpo-uebto TO wa_bapi_ekpo-over_dlv_tol.
 MOVE wa_ekpo-uebtk TO wa_bapi_ekpo-unlimited_dlv.
 MOVE wa_ekpo-untto TO wa_bapi_ekpo-under_dlv_tol.
 MOVE wa_ekpo-bwtar TO wa_bapi_ekpo-val_type.
 MOVE wa_ekpo-elikz TO wa_bapi_ekpo-no_more_gr.
 MOVE wa_ekpo-erekz TO wa_bapi_ekpo-final_inv.
 MOVE wa_ekpo-pstyp TO wa_bapi_ekpo-item_cat.
 MOVE wa_ekpo-vrtkz TO wa_bapi_ekpo-distrib.
 MOVE wa_ekpo-twrkz TO wa_bapi_ekpo-part_inv.
 MOVE wa_ekpo-wepos TO wa_bapi_ekpo-gr_ind.
 MOVE wa_ekpo-weunb TO wa_bapi_ekpo-gr_non_val.
 MOVE wa_ekpo-repos TO wa_bapi_ekpo-ir_ind.
*MOVE BAPIMEPOITEM-FREE_ITEM TO ..
 MOVE wa_ekpo-webre TO wa_bapi_ekpo-gr_basediv.
 MOVE wa_ekpo-evers TO wa_bapi_ekpo-shipping.
 MOVE wa_ekpo-prdat TO wa_bapi_ekpo-price_date.
 MOVE wa_ekpo-kunnr TO wa_bapi_ekpo-customer.
 MOVE wa_ekpo-ekkol TO wa_bapi_ekpo-cond_group.
 MOVE wa_ekpo-sktof TO wa_bapi_ekpo-no_disct.
 MOVE wa_ekpo-plifz TO wa_bapi_ekpo-plan_del.
 MOVE wa_ekpo-ntgew TO wa_bapi_ekpo-net_weight.
 MOVE wa_ekpo-gewei TO wa_bapi_ekpo-weightunit.
*MOVE BAPIMEPOITEM-WEIGHTUNIT_ISO TO ..
 MOVE wa_ekpo-txjcd TO wa_bapi_ekpo-taxjurcode.
 MOVE wa_ekpo-ssqss TO wa_bapi_ekpo-ctrl_key.
 MOVE wa_ekpo-bstae TO wa_bapi_ekpo-conf_ctrl.
 MOVE wa_ekpo-revlv TO wa_bapi_ekpo-rev_lev.
 MOVE wa_ekpo-geber TO wa_bapi_ekpo-fund.
 MOVE wa_ekpo-fistl TO wa_bapi_ekpo-funds_ctr.
 MOVE wa_ekpo-fipos TO wa_bapi_ekpo-cmmt_item.
 MOVE wa_ekpo-meprf TO wa_bapi_ekpo-pricedate.
 MOVE wa_ekpo-brgew TO wa_bapi_ekpo-gross_wt.
 MOVE wa_ekpo-volum TO wa_bapi_ekpo-volume.
 MOVE wa_ekpo-voleh TO wa_bapi_ekpo-volumeunit.
*MOVE BAPIMEPOITEM-VOLUMEUNIT_ISO TO ..
 MOVE wa_ekpo-inco1 TO wa_bapi_ekpo-incoterms1.
 MOVE wa_ekpo-inco2 TO wa_bapi_ekpo-incoterms2.
 MOVE wa_ekpo-kolif TO wa_bapi_ekpo-pre_vendor.
 MOVE wa_ekpo-ltsnr TO wa_bapi_ekpo-vend_part.
 MOVE wa_ekpo-packno TO wa_bapi_ekpo-pckg_no.
 MOVE wa_ekpo-uebpo TO wa_bapi_ekpo-hl_item.
 MOVE wa_ekpo-lewed TO wa_bapi_ekpo-gr_to_date.
 MOVE wa_ekpo-emlif TO wa_bapi_ekpo-supp_vendor.
 MOVE wa_ekpo-lblkz TO wa_bapi_ekpo-sc_vendor.
 MOVE wa_ekpo-kanba TO wa_bapi_ekpo-kanban_ind.
 MOVE wa_ekpo-cuobj TO wa_bapi_ekpo-int_obj_no.
 MOVE wa_ekpo-xersy TO wa_bapi_ekpo-ers.
 MOVE wa_ekpo-aktnr TO wa_bapi_ekpo-r_promo.
 MOVE wa_ekpo-anzpu TO wa_bapi_ekpo-points.
 MOVE wa_ekpo-punei TO wa_bapi_ekpo-point_unit.
*MOVE BAPIMEPOITEM-POINT_UNIT_ISO TO ..
 MOVE wa_ekpo-saiso TO wa_bapi_ekpo-season.
 MOVE wa_ekpo-saisj TO wa_bapi_ekpo-season_yr.
 MOVE wa_ekpo-ebon2 TO wa_bapi_ekpo-bon_grp2.
 MOVE wa_ekpo-ebon3 TO wa_bapi_ekpo-bon_grp3.
 MOVE wa_ekpo-ebonf TO wa_bapi_ekpo-sett_item.
 MOVE wa_ekpo-mhdrz TO wa_bapi_ekpo-minremlife.
 MOVE wa_ekpo-anfnr TO wa_bapi_ekpo-rfq_no.
 MOVE wa_ekpo-anfps TO wa_bapi_ekpo-rfq_item.
 MOVE wa_ekpo-banfn TO wa_bapi_ekpo-preq_no.
 MOVE wa_ekpo-bnfpo TO wa_bapi_ekpo-preq_item.
 MOVE wa_ekpo-konnr TO wa_bapi_ekpo-ref_doc.
 MOVE wa_ekpo-ktpnr TO wa_bapi_ekpo-ref_item.
 MOVE wa_ekpo-uptyp TO wa_bapi_ekpo-si_cat.
 MOVE wa_ekpo-retpo TO wa_bapi_ekpo-ret_item.
 MOVE wa_ekpo-bsgru TO wa_bapi_ekpo-order_reason.
 MOVE wa_ekpo-j_1bnbm TO wa_bapi_ekpo-bras_nbm.
 MOVE wa_ekpo-j_1bmatuse TO wa_bapi_ekpo-matl_usage.
 MOVE wa_ekpo-j_1bmatorg TO wa_bapi_ekpo-mat_origin.
 MOVE wa_ekpo-j_1bownpro TO wa_bapi_ekpo-in_house.
 MOVE wa_ekpo-j_1bindust TO wa_bapi_ekpo-indus????.
 MOVE wa_ekpo-j_1aindxp TO wa_bapi_ekpo-inf_index.
 MOVE wa_ekpo-j_1aidatep TO wa_bapi_ekpo-until_date.
 MOVE wa_ekpo-eglkz TO wa_bapi_ekpo-deliv_compl.
 MOVE wa_ekpo-kztlf TO wa_bapi_ekpo-part_deliv.
 MOVE wa_ekpo-novet TO wa_bapi_ekpo-ship_blocked.
 MOVE wa_ekpo-afnam TO wa_bapi_ekpo-preq_name.
 MOVE wa_ekpo-iprkz TO wa_bapi_ekpo-period_ind_expiration_date.
*MOVE wa_ekpo- TO wa_bapi_ekpo-BAPIMEPOITEM-BATCH TO ..
*MOVE wa_ekpo- TO wa_bapi_ekpo-BAPIMEPOITEM-VENDRBATCH TO ..
*MOVE wa_ekpo- TO wa_bapi_ekpo-BAPIMEPOITEM-CALCTYPE TO ..
*MOVE wa_ekpo- TO wa_bapi_ekpo-BAPIMEPOITEM-NO_ROUNDING TO ..

* Preis-Übergabe 1 = Brutto-Preis, 2 = Netto-Preis, 0=im Test-BAPI.
* Konditionen werden im BAPI abgeleitet, nicht aus dem Infosatz
 MOVE '0' TO wa_bapi_ekpo-po_price.

 MOVE wa_bapi_ekpo TO itab_bapi_ekpo.
 APPEND itab_bapi_ekpo.

 CLEAR: itab_bapi_ekpo_x, sy-subrc.

 MOVE wa_ekpo-ebelp TO itab_bapi_ekpo_x-po_item.

 WHILE sy-subrc = 0.
   REPLACE ' ' WITH 'X' INTO itab_bapi_ekpo_x.
 ENDWHILE.

 APPEND itab_bapi_ekpo_x.

ENDFORM.

*---------------------------------------------------------------------*
*                         B A P I _ E K E T                           *
*---------------------------------------------------------------------*
* Liefereinteilungen. Erklärung siehe Kopfdaten                       *
*---------------------------------------------------------------------*
FORM upro-bapi_eket.

 ADD 1 TO z_eket.

 MOVE wa_eket-ebelp TO itab_bapi_eket-po_item.
 MOVE z_eket        TO itab_bapi_eket-sched_line.
 MOVE wa_eket-lpein TO itab_bapi_eket-del_datcat_ext.

* Datenfelder werden über Transaktion sowieso überschrieben
 IF pmdatlf = 'J'.
   zw_datum = sy-datum + wa_ekpo-plifz + 5.
   MOVE zw_datum(2)   TO: itab_bapi_eket-delivery_date(2).
   MOVE zw_datum+2(2) TO: itab_bapi_eket-delivery_date+3(2).
   MOVE zw_datum+4(4) TO: itab_bapi_eket-delivery_date+6(4).
   MOVE '.'           TO: itab_bapi_eket-delivery_date+2(1),
                          itab_bapi_eket-delivery_date+5(1).
   MOVE zw_datum      TO itab_bapi_eket-stat_date.

   MOVE sy-datum      TO itab_bapi_eket-po_date.

   zw_datum = sy-datum + wa_ekpo-plifz + 7.
   MOVE zw_datum      TO itab_bapi_eket-ms_date.
 ELSE.
   MOVE wa_eket-eindt TO itab_bapi_eket-delivery_date.
   MOVE wa_eket-slfdt TO itab_bapi_eket-stat_date.
   MOVE wa_eket-bedat TO itab_bapi_eket-po_date.
   MOVE wa_eket-mbdat TO itab_bapi_eket-ms_date.
 ENDIF.

 MOVE wa_eket-menge TO itab_bapi_eket-quantity.
 MOVE wa_eket-uzeit TO itab_bapi_eket-deliv_time.
 MOVE wa_eket-banfn TO itab_bapi_eket-preq_no.
 MOVE wa_eket-bnfpo TO itab_bapi_eket-preq_item.
*MOVE BAPIMEPOSCHEDULE-ROUTESCHED TO.
 MOVE wa_eket-mbuhr TO itab_bapi_eket-ms_time.
 MOVE wa_eket-lddat TO itab_bapi_eket-load_date.
 MOVE wa_eket-lduhr TO itab_bapi_eket-load_time.
 MOVE wa_eket-tddat TO itab_bapi_eket-tp_date.
 MOVE wa_eket-tduhr TO itab_bapi_eket-tp_time.
 MOVE wa_eket-wadat TO itab_bapi_eket-gi_date.
 MOVE wa_eket-wauhr TO itab_bapi_eket-gi_time.
*MOVE BAPIMEPOSCHEDULE-DELETE_IND TO.

 APPEND itab_bapi_eket.

 CLEAR: itab_bapi_eket_x, sy-subrc.

 MOVE wa_eket-ebelp TO itab_bapi_eket_x-po_item.
 MOVE z_eket        TO itab_bapi_eket_x-sched_line.

 WHILE sy-subrc = 0.
   REPLACE ' ' WITH 'X' INTO itab_bapi_eket_x.
 ENDWHILE.

 APPEND itab_bapi_eket_x.

ENDFORM.

*---------------------------------------------------------------------*
*                         B A P I _ K O N V                           *
*---------------------------------------------------------------------*
* Konditionsdaten einer Position aufbereiten und in die interne       *
* Tabelle übertragen. Weitere Infos: Erklärung siehe Kopfdaten        *
*---------------------------------------------------------------------*
* =>] wa_konv: Wa-Variablen der KONV, die zuvor zugewiesen wurden
* <=> z_konv:  interner Zähler für die Konditionen einer Position
* <=> itab_bapi_konv: interne Tabelle um das neue Element hinzugefügt
* <=> itab_bapi_konv_x
*---------------------------------------------------------------------*
FORM upro-bapi_konv.

 ADD 1 TO z_konv.

**move WA_EKKO-KNUMV TO wa_bapi_kond-CONDITION_NO.
*  MOVE wa_ekpo-ebelp TO wa_bapi_konv-itm_number.
*  MOVE z_konv        TO wa_bapi_konv-cond_st_no.
*  MOVE '01'          TO wa_bapi_konv-cond_count.

* keine Kopie der Vorgangsnummer, muß frisch vergeben werden
*MOVE WA_KONV-KNUMV TO wa_bapi_konv-CONDITION_NO.
 MOVE wa_konv-kposn TO wa_bapi_konv-itm_number.
 MOVE wa_konv-stunr TO wa_bapi_konv-cond_st_no.
*  MOVE wa_konv-zaehk TO wa_bapi_konv-cond_count.
 MOVE z_konv        TO wa_bapi_konv-cond_count.

 MOVE wa_konv-kschl TO wa_bapi_konv-cond_type.
 MOVE wa_konv-kbetr TO wa_bapi_konv-cond_value.
 MOVE wa_konv-waers TO wa_bapi_konv-currency.
*MOVE TO wa_bapi_konv-CURRENCY_ISO.
 MOVE wa_konv-kmein TO wa_bapi_konv-cond_unit.
*MOVE TO wa_bapi_konv-COND_UNIT_ISO.
 MOVE wa_konv-kpein TO wa_bapi_konv-cond_p_unt.
 MOVE wa_konv-kdatu TO wa_bapi_konv-conpricdat.
 MOVE wa_konv-krech TO wa_bapi_konv-calctypcon.
 MOVE wa_konv-kawrt TO wa_bapi_konv-conbaseval.
 MOVE wa_konv-kkurs TO wa_bapi_konv-conexchrat.
 MOVE wa_konv-kumza TO wa_bapi_konv-numconvert.
 MOVE wa_konv-kumne TO wa_bapi_konv-denominato.
 MOVE wa_konv-kntyp TO wa_bapi_konv-condtype.
 MOVE wa_konv-kstat TO wa_bapi_konv-stat_con.
 MOVE wa_konv-knprs TO wa_bapi_konv-scaletype.
 MOVE wa_konv-kreli TO wa_bapi_konv-coninvolst.
 MOVE wa_konv-kherk TO wa_bapi_konv-condorigin.
 MOVE wa_konv-kgrpe TO wa_bapi_konv-groupcond.
 MOVE wa_konv-koupd TO wa_bapi_konv-cond_updat.
 MOVE wa_konv-kopos TO wa_bapi_konv-condcount.
 MOVE wa_konv-ksteu TO wa_bapi_konv-condcntrl.
 MOVE wa_konv-kinak TO wa_bapi_konv-condisacti.
 MOVE wa_konv-koaid TO wa_bapi_konv-condclass.
 MOVE wa_konv-kfaktor TO wa_bapi_konv-factbasval.
 MOVE wa_konv-kzbzg TO wa_bapi_konv-scalebasin.
 MOVE wa_konv-kstbs TO wa_bapi_konv-scalbasval.
 MOVE wa_konv-konms TO wa_bapi_konv-unitmeasur.
*MOVE TO itab_bapi_konv-UNITMEASUR_ISO.
 MOVE wa_konv-konws TO wa_bapi_konv-currenckey.
*MOVE TO itab_bapi_konv-CURRENCKEY_ISO.
 MOVE wa_konv-kfkiv TO wa_bapi_konv-condincomp.
 MOVE wa_konv-kvarc TO wa_bapi_konv-condconfig.
 MOVE wa_konv-kmprs TO wa_bapi_konv-condchaman.
*MOVE WA_KONV-KNUMH TO wa_bapi_konv-COND_NO.
*MOVE TO wa_bapi_konv-CHANGE_ID.

 MOVE wa_bapi_konv TO itab_bapi_konv.
 APPEND itab_bapi_konv.

 CLEAR: itab_bapi_konv_x, sy-subrc.

 MOVE wa_konv-kposn TO wa_bapi_konv-itm_number.
 MOVE wa_konv-stunr TO wa_bapi_konv-cond_st_no.
*  MOVE wa_konv-zaehk TO wa_bapi_konv-cond_count.
 MOVE z_konv        TO wa_bapi_konv-cond_count.

 WHILE sy-subrc = 0.
   REPLACE ' ' WITH 'X' INTO itab_bapi_konv_x.
 ENDWHILE.

* Konditionsnummer, soll vom System vergeben werden, kein Kopie !!!
 MOVE ' ' TO itab_bapi_konv_x-itm_numberx.

 APPEND itab_bapi_konv_x.

ENDFORM.

*---------------------------------------------------------------------*
*                   B A P I _ P O _ C R E A T E 1                     *
*---------------------------------------------------------------------*
* Funktionsbaustein, welcher das BAPI "PO Create1" aufruft = anlegen  *
* einer Bestellung (Internet-Version).                                *
*                                                                     *
* In diesem Beispiel-Programm fehlt die Versorgung einiger Tabellen   *
* und Werte, diese werden auch nicht als Übergabe mitgepflegt, jedoch *
* sind sie im Kommentar zum Basis-Funktionsaufruf aufgezeigt.         *
*---------------------------------------------------------------------*
* ]=> wa_fehlerhaft: Fehler im BAPI-Baustein (Error-Meldung)          *
* ]=> wa_ekko-ebeln: neue Bestellnummer (bei Fehler = 0)              *
* ]=> sy-subrc     : Status für den Commit (Muß-Aktion)               *
*---------------------------------------------------------------------*
FORM upro-bapi_po_create1
    TABLES   itab_bapi_return
             itab_bapi_ekpo itab_bapi_ekpo_x
             itab_bapi_eket itab_bapi_eket_x
             itab_bapi_konv itab_bapi_konv_x
    USING    wa_bapi_ekko   wa_bapi_ekko_x
             p_pmtest
    CHANGING wa_fehlerhaft
             wa_ekko_ebeln.

 CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
           poheader               = wa_bapi_ekko
           poheaderx              = wa_bapi_ekko_x
*           POADDRVENDOR           =
           testrun                = pmx_test
           memory_uncomplete      = ' '
*           MEMORY_COMPLETE        =
*           NO_MESSAGING           = pmnomeld
*           NO_MESSAGE_REQ         =
*           NO_AUTHORITY           =
           no_price_from_po       = 'X'
      IMPORTING
           exppurchaseorder       = wa_ekko-ebeln
*           EXPHEADER              =
      TABLES
           return                 = itab_bapi_return
           poitem                 = itab_bapi_ekpo
           poitemx                = itab_bapi_ekpo_x
*           POADDRDELIVERY         =
           poschedule             = itab_bapi_eket
           poschedulex            = itab_bapi_eket_x
*           POACCOUNT              =
*           POACCOUNTPROFITSEGMENT =
*           POACCOUNTX             =
*           POCONDHEADER           =
*           POCONDHEADERX          =
           pocond                 = itab_bapi_konv
           pocondx                = itab_bapi_konv_x
*           POLIMITS               =
*           POCONTRACTLIMITS       =
*           POSERVICES             =
*           POSRVACCESSVALUES      =
*           POSERVICESTEXT         =
*           EXTENSIONIN            =
*           EXTENSIONOUT           =
*           POTEXTHEADER           =
*           POTEXTITEM             =
*           POPARTNER              =
           .
* prüfen, ob ein schwerer Fehler aufgetreten ist
* in der Return-Rückgabestruktur muß nur eine Meldung mit 'E'=Error sein
 MOVE 'N' TO wa_fehlerhaft.
 LOOP AT itab_bapi_return INTO wa_bapi_return.
   IF wa_bapi_return-type = 'E'.
     MOVE 'J' TO wa_fehlerhaft.
     MOVE '0000000000' TO wa_ekko-ebeln.
   ENDIF.
 ENDLOOP.

* muß sein, damit die Bestellung aktiv ist
 IF pmx_test = 'X'.
   MOVE 0 TO sy-subrc.
 ELSE.
   COMMIT WORK.
 ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*                     B A P I _ 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-bapi_ergebnis.

 CLEAR: anzahl_rot, anzahl_gelb, anzahl_gruen.

* in der Parameterleiste wurde "Meldungen anzeigen" angekreuzt
 IF pmmeld = 'X'.
* zuerst einzeiliger Gesamtstatus des Laufes.
* irgendwas verlief nicht nach Plan. Fehleranzeige (rote Ampel)
   IF wa_fehlerhaft = 'J'.
     WRITE AT: /1 icon_red_light, 7 'Fehler bei dem Aufbau'.
   ELSE.
     IF sy-subrc = 0.
* Kein Fehler, Ampel zeigt nur an, ob Test- (gelb) oder Echtlauf (grün)
       IF pmx_test = 'X'.
         WRITE AT: /1 icon_yellow_light, 7 'Testlauf'.
       ELSE.
         WRITE AT: /1 icon_green_light, 7 'Bestellung',
                   18 wa_ekko-ebeln, 29 'erfolgreich angelegt'.
       ENDIF.
     ELSE.
* Bapi durchgelaufen, aber Commit nicht erfolgreich (rote Ampel).
* Bestellung existiert nicht. Der Commit ist ein Muß am Ende !
       WRITE AT: /1 icon_red_light, 7 'Commit fehlerhaft'.
     ENDIF.
   ENDIF.
   SKIP 1.
 ENDIF.

 LOOP AT itab_bapi_return INTO wa_bapi_return.
* Datei aufbauen wird in diesem Testbeispiel nicht benutzt
* 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.

   IF pmmeld    =  'X'
   AND sy-batch <> 'X'.
* Meldungen am Bildschirm anzeigen, gemäß Stufe Ampel am Bildschirm
* bringen, jedoch Warnstufe beachten, welche gewünscht wurde beim
* Einstieg. Diese Protokolltabelle wird im BAPI erzeugt
     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.
       WHEN 'I'.
         ADD 1 TO anzahl_gruen.
         IF pmxgruen = 'X'.
           WRITE AT: /1 icon_hint AS ICON,
                      7 zw_text.
         ENDIF.
       WHEN OTHERS.
         WRITE AT: /1 wa_bapi_return-type,
                    7 zw_text.
     ENDCASE.
   ENDIF.
 ENDLOOP.

* Gesamtanzahl der Meldungen anzeigen, welche niedriger sind als die
* gewünschte Warnstufe
 IF pmmeld    =  'X'
 AND sy-batch <> 'X'.
   SKIP 1.

   IF  pmx_gelb = ' '
   AND pmxgruen = ' '
   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.
 ENDIF.

ENDFORM.

*****  E n d e  *****
* Copyright BJH Software, Datei überarbeitet am: 23.7.2005