DATA: LW_SALES_HEADER_IN LIKE BAPISDHD1,
LW_SALES_HEADER_INX LIKE BAPISDHD1X,
LV_SALESDOCUMENT_EX LIKE BAPIVBELN-VBELN,
LT_SALES_ITEMS_IN LIKE TABLE OF BAPISDITM WITH HEADER LINE,
LT_SALES_ITEMS_INX LIKE TABLE OF BAPISDITMX WITH HEADER LINE,
LT_SALES_SCHEDULES_IN LIKE TABLE OF BAPISCHDL WITH HEADER LINE,
LT_SALES_SCHEDULES_INX LIKE TABLE OF BAPISCHDLX WITH HEADER LINE,
LT_SALES_CONDITIONS_IN LIKE TABLE OF BAPICOND WITH HEADER LINE,
LT_SALES_CONDITIONS_INX LIKE TABLE OF BAPICONDX WITH HEADER LINE,
LT_SALES_TEXT LIKE TABLE OF BAPISDTEXT WITH HEADER LINE,
LT_SALES_PARTNERS_IN LIKE TABLE OF BAPIPARNR WITH HEADER LINE,
LT_RETURN LIKE TABLE OF BAPIRET2 WITH HEADER LINE.
DATA: LT_00700 TYPE TABLE OF ZMMTZR00700 WITH HEADER LINE.
DATA: L_ANSWER TYPE C.
CLEAR: LT_SALES_ITEMS_IN, LT_SALES_ITEMS_INX,
LT_SALES_SCHEDULES_IN, LT_SALES_SCHEDULES_INX,
LT_SALES_CONDITIONS_IN,LT_SALES_CONDITIONS_INX,
LT_SALES_PARTNERS_IN,
LT_RETURN.
**=> sales order header
IF LW_SALES_HEADER_IN IS INITIAL.
LW_SALES_HEADER_IN-DOC_TYPE = 'ZSFI'. " 销售凭证类型
LW_SALES_HEADER_IN-SALES_ORG = 'ZR04'. " 销售组织
LW_SALES_HEADER_IN-DISTR_CHAN = 'S7'. " 分销渠道
LW_SALES_HEADER_IN-SALES_GRP = '17Z'. " 销售组
* LW_SALES_HEADER_IN-DIVISION = '01'. " 产品组
LW_SALES_HEADER_IN-SALES_OFF = 'ZRZ1'. " 销售部门
* LW_SALES_HEADER_IN-REQ_DATE_H = '20181010'. " 请求交货日期
LW_SALES_HEADER_IN-DOC_DATE = '20181010'. " 凭证日期
LW_SALES_HEADER_IN-S_PROC_IND = 'S1'. " 特殊处理标记
LW_SALES_HEADER_IN-SHIP_TYPE = '01'. " 装运类型
* LW_SALES_HEADER_IN-PURCH_NO_C = 'P00001' " 客户采购订单编号
* LW_SALES_HEADER_IN-SALES_DIST = '123'. " 销售地区
* LW_SALES_HEADER_IN-INCOTERMS1 = 120' " 国际贸易条件
* LW_SALES_HEADER_IN-INCOTERMS2 = '120. " 国际贸易条件
* LW_SALES_HEADER_IN-PMNTTRMS = '/'. " 付款条件
LW_SALES_HEADER_INX-DOC_TYPE = ABAP_TRUE.
LW_SALES_HEADER_INX-SALES_ORG = ABAP_TRUE.
LW_SALES_HEADER_INX-DISTR_CHAN = ABAP_TRUE.
LW_SALES_HEADER_INX-SALES_GRP = ABAP_TRUE.
* LW_SALES_HEADER_INX-DIVISION = ABAP_TRUE.
LW_SALES_HEADER_INX-SALES_OFF = ABAP_TRUE.
* LW_SALES_HEADER_INX-REQ_DATE_H = ABAP_TRUE.
LW_SALES_HEADER_INX-DOC_DATE = ABAP_TRUE.
LW_SALES_HEADER_INX-S_PROC_IND = ABAP_TRUE.
LW_SALES_HEADER_INX-SHIP_TYPE = ABAP_TRUE.
* LW_SALES_HEADER_INX-PURCH_NO_C = ABAP_TRUE.
ENDIF.
IF LT_SALES_PARTNERS_IN[] IS INITIAL.
CLEAR : LT_SALES_PARTNERS_IN.
LT_SALES_PARTNERS_IN-PARTN_ROLE = 'SP'. "
LT_SALES_PARTNERS_IN-PARTN_NUMB = '0035950000'.
APPEND LT_SALES_PARTNERS_IN.
CLEAR : LT_SALES_PARTNERS_IN.
LT_SALES_PARTNERS_IN-PARTN_ROLE = 'SH'. "
LT_SALES_PARTNERS_IN-PARTN_NUMB = '0035950000'.
APPEND LT_SALES_PARTNERS_IN.
* CLEAR : LT_SALES_PARTNERS_in.
* LT_SALES_PARTNERS_in-PARTN_ROLE = 'BP'. "
* LT_SALES_PARTNERS_in-PARTN_NUMB = ZMMTZR00770-KUNNR.
* APPEND LT_SALES_PARTNERS_in.
*
* CLEAR : LT_SALES_PARTNERS_in.
* LT_SALES_PARTNERS_in-PARTN_ROLE = 'PY'. "
* LT_SALES_PARTNERS_in-PARTN_NUMB = ZMMTZR00770-KUNNR.
* APPEND LT_SALES_PARTNERS_in.
ENDIF.
**=> sales order item
LT_SALES_ITEMS_IN-ITM_NUMBER = '10'.
LT_SALES_ITEMS_IN-MATERIAL = '000623040060001874'. " 物料
LT_SALES_ITEMS_IN-SALES_UNIT = 'MT'. " 计量单位
LT_SALES_ITEMS_IN-PLANT = 'ZRAX'. " 工厂
LT_SALES_ITEMS_IN-STORE_LOC = 'Z001'. " 库存地点
LT_SALES_ITEMS_IN-SHIP_TYPE = '01'. " 装运类型-汽车
* LT_SALES_ITEMS_IN-TARGET_QU = 'KG'. " 目标数量计量单位
* LT_SALES_ITEMS_IN-VAL_TYPE = 'AA'. " 评估类型
LT_SALES_ITEMS_IN-PROFIT_CTR = '9ZRA015000'. " 利润中心
LT_SALES_ITEMS_INX-ITM_NUMBER = '10'.
LT_SALES_ITEMS_INX-MATERIAL = ABAP_TRUE.
LT_SALES_ITEMS_INX-SALES_UNIT = ABAP_TRUE.
LT_SALES_ITEMS_INX-PLANT = ABAP_TRUE.
LT_SALES_ITEMS_INX-STORE_LOC = ABAP_TRUE.
LT_SALES_ITEMS_INX-SHIP_TYPE = ABAP_TRUE.
* LT_SALES_ITEMS_INX-TARGET_QU = ABAP_TRUE.
LT_SALES_ITEMS_INX-PROFIT_CTR = ABAP_TRUE . " 利润中心
APPEND: LT_SALES_ITEMS_IN, LT_SALES_ITEMS_INX.
CLEAR: LT_SALES_ITEMS_IN, LT_SALES_ITEMS_INX.
" 计划行号
LT_SALES_SCHEDULES_IN-ITM_NUMBER = '10'.
LT_SALES_SCHEDULES_IN-SCHED_LINE = '0001'. " L_TABIX.
LT_SALES_SCHEDULES_IN-REQ_DATE = SY-DATUM. " 计划行日期
LT_SALES_SCHEDULES_IN-REQ_QTY = '10'. " 以销售单位计的 订单数量
LT_SALES_SCHEDULES_INX-ITM_NUMBER = '10'.
LT_SALES_SCHEDULES_INX-SCHED_LINE = '0001'.
LT_SALES_SCHEDULES_INX-REQ_DATE = ABAP_TRUE.
LT_SALES_SCHEDULES_INX-REQ_QTY = ABAP_TRUE.
APPEND: LT_SALES_SCHEDULES_IN, LT_SALES_SCHEDULES_INX.
CLEAR: LT_SALES_SCHEDULES_IN, LT_SALES_SCHEDULES_INX.
*** 条件 ********************************************************************
* IF ZMMTZR00780-PRICE NE 0.
* LT_SALES_CONDITIONS_IN-ITM_NUMBER = '10'.
* LT_SALES_CONDITIONS_IN-COND_TYPE = 'PR01'. " 条件类型 定价条件
* LT_SALES_CONDITIONS_IN-COND_VALUE = '100'. " 价格 定价比率
* LT_SALES_CONDITIONS_IN-CURRENCY = 'RMB' " 货币码
** LT_SALES_CONDITIONS_IN-COND_UNIT = '1'. " 条件单位
** LT_SALES_CONDITIONS_IN-COND_P_UNT = KG. " 条件定价单位
*
* LT_SALES_CONDITIONS_INX-ITM_NUMBER = ABAP_TRUE.
* LT_SALES_CONDITIONS_INX-COND_TYPE = ABAP_TRUE.
* LT_SALES_CONDITIONS_INX-CURRENCY = ABAP_TRUE.
* LT_SALES_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.
*
* APPEND: LT_SALES_CONDITIONS_IN, LT_SALES_CONDITIONS_INX.
* CLEAR: LT_SALES_CONDITIONS_IN, LT_SALES_CONDITIONS_INX.
*
* ENDIF.
DATA:LV_STRING TYPE STRING,
LV_CHAR(960) TYPE C,
LS_BAPE_VBAP TYPE BAPE_VBAP,
LS_BAPE_VBAPX TYPE BAPE_VBAPX,
LS_BAPE_VBAK TYPE BAPE_VBAK,
LS_BAPE_VBAKX TYPE BAPE_VBAKX.
DATA: LT_EXTENSIONIN TYPE TABLE OF BAPIPAREX WITH HEADER LINE.
**添加扩展字段
* CLEAR: LS_BAPE_VBAP,LT_EXTENSIONIN.
** LS_BAPE_VBAP-VBELN = LS_TAB-VBELN.
* LS_BAPE_VBAP-POSNR = '10'.
* LS_BAPE_VBAP-ZXSJG = 100. " 用户
* LS_BAPE_VBAP-SGSJG = 110 . " 省公司
*
* LT_EXTENSIONIN-STRUCTURE = 'BAPE_VBAP'.
CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C
EXPORTING
IM_VALUE = LS_BAPE_VBAP
IMPORTING
EX_CONTAINER = LT_EXTENSIONIN+30
EXCEPTIONS
ILLEGAL_PARAMETER_TYPE = 1
OTHERS = 2.
APPEND LT_EXTENSIONIN.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
SALES_HEADER_IN = LW_SALES_HEADER_IN
SALES_HEADER_INX = LW_SALES_HEADER_INX
CONVERT_PARVW_AUART = 'X'
IMPORTING
SALESDOCUMENT_EX = LV_SALESDOCUMENT_EX
TABLES
RETURN = LT_RETURN
SALES_ITEMS_IN = LT_SALES_ITEMS_IN
SALES_ITEMS_INX = LT_SALES_ITEMS_INX
* SALES_CONDITIONS_IN = LT_SALES_CONDITIONS_IN
* SALES_CONDITIONS_INX = LT_SALES_CONDITIONS_INX
SALES_SCHEDULES_IN = LT_SALES_SCHEDULES_IN
SALES_SCHEDULES_INX = LT_SALES_SCHEDULES_INX
SALES_PARTNERS = LT_SALES_PARTNERS_IN.
IF SY-SUBRC EQ 0.
COMMIT WORK.
ENDIF.