创建销售订单的函数有3个:
BAPI_SALESORDER_CREATEFROMDAT2
BAPI_CUSTOMERRETURN_CREATE
SD_SALESDOCUMENT_CREATE
前面2个BAPI都是调用的第三个函数SD_SALESDOCUMENT_CREATE,区别在于里面的业务类型是固定的,BAPI_SALESORDER_CREATEFROMDAT2限制了业务对象为BUS2032,创建退货类型的销售订单时会提示BUS2032与H类型不匹配,需要使用函数SD_SALESDOCUMENT_CREATE来创建。
DATA: lv_msg(100) TYPE c,
ls_kna1 TYPE kna1,
lv_kunnr TYPE kna1-kunnr,
ls_zsdt005 TYPE zsdt005,
lv_vbeln TYPE bapivbeln-vbeln,
lv_posnr TYPE vbap-posnr,
ls_edit TYPE lvc_s_styl,
lt_edit TYPE lvc_t_styl.
DATA: ls_head_in TYPE bapisdhd1,
ls_head_inx TYPE bapisdhd1x,
lt_items_in TYPE TABLE OF bapisditm,
ls_items_in TYPE bapisditm,
lt_items_inx TYPE TABLE OF bapisditmx,
ls_items_inx TYPE bapisditmx,
lt_partners TYPE TABLE OF bapiparnr,
ls_partners TYPE bapiparnr,
lt_schedules_in TYPE TABLE OF bapischdl,
ls_schedules_in TYPE bapischdl,
lt_schedules_inx TYPE TABLE OF bapischdlx,
ls_schedules_inx TYPE bapischdlx,
lt_conditions_in TYPE TABLE OF bapicond,
ls_conditions_in TYPE bapicond,
lt_conditions_inx TYPE TABLE OF bapicondx,
ls_conditions_inx TYPE bapicondx,
lt_extensionin TYPE TABLE OF bapiparex,
ls_extensionin TYPE bapiparex,
lt_text TYPE TABLE OF bapisdtext,
ls_text TYPE bapisdtext,
lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2,
lt_kortab TYPE TABLE OF mdvu,
ls_kortab TYPE mdvu.
DATA: ls_bape_vbak TYPE bape_vbak, "屏幕增强字段
ls_bape_vbakx TYPE bape_vbakx.
DATA: ls_bape_vbap TYPE bape_vbap, "屏幕增强字段
ls_bape_vbapx TYPE bape_vbapx.
*"----------------------------------------------------------------------
* 销售订单抬头数据
*"----------------------------------------------------------------------
CLEAR gs_data.
READ TABLE gt_data INTO gs_data WITH KEY zsel = 'X' kunnr = pv_kunnr.
"客户编号
lv_kunnr = gs_data-kunnr.
ls_head_in-purch_no_c = gs_data-remark. "客户采购订单编号
ls_head_in-purch_no_s = gs_data-bookingid. "运达方采购订单编号 PO号
ls_head_in-doc_type = 'ZJR'. "销售凭证类型
ls_head_in-sales_org = '2016'. "销售组织
ls_head_in-distr_chan = '10'. "分销渠道
ls_head_in-division = '20'. "产品组
ls_head