几个有用的BAPI调用样例

 ***INCLUDE MMWE0F01 .
* 88951 26.11.97 4.0B KB: Preis黚ergabe an ME_CREATE_PO_ITEM
* 94702 04.02.98 4.0B KB: Verbuchungsproblem Bestellung/Kundenauftrag
*102133 24.04.98 4.0C KB: Preis黚ernahme in Bestellung
*106225 09.06.98 4.5A KB: Bestellpreismengeneinheit in Bestellposition
*134329 15.01.99 4.5B RB: WE/RE-Kennzeichen
*167369 12.08.99 4.6B RB: Positionsreihenfolge in erzeugten Objekten
*&---------------------------------------------------------------------*
*&      Hinzuf黦en neue Position aus dem Katalog in BAN
*&---------------------------------------------------------------------*
form ban_store_cat.

  clear ban.
  ban-preq_item = h_banpos + 1.
  clear bankey.
  bankey-preq_item = ban-preq_item.

* lesen BAN - merken Indizes
  read table ban with key bankey binary search.
  h_index = sy-tabix.
  h_subrc = sy-subrc.

* 黚ernehmen globale Daten in BAN
  move-corresponding global to ban.
  if ban-preq_name is initial.
    ban-preq_name = sy-uname.
  endif.

* 黚ernehmen Katalog-Daten in BAN
  ban-material     = new_item-matnr.
  ban-pur_mat      = new_item-matnr.
  ban-quantity     = new_item-quantity.

  if new_item-unit is initial.
    message s064 with new_item-unit.
    exit.
  endif.
  perform unit_of_measure_to_sap using new_item-unit.
  if exitflag ne space.
    message s064 with new_item-unit.
    exit.
  endif.

  ban-unit         = new_item-unit.
  ban-short_text   = new_item-description.

  if not new_item-currency is initial and
     not new_item-price is initial.
    perform value_to_sap using new_item-currency new_item-price.
    if exitflag ne space.
      message s065 with new_item-price new_item-currency.
      exit.
    endif.
  endif.

  ban-preis        = new_item-price.
  ban-c_amt_bapi   = new_item-price.
  ban-price_unit   = new_item-priceunit.
  if not ban-preis is initial.
*  BAN-PO_PRICE = '2'.                                "102133/KB
    ban-po_price = '1'.                "102133/KB
  endif.

  if not new_item-currency is initial.
    perform currency_to_sap using new_item-currency.
    if exitflag ne space.
      message s066 with new_item-currency.
      exit.
    endif.
  endif.

  ban-currency     = new_item-currency.
  ban-waers        = ban-currency.
  ban-deliv_date   = sy-datlo + new_item-leadtime.
  ban-vend_mat     = new_item-vendormat.
  ban-manu_mat     = new_item-manufactmat.
  ban-mfr_no_ext   = new_item-manufactcode.

  if h_catalogs-lifnr ne space.
    ban-fixed_vend = h_catalogs-lifnr.
    ban-purch_org  = h_catalogs-ekorg.
  else.
    ban-fixed_vend = new_item-vendor.
    if not h_catalogs-ekorg is initial and
       ban-purch_org is initial.
      ban-purch_org = h_catalogs-ekorg.
    endif.
  endif.

* Materialnummer von Katalog 黚ergeben - Pr黤en Mat. und 黚ern. Daten
  if ban-pur_mat  ne space.
    perform material_get using ban-pur_mat.
    if no_material ne space or
       no_status_b ne space.
      message s050 with ban-pur_mat.
      clear ban-pur_mat.
      clear ban-material.
    else.
      move-corresponding mat_tab to ban.
      ban-preis = mat_tab-c_amt_bapi.
      perform material_availability_check.
    endif.
  endif.

* Materialnummer 黚er Infosatz suchen, wenn Lieferantenmatnr. sitzt
  if ban-pur_mat eq space.
    if ban-vend_mat ne space.
      perform determine_material_inforecord using new_item-vendormat
                                                  ban-fixed_vend
                                                  ban-pur_mat
                                                  ban-info_rec.
* falls Materialnummer gefunden wurde, so weiter, als sei sie eingegeben
      if ban-pur_mat ne space.
        perform material_get using ban-pur_mat.
        if no_material ne space or
           no_status_b ne space.
          clear ban-pur_mat.
          clear ban-material.
        else.
          move-corresponding mat_tab to ban.
          ban-preis = mat_tab-c_amt_bapi.
          perform material_availability_check.
        endif.
      endif.
    endif.

* Materialnummer 黚er Hersteller und Herstellerteilenummer
    if new_item-manufactmat ne space and
       new_item-manufactcode ne space.
      perform determine_material_manufact using new_item-manufactmat
                                                new_item-manufactcode
                                                ban-pur_mat.

* falls Materialnummer gefunden wurde, so weiter, als sei sie eingegeben
      if ban-pur_mat ne space.
        perform material_get using ban-pur_mat.
        if no_material ne space or
           no_status_b ne space.
          clear ban-pur_mat.
          clear ban-material.
        else.
          move-corresponding mat_tab to ban.
          ban-preis = mat_tab-c_amt_bapi.
          perform material_availability_check.
        endif.
      endif.
    endif.
  endif.

* lesen lieferantenstamm und ermitteln EKORG
  if ban-fixed_vend ne space and
     ban-purch_org  eq space.
  endif.

* Festwerte
  if ban-price_unit is initial.
    ban-price_unit = 1.
  endif.
  ban-del_datcat = '1'.
  ban-item_cat   = '0'.
  ban-update = 'I'.

  perform check_mandantory_fields.

* WE/RE-Kennzeichen setzen                                    "134329/RB
  select single * from t163  where pstyp = ban-item_cat.      "134329/RB
  select single * from t163k where knttp = ban-acctasscat.    "134329/RB
                                       "134329/RB
  ban-gr_ind = t163-wepos.             "134329/RB
  ban-gr_non_val = t163-weunb.         "134329/RB
  ban-ir_ind = t163-repos.             "134329/RB
                                       "134329/RB
  if ban-acctasscat ne space.          "134329/RB
    ban-consumpt = t163k-kzvbr.        "134329/RB
    if t163-wepov eq space.            "134329/RB
      ban-gr_ind = t163k-wepos.        "134329/RB
    endif.                             "134329/RB
    if t163-weunv eq space.            "134329/RB
      ban-gr_non_val = t163k-weunb.    "134329/RB
    endif.                             "134329/RB
    if t163-repov eq space.            "134329/RB
      ban-ir_ind = t163k-repos.        "134329/RB
    endif.                             "134329/RB
  endif.                               "134329/RB

* merken redirectURL f黵 SD-scenario
  ban-katalog = h_catalogs-katalog.
  ban-sd      = sel_sd.
  if sel_sd ne space.
    read table redirect with key ban-katalog.
    if sy-subrc ne 0.
      redirect-katalog = ban-katalog.
      field-get 'SD_HOOK_URL' 1 h_redirect h_redirect_length.
      move h_redirect to redirect-url.
      append redirect.
    endif.
  endif.

  if h_subrc eq 0.
    modify ban index h_index.
  else.
    insert ban index h_index.
  endif.
  h_banpos = ban-preq_item.

* erzeugen Kontierungszeile
  perform init_bsc.

* erzeugen Textzeilen
  perform init_bantx.
  clear ban.

endform.

*&---------------------------------------------------------------------*
*&      膎dern Position 黚er das Detailbild - Grunddaten
*&---------------------------------------------------------------------*
form ban_store_core.

  clear bankey.
  bankey-preq_item = bapieban-preq_item.
  read table ban with key bankey binary search.
  h_index = sy-tabix.
  h_subrc = sy-subrc.

* unerhebliche Felder - einfach 黚ernehmen
  ban-doc_type     = bapieban-doc_type.
  ban-pur_group    = bapieban-pur_group.
  ban-short_text   = bapieban-short_text.
  ban-store_loc    = bapieban-store_loc.
  ban-preq_name    = bapieban-preq_name.
  ban-trackingno   = bapieban-trackingno.
  ban-preis        = eban-preis.
  ban-price_unit   = bapieban-price_unit.
  ban-currency     = bapieban-currency.
  ban-vend_mat     = bapieban-vend_mat.

* L鰏chen Bezugsquellendaten bei bestimmten 膎derungen
  if ban-plant ne bapieban-plant or
     ban-mat_grp ne bapieban-mat_grp or
     ban-unit ne bapieban-unit or
     ban-item_cat ne bapieban-item_cat.
    clear next.
    loop at sos where preq_item eq ban-preq_item.
      delete sos.
      next = next + 1.
    endloop.
    if next > 0.
      clear next.
      message s132.
      clear: ban-fixed_vend,
             ban-purch_org,
             ban-agreement,
             ban-agmt_item,
             ban-info_rec.
    endif.
  endif.

* 黚ernehmen Felder, wenn Nichtlagerposition
  if ban-pur_mat  eq space.
    ban-mat_grp      = bapieban-mat_grp.
    ban-plant        = bapieban-plant.
    ban-unit         = bapieban-unit.
    ban-c_amt_bapi   = bapieban-c_amt_bapi.
    ban-price_unit   = bapieban-price_unit.
    ban-currency     = bapieban-currency.
    if not ban-preis is initial.
*     BAN-PO_PRICE = '2'.                                 "102133/KB
      ban-po_price = '1'.              "102133/KB
    endif.
  else.
*  IF NOT BAN-PREIS IS INITIAL.                           "102133/KB
*     BAN-PO_PRICE = '1'.                                 "102133/KB
*  ENDIF.                                                 "102133/KB
  endif.

* Anstossen Verf黦barkeit bei 膎derung Menge oder Termin
  if ban-material ne space.
    if ban-quantity ne bapieban-quantity or
       ban-deliv_date ne bapieban-deliv_date.
      ban-quantity     = bapieban-quantity.
      ban-deliv_date   = bapieban-deliv_date.
      perform material_availability_check.
      message s047.
    endif.
  endif.

  ban-quantity     = bapieban-quantity.
  ban-deliv_date   = bapieban-deliv_date.

* Festwerte
  if ban-price_unit is initial.
    ban-price_unit = 1.
  endif.
  ban-del_datcat = '1'.
  ban-item_cat   = '0'.
  ban-update = 'I'.
  perform check_mandantory_fields.

  modify ban index h_index.

endform.

*&---------------------------------------------------------------------*
*&      Sichern neue oder ge鋘derte Daten in interner Tabelle BAN
*&---------------------------------------------------------------------*
form ban_store_loop.

  clear bankey.
  bankey-preq_item = banwa-preq_item.
  read table ban with key bankey binary search.
  h_index = sy-tabix.

  if sy-subrc eq 0.
* Position ver鋘dert
    if ban-update ne space.
* Daten der Verf黦barkeit haben sich unter Umst鋘den ge鋘dert
      if ban-quantity ne banwa-quantity or
         ban-deliv_date ne banwa-deliv_date.
        ban-quantity   = banwa-quantity.
        ban-deliv_date = banwa-deliv_date.
        if ban-material ne space.
          perform material_availability_check.
          message s047.
        endif.
      endif.
* L鰏chen Bezugsquellendaten bei bestimmten 膎derungen
      if ban-unit ne banwa-unit.
        clear next.
        loop at sos where preq_item eq ban-preq_item.
          delete sos.
          next = next + 1.
        endloop.
        if next > 0.
          clear next.
          message s132.
          clear: ban-fixed_vend,
                 ban-purch_org,
                 ban-agreement,
                 ban-agmt_item,
                 ban-info_rec.
        endif.
      endif.

      ban-unit  = banwa-unit.
      ban-short_text = banwa-short_text.
      perform check_mandantory_fields.
      modify ban index h_index.

* Position ver鋘dert, aber Dummyposition
    else.
      move-corresponding global to ban.
      move-corresponding banwa  to ban.
      if ban-preq_name is initial.
        ban-preq_name = sy-uname.
      endif.
      if ban-pur_mat ne space.
        perform material_get using ban-pur_mat.
        if no_material ne space or
           no_status_b ne space.
          message s050 with ban-pur_mat.
          prepare_item = 'X'.
          delete ban index h_index.
          exit.
        else.
          move-corresponding mat_tab to ban.
          ban-preis = mat_tab-c_amt_bapi.
*           IF NOT BAN-PREIS IS INITIAL.                    "102133/KB
*              BAN-PO_PRICE = '1'.                          "102133/KB
*           ENDIF.                                          "102133/KB
          perform material_availability_check.
        endif.
      else.                            "102133/KB
        if not ban-preis is initial.   "102133/KB
          ban-po_price = '1'.          "102133/KB
        endif.                         "102133/KB
      endif.
      if ban-price_unit is initial.
        ban-price_unit = 1.
      endif.
      ban-del_datcat = '1'.
      ban-item_cat   = '0'.
      ban-update = 'I'.
      h_banpos = ban-preq_item.
      perform check_mandantory_fields.

* WE/RE-Kennzeichen setzen                                    "134329/RB
      select single * from t163  where pstyp = ban-item_cat.  "134329/RB
      select single * from t163k where knttp = ban-acctasscat."134329/RB
                                       "134329/RB
      ban-gr_ind = t163-wepos.         "134329/RB
      ban-gr_non_val = t163-weunb.     "134329/RB
      ban-ir_ind = t163-repos.         "134329/RB
                                       "134329/RB
      if ban-acctasscat ne space.      "134329/RB
        ban-consumpt = t163k-kzvbr.    "134329/RB
        if t163-wepov eq space.        "134329/RB
          ban-gr_ind = t163k-wepos.    "134329/RB
        endif.                         "134329/RB
        if t163-weunv eq space.        "134329/RB
          ban-gr_non_val = t163k-weunb."134329/RB
        endif.                         "134329/RB
        if t163-repov eq space.        "134329/RB
          ban-ir_ind = t163k-repos.    "134329/RB
        endif.                         "134329/RB
      endif.                           "134329/RB

      modify ban index h_index.

* erzeugen Kontierungszeile
      perform init_bsc.
* erzeugen Textzeilen
      perform init_bantx.
    endif.

* neue Position
  else.
    clear ban.
    move-corresponding global to ban.
    move-corresponding banwa  to ban.
    if ban-preq_name is initial.
      ban-preq_name = sy-uname.
    endif.
    if ban-pur_mat ne space.
      perform material_get using ban-pur_mat.
      if no_material ne space or
         no_status_b ne space.
        message s050 with ban-pur_mat.
        prepare_item = 'X'.
        delete ban index h_index.
        exit.
      else.
        move-corresponding mat_tab to ban.
        ban-preis = mat_tab-c_amt_bapi.
*        IF NOT BAN-PREIS IS INITIAL.                       "102133/KB
*           BAN-PO_PRICE = '1'.                             "102133/KB
*        ENDIF.                                             "102133/KB
        perform material_availability_check.
      endif.
    else.                              "102133/KB
      if not ban-preis is initial.     "102133/KB
        ban-po_price = '1'.            "102133/KB
      endif.                           "102133/KB
    endif.
    if ban-price_unit is initial.
      ban-price_unit = 1.
    endif.
    ban-update = 'I'.
    perform check_mandantory_fields.
    ban-item_cat = '0'.
    ban-del_datcat = '1'.
    h_banpos = ban-preq_item.

* WE/RE-Kennzeichen setzen                                    "134329/RB
    select single * from t163  where pstyp = ban-item_cat.    "134329/RB
    select single * from t163k where knttp = ban-acctasscat.  "134329/RB
                                       "134329/RB
    ban-gr_ind = t163-wepos.           "134329/RB
    ban-gr_non_val = t163-weunb.       "134329/RB
    ban-ir_ind = t163-repos.           "134329/RB
                                       "134329/RB
    if ban-acctasscat ne space.        "134329/RB
      ban-consumpt = t163k-kzvbr.      "134329/RB
      if t163-wepov eq space.          "134329/RB
        ban-gr_ind = t163k-wepos.      "134329/RB
      endif.                           "134329/RB
      if t163-weunv eq space.          "134329/RB
        ban-gr_non_val = t163k-weunb.  "134329/RB
      endif.                           "134329/RB
      if t163-repov eq space.          "134329/RB
        ban-ir_ind = t163k-repos.      "134329/RB
      endif.                           "134329/RB
    endif.                             "134329/RB

    insert ban index h_index.

* erzeugen Kontierungszeile
    perform init_bsc.
* erzeugen Textzeilen
    perform init_bantx.
  endif.
  clear ban.

endform.

*&---------------------------------------------------------------------*
*&      膎dern Position - Kontierungen 黚er das Detailbild
*&---------------------------------------------------------------------*
form bsc_store_account.

  clear bankey.
  bankey-preq_item = bapieban-preq_item.
  read table ban with key bankey binary search.

* bsc lesen und Daten fortschreiben
  clear bsckey.
  bsckey-preq_item = bapieban-preq_item.
  bsckey-serial_no = '01'.
  read table bsc with key bsckey binary search.
  h_index1 = sy-tabix.
  if sy-subrc eq 0.
    move-corresponding bapiebkn to bapipogna.
    perform check_account_assignment.
    check exitflag eq space.
    move-corresponding bapipogna to bapiebkn.
    move-corresponding bapiebkn to bsc.
    move-corresponding bsckey to bsc.
    modify bsc index h_index1.
  endif.

endform.

*&---------------------------------------------------------------------*
*&      Form  CHECK_MANDANTORY_FIELDS
*&---------------------------------------------------------------------*
form check_mandantory_fields.

  if ban-quantity is initial.
    message e094.
  endif.

  if ban-deliv_date is initial.
    message e095.
  endif.

  if ban-unit is initial.
    message e096.
  endif.

endform.                               " CHECK_MANDANTORY_FIELDS

*&---------------------------------------------------------------------*
*&      Aufruf fremder Katalog
*&---------------------------------------------------------------------*
form call_catalog.

  loop at catalogs where katalog eq select_cat.
    exit.
  endloop.
  h_catalogs = catalogs.

* merken Katalog-Id und Lieferant in Hilfsfeld
  sel_sd = catalogs-sd_catalog.
  sel_vendor = catalogs-lifnr.

* im Falle SD, Kundennummer besorgen
  if sel_sd ne space.
    perform get_company_code.
    perform get_customer_number.
    field-set 'CUSTOMER_NO' 1 customer_no.
  endif.

* Aufruf Katalog
* wenn vorher bereits aufgerufen - URL aus interner Tabelle
  read table redirect with key catalogs-katalog.
  if sy-subrc eq 0.
    clear my_hook_url.
    its-wgateurl my_hook_url.
    field-set 'MM_HOOK_URL' 1 my_hook_url.
    field-set '~OkCode' 1 'SHPS'.
    its-browser_redirect redirect-url.
  else.
* wenn noch nicht aufgerufen - URL 黚er Customizingtabelle aufbauen
    perform catalog_browser_redirect using catalogs-katalog.
  endif.

endform.

*&---------------------------------------------------------------------*
*&      Form  CATALOG_BROWSER_REDIRECT
*&---------------------------------------------------------------------*
*       Aufruf externe Kataloge 黚er Customizingtabelle
*----------------------------------------------------------------------*
form catalog_browser_redirect using cbr_katalog.

  data: url like savwctxt-fieldcont,
        hook like savwctxt-fieldcont,
        name like savwctxt-fieldname,
        cont like savwctxt-fieldcont,
        hook_name like savwctxt-fieldname,
        hook_index like sy-tabix,
        sep.

  refresh: xmw03.
  clear: xmw03.
* Katalog-Parameter besorgen
  select * from tmw03
           into table xmw03
           where katalog = cbr_katalog.
  sort xmw03.

* 1. Runde: URL des Katalogs merken
  loop at xmw03.
    hook_index = sy-tabix.
* Parameter merken bei Parameter-Wechsel
    if xmw03-fieldnam ne space.
      if name ne space or cont ne space.
        field-set name 0 cont.
        clear: name, cont.
      endif.
* Parameter-Name
      name = xmw03-fieldnam.
    endif.
* Parameter-Wert analysieren
    case xmw03-valuetyp.
* URL
      when '0'.
        concatenate url xmw03-fieldval into url.
* Festwert
      when '2'.
        concatenate cont xmw03-fieldval into cont.
* ABAP-Feld
      when '1'.
        write (xmw03-fieldval) to cont.
* Hook-Url
      when '4'.
* Ende 1.Runde
        exit.
    endcase.
  endloop.

* Fester Teil der R點kgabe-URL vom ITS
  its-wgateurl hook.

* 2. Runde: R點kgabe-URL merken
  loop at xmw03 from hook_index.
* Erster Parameter: Trennzeichen '?'
    if not hook cs '?'.
      sep = '?'.
* Folgeparameter: Trennzeichen '&'
    else.
      sep = '&'.
    endif.
* Parameter-Wert analysieren
    case xmw03-valuetyp.
* Festwert
      when '2'.
       concatenate hook sep xmw03-fieldnam '=' xmw03-fieldval into hook.
* ABAP-Feld
      when '1'.
        write (xmw03-fieldval) to cont.
        concatenate hook sep xmw03-fieldnam '=' cont into hook.
* Hook-Url
      when '4'.
        hook_name = xmw03-fieldnam.
    endcase.
  endloop.

* Komplette R點kgabe-URL als Parameter merken
  field-set hook_name 0 hook.
* URL zusammenbauen, encoden und an ITS 黚ergeben
  its-browser_redirect url.

endform.

*&---------------------------------------------------------------------*
*&      Pr黤en Kontierungsdaten
*&---------------------------------------------------------------------*
form check_account_assignment.

  perform fill_bapicobl.
  refresh return1.
  clear   return1.
  clear   exitflag.

* Aufruf Kontierungspr黤ung und -erg鋘zung
  call function 'BAPI_ACCSERV_CHECKACCASSIGNMT'
       exporting
            check_codingblock   = bapicobl
       importing
            changed_codingblock = bapicobl
       tables
            return              = return1
       exceptions
            error_message       = 1.

* keine Fehler
  if return1[] is initial and
     sy-subrc eq 0.
    perform fill_bapipogna.
  else.
* Fehler ausgeben
    loop at return1 where type eq 'E'.
*     MESSAGE ID RETURN1-ID TYPE RETURN1-TYPE NUMBER RETURN1-NUMBER
      message id return1-id type 'S' number return1-number
              with return1-message_v1 return1-message_v2
                   return1-message_v3 return1-message_v4.
      exitflag = 'X'.
      exit.
    endloop.

    loop at return1 where type ne 'E'.
      message id return1-id type 'S' number return1-number
              with return1-message_v1 return1-message_v2
                   return1-message_v3 return1-message_v4.
    endloop.
  endif.

endform.

*&---------------------------------------------------------------------*
*&      Pr黤en Globale Daten auf Vollst鋘digkeit
*&---------------------------------------------------------------------*
form check_global_data.

  clear global_data_missing.
  if bapipogn-doc_type is initial.
    global_data_missing = 'X'.
  endif.
  if bapipogn-pur_group is initial.
    global_data_missing = 'X'.
  endif.
  if bapipogn-mat_grp is initial.
    global_data_missing = 'X'.
  endif.
  if bapipogn-plant is initial.
    global_data_missing = 'X'.
  endif.
  if bapipogn-acctasscat is initial.
    global_data_missing = 'X'.
  endif.
  if bapipogna-cost_ctr is initial.
    global_data_missing = 'X'.
  endif.

endform.

*&---------------------------------------------------------------------
*       Erzeugen Bestellung
*----------------------------------------------------------------------
form create_po.

 data: transaction_id like arfctid,    "94702/KB
       commit_work(15) value 'COMMIT_WORK',                    "94702/KB
       status_of_transaction(15).      "94702/KB

  clear return.
  refresh return.
 clear transaction_id.                 "94702/KB

* Verbuchung 'normal' wenn SD nicht im Spiel                  "94702/KB
 if sd_katalog is initial.             "94702/KB
* Aufruf BAPI zum Erzeugen der Bestellung
    call function 'BAPI_PO_CREATE'
         exporting
              po_header                  = po_head
         importing
              purchaseorder              = h_ebeln
         tables
              po_items                   = po_item
              po_item_schedules          = po_sched
              po_item_account_assignment = po_acct
              po_item_text               = po_text
              return                     = return
         exceptions
              others                     = 0.

* Verbuchung mit commit and wait, wenn SD im Spiel            "94702/KB
 else.                                 "94702/KB
    call function 'TRANSACTION_BEGIN'  "94702/KB
         importing                     "94702/KB
              transaction_id = transaction_id                  "94702/KB
         exceptions                    "94702/KB
              others         = 1.      "94702/KB
    call function 'BAPI_PO_CREATE'     "94702/KB
         exporting                     "94702/KB
              po_header                  = po_head             "94702/KB
         importing                     "94702/KB
              purchaseorder              = h_ebeln             "94702/KB
         tables                        "94702/KB
              po_items                   = po_item             "94702/KB
              po_item_schedules          = po_sched            "94702/KB
              po_item_account_assignment = po_acct             "94702/KB
              po_item_text               = po_text             "94702/KB
              return                     = return              "94702/KB
         exceptions                    "94702/KB
              others                     = 0.                  "94702/KB
    call function 'TRANSACTION_STATUS' "94702/KB
         importing                     "94702/KB
              status  = status_of_transaction                  "94702/KB
         exceptions                    "94702/KB
              others  = 1.             "94702/KB
    if status_of_transaction = commit_work.                    "94702/KB
      commit work and wait.            "94702/KB
    endif.                             "94702/KB
    call function 'TRANSACTION_END'    "94702/KB
         exporting                     "94702/KB
              transaction_id = transaction_id                  "94702/KB
         exceptions                    "94702/KB
              others         = 1.      "94702/KB
 endif.                                "94702/KB

* Auswertung der aufgetretenen Fehler und Fortschreiben Protokoll
  loop at return.
    error_po = 'X'.
    move-corresponding return to prot_po.
    prot_po-vendor = po_head-vendor.
    append prot_po.
  endloop.

* Merken SD-Katalog in PO-Tabelle um den erneuten Aufruf zu erm鰃lichen
  clear object_po.
  if h_ebeln ne space.
    po_exist = 'X'.
    object_po-number = h_ebeln.
    if not sd_katalog is initial.
      object_po-katalog = sd_katalog.
    endif.
    append object_po.
  endif.

  clear: po_head, po_item, po_acct, po_text, return.
  refresh: po_item, po_acct, po_text, return.

endform.

*&---------------------------------------------------------------------*
*&      Form  CREATE_REQUISITION
*&---------------------------------------------------------------------*
*       Anlegen Bestellanforderung 黚er BAPI_REQUISITION_CREATE
*----------------------------------------------------------------------*
form create_requisition.

  clear error_rq.
  clear rq_exist.
  clear return.
  refresh return.

* Aufruf BAPI zum Erzeugen der Bestellanforderung
  call function 'BAPI_REQUISITION_CREATE'
       exporting
            skip_items_with_error          = 'X'
       importing
            number                         = h_banfn
       tables
            requisition_items              = req_item
            requisition_account_assignment = req_acct
            requisition_item_text          = req_text
            return                         = return
       exceptions
            others                         = 0.

* Auswertung der aufgetretenen Fehler und Fortschreiben Protokoll
  loop at return.
    error_rq = 'X'.
    move-corresponding return to prot_rq.
    append prot_rq.
  endloop.

* Banfnummer merken
  if h_banfn ne space.
    rq_exist = 'X'.
    object_rq-number = h_banfn.
    append object_rq.
  endif.

  clear: req_item, req_acct, req_text, return.
  refresh: req_item, req_acct, req_text, return.

endform.

*&---------------------------------------------------------------------*
*&      Form  CREATE_RESERVATION
*&---------------------------------------------------------------------*
*       Anlegen Reservierung 黚er BAPI_RESERVATION_CREATE
*----------------------------------------------------------------------*
form create_reservation.

  clear return.
  refresh return.

* Aufruf BAPI zum Erzeugen der Reservierungen
  call function 'BAPI_RESERVATION_CREATE'
       exporting
            reservation_header = res_head
       importing
            reservation        = h_rsnum
       tables
            reservation_items  = res_item
            return             = return
       exceptions
            others             = 0.

* Auswertung der aufgetretenen Fehler und Fortschreiben Protokoll
  loop at return.
    error_rs = 'X'.
    move-corresponding return to prot_rs.
    prot_rs-material = res_item-material.
    append prot_rs.
  endloop.

* Reservierungsnummer merken
  if h_rsnum ne space.
    rs_exist = 'X'.
    object_rs-number = h_rsnum.
    append object_rs.
  endif.

  clear: res_item, res_head, return.
  refresh: res_item, return.

endform.

*&---------------------------------------------------------------------
*       Erzeugen Kundenauftrag
*----------------------------------------------------------------------
form create_sd_order.

  sort object_po by katalog number.
  loop at object_po where katalog ne space.
* f黮len 躡ergabefelder / - tabelle f黵 SD
    sd_index = sy-tabix.
    field-set 'PO_NUMBER' 1 object_po-number.
    next = 0.
    loop at ban where katalog eq object_po-katalog.
      add 1 to next.
      edi_quan = ban-quantity.
      condense edi_quan.
      edi_date = ban-deliv_date.
      perform unit_of_measure_to_iso using ban-unit.
      field-set 'ORDER_ITEM-QUANTITY'   next edi_quan.
      field-set 'ORDER_ITEM-MATERIAL'   next ban-vend_mat.
      field-set 'ORDER_ITEM-UNIT_ISO'   next ban-unit.
      field-set 'ORDER_ITEM-DELIV_DATE' next edi_date.
    endloop.
* zur點ksetzen Katalog in OBJECT_PO -> diese PO ist bereits weg
    sd_katalog = object_po-katalog.
    clear object_po-katalog.
    modify object_po index sd_index.
    perform sd_browser_redirect_post.
  endloop.

* keine weiteren POs mehr ans SD zu 黚ergeben
  if sy-subrc ne 0.
    no_more_po = 'X'.
  endif.

endform.

*&---------------------------------------------------------------------*
*&      Konvertieren ISO-Currency in internes SAP-Format
*&---------------------------------------------------------------------*
form currency_to_sap using cts_currency.

  data: h_waers like ekko-waers.
  data: h_currency(3).
  h_currency = cts_currency.
  clear exitflag.

  call function 'CURRENCY_CODE_ISO_TO_SAP'
       exporting
            iso_code  = h_currency
       importing
            sap_code  = h_waers
       exceptions
            not_found = 1
            others    = 2.

* Konvertierung erfolgreich - Feld umsetzen
  if sy-subrc eq 0.
    cts_currency = h_waers.
  else.
    exitflag = 'X'.
  endif.

endform.

*&---------------------------------------------------------------------*
*&      Form  DETERMINE_MATERIAL_INFORECORD
*&---------------------------------------------------------------------*

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值