DEMO:VA01创建贷项订单SD_SALESDOCUMENT_CREATE_SAP刘梦_新浪博客

DEMO:VA01创建贷项订单SD_SALESDOCUMENT_CREATE
*&---------------------------------------------------------------------*
*& Report  ZDEMO_VA01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdemo_va01_zdcr.

PARAMETERS p_kunnr TYPE kunnr DEFAULT '1004615'.
PARAMETERS p_vkorg TYPE vkorg DEFAULT 'S600'.
PARAMETERS p_vtweg TYPE vtweg DEFAULT '10'.
PARAMETERS p_spart TYPE spart DEFAULT '00'.
PARAMETERS p_werks TYPE werks_d DEFAULT 'S600'.
PARAMETERS p_lgort TYPE lgort_d DEFAULT '6001'.
PARAMETERS p_vstel TYPE vstel DEFAULT 'S600'.
PARAMETERS p_matnr TYPE matnr DEFAULT 'XSWPTEST'.


DATA:ls_order_header_in       LIKE bapisdhd1.
DATA:ls_order_header_inx      LIKE bapisdhd1x.
DATA:lt_order_items_in        LIKE TABLE OF bapisditm.
DATA:lt_order_items_inx       LIKE TABLE OF bapisditmx.
DATA:ls_order_items_in        LIKE bapisditm.
DATA:ls_order_items_inx       LIKE bapisditmx.
DATA:lt_order_partners        LIKE TABLE OF bapiparnr.
DATA:ls_order_partners        LIKE LINE OF lt_order_partners.
DATA:lt_schedules_in          LIKE TABLE OF bapischdl .
DATA:lt_schedules_inx         LIKE TABLE OF  bapischdlx .
DATA:ls_schedules_in          LIKE bapischdl .
DATA:ls_schedules_inx         LIKE bapischdlx .
DATA:lt_order_conditions_in   LIKE TABLE OF  bapicond .
DATA:lt_order_conditions_inx  LIKE TABLE OF  bapicondx .
DATA:ls_order_conditions_in   LIKE  bapicond .
DATA:ls_order_conditions_inx  LIKE  bapicondx .

DATA: lt_return               LIKE TABLE OF bapiret2.
DATA: ls_return               LIKE    bapiret2.

DATA:lv_salesdocument     LIKE bapivbeln-vbeln.

CLEAR ls_order_header_in.
ls_order_header_in-doc_type     = 'ZDCR'."订单类型
ls_order_header_in-sales_org    = p_vkorg.
ls_order_header_in-distr_chan   = p_vtweg."分销渠道
ls_order_header_in-division     = p_spart."产品组
*    ls_order_header_in-sales_off    = . "销售部门
ls_order_header_in-purch_no_c = 'test'.
ls_order_header_in-BILL_DATE = '20190820'."开具发票日期

CLEAR ls_order_header_inx.
ls_order_header_inx-doc_type   = 'X'.
ls_order_header_inx-sales_org  = 'X'.
ls_order_header_inx-distr_chan = 'X'.
ls_order_header_inx-division   = 'X'.
*ls_order_header_inx-sales_off  = 'X'.
ls_order_header_inx-ass_number = 'X'.
ls_order_header_inx-updateflag = '1'.
ls_order_header_inx-purch_no_c = 'X'.
ls_order_header_inx-BILL_DATE = 'X'.

CLEAR ls_order_items_in.
CLEAR lt_order_items_in[].
ls_order_items_in-itm_number   = '10'."只有一个行项目
ls_order_items_in-material     = p_matnr.
ls_order_items_in-plant        = p_werks.
ls_order_items_in-store_loc    = p_lgort.
ls_order_items_in-target_qty   = 1.
ls_order_items_in-ship_point   = p_vstel."装运点
ls_order_items_in-target_qu    = 'EA'.
ls_order_items_in-sales_unit   = 'EA'.

APPEND ls_order_items_in TO lt_order_items_in.

CLEAR lt_schedules_in[].
CLEAR ls_schedules_in.
ls_schedules_in-itm_number      =  '10'."只有一个行项目
ls_schedules_in-req_qty         = 1.
APPEND ls_schedules_in TO lt_schedules_in.

CLEAR ls_schedules_inx.
CLEAR lt_schedules_inx[].
ls_schedules_inx-updateflag      = 'X'.
ls_schedules_inx-itm_number      = 'X'.
ls_schedules_inx-req_qty         = 'X'.
APPEND ls_schedules_inx TO lt_schedules_inx.

"售达方默认
CLEAR ls_order_partners.
ls_order_partners-partn_role   = 'AG'.
ls_order_partners-partn_numb   = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.


*&-------------------------------------
"送达方 使用一次性客户
*&-------------------------------------

CLEAR ls_order_partners.
*ls_order_partners-partn_role   = 'WE'.
*ls_order_partners-partn_numb   = '1'.
*
*CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*  EXPORTING
*    input  = ls_order_partners-partn_numb
*  IMPORTING
*    output = ls_order_partners-partn_numb.
*
*ls_order_partners-name         = '一次性客户测试'.
*ls_order_partners-country      = 'CN'.
*APPEND ls_order_partners TO lt_order_partners.

"送达方
CLEAR ls_order_partners.
ls_order_partners-partn_role   = 'WE'.
ls_order_partners-partn_numb   = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.

*&---------------------------------------------------------------


"付款方
CLEAR ls_order_partners.
ls_order_partners-partn_role   = 'RE'.
ls_order_partners-partn_numb   = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.

"收票方
CLEAR ls_order_partners.
ls_order_partners-partn_role   = 'RG'.
ls_order_partners-partn_numb   = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.

CLEAR lt_order_conditions_in[].
CLEAR lt_order_conditions_inx[].


CLEAR ls_order_conditions_in.
ls_order_conditions_in-itm_number = '10'.
ls_order_conditions_in-cond_st_no = ''.
ls_order_conditions_in-cond_count = ''.
ls_order_conditions_in-cond_type  = 'ZP32'.  "定价条件
ls_order_conditions_in-cond_value = 1000.
ls_order_conditions_in-currency   = 'RMB'.  "币别

APPEND ls_order_conditions_in TO lt_order_conditions_in.

CLEAR ls_order_conditions_inx.

ls_order_conditions_inx-itm_number = '10'.
ls_order_conditions_inx-cond_st_no = ''.
ls_order_conditions_inx-cond_count = ''.
ls_order_conditions_inx-updateflag = 'X'.
ls_order_conditions_inx-cond_type  = 'ZP32'.  "定价条件
ls_order_conditions_inx-cond_value = 'X'.  "价格

IF ls_order_conditions_in-currency IS NOT INITIAL.
  ls_order_conditions_inx-currency   = 'X'.  "币别
ENDIF.


APPEND ls_order_conditions_inx TO lt_order_conditions_inx.

CLEAR lv_salesdocument.
CALL FUNCTION 'SD_SALESdocument.create_r'
  EXPORTING
    sales_header_in      = ls_order_header_in
    sales_header_inx     = ls_order_header_inx
  IMPORTING
    salesdocument_ex     = lv_salesdocument
  TABLES
    return               = lt_return
    sales_items_in       = lt_order_items_in
    sales_items_inx      = lt_order_items_inx
    sales_partners       = lt_order_partners
    sales_schedules_in   = lt_schedules_in
    sales_schedules_inx  = lt_schedules_inx
    sales_conditions_in  = lt_order_conditions_in
    sales_conditions_inx = lt_order_conditions_inx.

**&不能使用 BAPI_SALESORDER_CREATEFROMDAT2
*CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
*  EXPORTING
*    order_header_in      = ls_order_header_in
*    order_header_inx     = ls_order_header_inx
*  IMPORTING
*    salesdocument        = lv_salesdocument
*  TABLES
*    return               = lt_return
*    order_items_in       = lt_order_items_in
*    order_items_inx      = lt_order_items_inx
*    order_partners       = lt_order_partners
*    order_schedules_in   = lt_schedules_in
*    order_schedules_inx  = lt_schedules_inx
*    order_conditions_in  = lt_order_conditions_in
*    order_conditions_inx = lt_order_conditions_inx.

IF lv_salesdocument IS NOT INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.

ENDIF.

WRITE lv_salesdocument.

DEMO:VA01创建贷项订单SD_SALESDOCUMENT_CREATE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值