SAP 销售订单创建BAPI 正常订单/借贷项订单/退货订单

正常订单:BAPI_SALESORDER_CREATEFROMDAT2 业务对象:BUS2032

BAPI_SALESORDER_CREATEFROMDAT2代码样例:

待补充

退货订单:BAPI_CUSTOMERRETURN_CREATE 业务对象:BUS2102

BAPI_CUSTOMERRETURN_CREATE代码样例:

待补充

借/贷订单:SD_SALESDOCUMENT_CREATE 业务对象:BUS2096 /BUS2094

SD_SALESDOCUMENT_CREATE创建代码样例:

FUNCTION zjkjst005.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(HEAD) TYPE  ZSJST005_H OPTIONAL
*"  EXPORTING
*"     VALUE(SALESDOCUMENT_OUT) TYPE  BAPIVBELN-VBELN
*"  TABLES
*"      ITEM STRUCTURE  ZSJST005_I OPTIONAL
*"      ITEM_CURR STRUCTURE  ZSJST005_C OPTIONAL
*"      E_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
  DATA: ls_sales_header_in      TYPE bapisdhd1,
        ls_sales_header_inx     TYPE bapisdhd1x,
        return                  TYPE TABLE OF bapiret2,
        ls_return               TYPE bapiret2,
        sales_items_in          TYPE TABLE OF bapisditm,
        ls_sales_items_in       TYPE bapisditm,
        sales_items_inx         TYPE TABLE OF bapisditmx,
        ls_sales_items_inx      TYPE bapisditmx,
        sales_partners          TYPE TABLE OF bapiparnr,
        ls_sales_partners       TYPE bapiparnr,
        sales_conditions_in     TYPE TABLE OF bapicond,
        ls_sales_conditions_in  TYPE bapicond,
        sales_conditions_inx    TYPE TABLE OF bapicondx,
        ls_sales_conditions_inx TYPE bapicondx,
        salesdocument_ex        TYPE bapivbeln-vbeln,
        sales_header_out        TYPE bapisdhd,
        ls_item                 TYPE zsjst005_i,
        ls_item_curr            TYPE zsjst005_c,
        ls_e_return             TYPE bapiret2.

  "抬头
  ls_sales_header_inx-updateflag = 'I'.

  ls_sales_header_in-doc_type = head-doc_type. "订单类型
  ls_sales_header_inx-doc_type = 'X'.
  ls_sales_header_in-sales_org = head-sales_org. "销售组织
  ls_sales_header_inx-sales_org = 'X'.
  ls_sales_header_in-distr_chan = head-distr_chan. "分销渠道
  ls_sales_header_inx-distr_chan = 'X'.
  ls_sales_header_in-division = head-division. "产品组
  ls_sales_header_inx-division = 'X'.
  IF head-purch_no_c IS NOT INITIAL.
    ls_sales_header_in-purch_no_c = head-purch_no_c. "客户采购订单编号
    ls_sales_header_inx-purch_no_c = 'X'.
  ENDIF.

  IF head-purch_date IS NOT INITIAL.
    ls_sales_header_in-purch_date = head-purch_date. "客户采购订单日期
    ls_sales_header_inx-purch_date = 'X'.
  ENDIF.

  IF head-comp_cde_b IS NOT INITIAL.
    ls_sales_header_in-comp_cde_b = head-comp_cde_b. "收票方的公司代码
    ls_sales_header_inx-comp_cde_b = 'X'.
  ENDIF.

  IF head-ord_reason IS NOT INITIAL.
    ls_sales_header_in-ord_reason = head-ord_reason. "订购原因( 业务原因 )
    ls_sales_header_inx-ord_reason = 'X'.
  ENDIF.

  IF head-bill_date IS NOT INITIAL.
    ls_sales_header_in-bill_date = head-bill_date. "出具发票索引和打印的出具发票日期
    ls_sales_header_inx-bill_date = 'X'.
  ENDIF.

  IF head-serv_date IS NOT INITIAL.
    ls_sales_header_in-serv_date = head-serv_date. "提供服务日期
    ls_sales_header_inx-serv_date = 'X'.
  ENDIF.

  "明细行信息
  LOOP AT item INTO ls_item.
    ls_sales_items_inx-updateflag = 'I'.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = ls_item-itm_number
      IMPORTING
        output = ls_item-itm_number.
    ls_sales_items_in-itm_number = ls_item-itm_number. "行项目号
    ls_sales_items_inx-itm_number = ls_item-itm_number.
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = ls_item-material
      IMPORTING
        output       = ls_item-material
      EXCEPTIONS
        length_error = 1
        OTHERS       = 2.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
    ls_sales_items_in-material = ls_item-material. "物料号
    ls_sales_items_inx-material = 'X'.
    ls_sales_items_in-target_qty = ls_item-target_qty. "数量
    ls_sales_items_inx-target_qty = 'X'.
    IF ls_item-target_qu IS NOT INITIAL.
      ls_sales_items_in-target_qu = ls_item-target_qu. "单位
      ls_sales_items_inx-target_qu = 'X'.
    ENDIF.

    IF ls_item-reason_rej IS NOT INITIAL.
      ls_sales_items_in-reason_rej = ls_item-reason_rej. "拒绝原因
      ls_sales_items_inx-reason_rej = 'X'.
    ENDIF.

    IF ls_item-item_categ IS NOT INITIAL.
      ls_sales_items_in-item_categ = ls_item-item_categ. "项目类别
      ls_sales_items_inx-item_categ = 'X'.
    ENDIF.

    APPEND ls_sales_items_in TO sales_items_in.
    APPEND ls_sales_items_inx TO sales_items_inx.
    CLEAR: ls_sales_items_in, ls_sales_items_inx, ls_item.
  ENDLOOP.


  "合作伙伴信息
  IF head-kunnr IS NOT INITIAL. "售达方
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = head-kunnr
      IMPORTING
        output = head-kunnr.
    ls_sales_partners-partn_role = 'AG'.
    ls_sales_partners-partn_numb = head-kunnr.
    APPEND ls_sales_partners TO sales_partners.
    CLEAR: ls_sales_partners.
  ENDIF.

  IF head-ktonr_py IS NOT INITIAL. "付款方
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = head-ktonr_py
      IMPORTING
        output = head-ktonr_py.
    ls_sales_partners-partn_role = 'RG'.
    ls_sales_partners-partn_numb = head-ktonr_py.
    APPEND ls_sales_partners TO sales_partners.
    CLEAR: ls_sales_partners.
  ENDIF.

  IF head-ktonr_sh IS NOT INITIAL. "送达方
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = head-ktonr_sh
      IMPORTING
        output = head-ktonr_sh.
    ls_sales_partners-partn_role = 'WE'.
    ls_sales_partners-partn_numb = head-ktonr_sh.
    APPEND ls_sales_partners TO sales_partners.
    CLEAR: ls_sales_partners.

  ENDIF.

  "价格信息
  LOOP AT item_curr INTO ls_item_curr.
    ls_sales_conditions_inx-updateflag = 'I'.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = ls_item_curr-itm_number
      IMPORTING
        output = ls_item_curr-itm_number.

    ls_sales_conditions_in-itm_number = ls_item_curr-itm_number.
    ls_sales_conditions_inx-itm_number = ls_item_curr-itm_number.
    ls_sales_conditions_in-cond_type = ls_item_curr-cond_type.
    ls_sales_conditions_inx-cond_type = ls_item_curr-cond_type.
    ls_sales_conditions_in-cond_value = ls_item_curr-cond_value.
    ls_sales_conditions_inx-cond_value = 'X'.
    ls_sales_conditions_in-currency = ls_item_curr-currency.
    ls_sales_conditions_inx-currency = 'X'.
    IF ls_item_curr-cond_unit IS NOT INITIAL.
      ls_sales_conditions_in-cond_unit = ls_item_curr-cond_unit.
      ls_sales_conditions_inx-cond_unit = 'X'.
    ENDIF.

    IF ls_item_curr-cond_p_unt IS NOT INITIAL.
      ls_sales_conditions_in-cond_p_unt = ls_item_curr-cond_p_unt.
      ls_sales_conditions_inx-cond_p_unt = 'X'.
    ENDIF.

    APPEND ls_sales_conditions_in TO sales_conditions_in.
    APPEND ls_sales_conditions_inx TO sales_conditions_inx.
    CLEAR: ls_sales_conditions_in, ls_sales_conditions_inx, ls_item_curr.
  ENDLOOP.

  CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
    EXPORTING
*     SALESDOCUMENT        =
      sales_header_in      = ls_sales_header_in
      sales_header_inx     = ls_sales_header_inx
*     SENDER               =
*     BINARY_RELATIONSHIPTYPE       = ' '
*     INT_NUMBER_ASSIGNMENT         = ' '
*     BEHAVE_WHEN_ERROR    = ' '
*     LOGIC_SWITCH         = ' '
*     BUSINESS_OBJECT      = ' '
*     TESTRUN              =
*     CONVERT_PARVW_AUART  = ' '
*     STATUS_BUFFER_REFRESH         = 'X'
*     CALL_ACTIVE          = ' '
*     I_WITHOUT_INIT       = ' '
    IMPORTING
      salesdocument_ex     = salesdocument_ex
      sales_header_out     = sales_header_out
*     SALES_HEADER_STATUS  =
    TABLES
      return               = return
      sales_items_in       = sales_items_in
      sales_items_inx      = sales_items_inx
      sales_partners       = sales_partners
*     SALES_SCHEDULES_IN   =
*     SALES_SCHEDULES_INX  =
      sales_conditions_in  = sales_conditions_in
      sales_conditions_inx = sales_conditions_inx
*     SALES_CFGS_REF       =
*     SALES_CFGS_INST      =
*     SALES_CFGS_PART_OF   =
*     SALES_CFGS_VALUE     =
*     SALES_CFGS_BLOB      =
*     SALES_CFGS_VK        =
*     SALES_CFGS_REFINST   =
*     SALES_CCARD          =
*     SALES_TEXT           =
*     SALES_KEYS           =
*     SALES_CONTRACT_IN    =
*     SALES_CONTRACT_INX   =
*     EXTENSIONIN          =
*     PARTNERADDRESSES     =
*     SALES_SCHED_CONF_IN  =
*     ITEMS_EX             =
*     SCHEDULE_EX          =
*     BUSINESS_EX          =
*     INCOMPLETE_LOG       =
*     EXTENSIONEX          =
*     CONDITIONS_EX        =
*     PARTNERS_EX          =
*     TEXTHEADERS_EX       =
*     TEXTLINES_EX         =
*     BATCH_CHARC          =
*     CAMPAIGN_ASGN        =
*     CONDITIONS_KONV_EX   =
    .
  LOOP AT return INTO ls_return WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.
  IF sy-subrc = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
*     IMPORTING
*       RETURN        =
      .

  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'
*     IMPORTING
*       RETURN        =
      .

  ENDIF.

  salesdocument_out = salesdocument_ex.
  LOOP AT return INTO ls_return.
    ls_e_return = ls_return.
    APPEND ls_e_return TO e_return.
    CLEAR: ls_e_return, ls_return.
  ENDLOOP.

ENDFUNCTION.

你可能感兴趣的:(sap)