BAPI_SALESORDER_CREATEFROMDAT2 BAPI建立VA01 銷售訂單

SAP騎士發表於2011-06-15
用bapi建立銷售訂單 VA01 用的bapi如下
關於定價,可能要多做除錯,只能傳入COND_VALUE定價比率,而定價值是不可以直接修改的,


DATA: header_in            TYPE bapisdhd1,
        header_inx           TYPE bapisdhd1x,
        l_vbeln              LIKE vbak-vbeln,
        l_message            TYPE string,
        lt_return            TYPE TABLE OF bapiret2   WITH HEADER LINE,
        items_in             TYPE TABLE OF bapisditm  WITH HEADER LINE,
        items_inx            TYPE TABLE OF bapisditmx WITH HEADER LINE,
        partners             TYPE TABLE OF bapiparnr  WITH HEADER LINE,
        schedules_in         TYPE TABLE OF bapischdl  WITH HEADER LINE,
        order_conditions_in  TYPE bapicond   OCCURS WITH HEADER LINE,
        order_conditions_inx TYPE bapicondx  OCCURS WITH HEADER LINE,
        logic_switch         TYPE bapisdls   OCCURS WITH HEADER LINE,
        extensionin           TYPE  bapiparex  OCCURS WITH HEADER LINE.

  CLEAR: header_in,
         header_inx,
         order_conditions_in,
         order_conditions_inx,
         l_vbeln,
         items_in[],items_in,
         items_inx[],items_inx,
         partners[],partners,
         schedules_in[],schedules_in,
         g_exit.

* header
  header_in-doc_type    = lt_reslut-auart.
  header_in-sales_org   = lt_reslut-vkorg .
  header_in-distr_chan  = lt_reslut-vtweg.
  header_in-division    = lt_reslut-spart.
  header_in-sales_grp   = lt_reslut-vkgrp.
  header_in-sales_off   = lt_reslut-vkbur.
  header_in-sd_doc_cat  = 'C'.
  header_in-doc_date    = sy-datum.
  header_in-purch_date  = lt_reslut-audat.
  header_in-price_date  = sy-datum.
  header_in-dlvschduse  = l_abrvw.         "審批狀態
  header_in-ship_type   = lt_reslut-vsart.  "裝運型別
  header_in-s_proc_ind  = lt_reslut-sdabw.  "特殊標識
  header_in-pymt_meth   = lt_reslut-zlsch.  "付款方式

* item
  LOOP AT it_tab100.

    items_in-itm_number = it_tab100-posnr.
    items_in-material   = it_tab100-matnr.
    items_in-plant      = it_tab100-werks.
    items_in-store_loc  = it_tab100-lgort.
    APPEND items_in.
    CLEAR items_in.

    items_inx-itm_number  = it_tab100-posnr.
    items_inx-material    = 'X'.
    items_inx-plant       = 'X'.
    items_inx-store_loc   = 'X'.
    APPEND items_inx.
    CLEAR items_inx.

    schedules_in-itm_number   = it_tab100-posnr.
    schedules_in-req_qty      = it_tab100-kwmeng.
    APPEND schedules_in.
    CLEAR schedules_in.

    order_conditions_in-itm_number = it_tab100-posnr.  "itm_number
    order_conditions_in-cond_type  = 'Z11'.            "定價條件
    order_conditions_in-cond_value = it_tab100-kbetr.
    order_conditions_in-currency   = it_tab100-waerk.    "
    order_conditions_in-cond_unit  = it_tab100-vrkme.  "條件單位

    APPEND order_conditions_in.

    CLEAR order_conditions_inx.
    order_conditions_inx-itm_number = it_tab100-posnr.
    order_conditions_inx-cond_type  = 'Z11'.
    order_conditions_inx-cond_value = 'X'.
    order_conditions_inx-currency   = 'X'.
    order_conditions_inx-cond_unit  = 'X'.
    order_conditions_inx-cond_p_unt = 'X'.
    APPEND order_conditions_inx.

  ENDLOOP.

* partener
  partners-partn_role = 'WE'.
  partners-partn_numb = lt_reslut-kunnr.
  APPEND partners.
  CLEAR partners.

  partners-partn_role = 'RE'.
  partners-partn_numb = lt_reslut-kunnr.
  APPEND partners.
  CLEAR partners.

  logic_switch-pricing = ''.
  APPEND logic_switch.

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
*      SALESDOCUMENTIN           =
      order_header_in           = header_in
      order_header_inx          = header_inx
*      SENDER                    =
*      BINARY_RELATIONSHIPTYPE   =
*      INT_NUMBER_ASSIGNMENT     =
*      BEHAVE_WHEN_ERROR         =
      logic_switch              = logic_switch
    IMPORTING
      salesdocument             = l_vbeln
    TABLES
      return                    = lt_return
      order_items_in            = items_in
      order_items_inx           = items_inx
      order_partners            = partners
      order_schedules_in        = schedules_in
      order_conditions_in       = order_conditions_in
      order_conditions_inx      = order_conditions_inx
      extensionin               = extensionin.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17204926/viewspace-698007/,如需轉載,請註明出處,否則將追究法律責任。

相關文章