START-OF-SELECTION.
*DATA SALESDOCUMENTIN TYPE BAPIVBELN-VBELN.
DATA:gs_order_header_in TYPE bapisdhd1.
DATA:gs_order_header_inx TYPE bapisdhd1x.
*DATA SENDER TYPE BAPI_SENDER.
*DATA BINARY_RELATIONSHIPTYPE TYPE BAPIRELTYPE-RELTYPE.
*DATA INT_NUMBER_ASSIGNMENT TYPE BAPIFLAG-BAPIFLAG.
*DATA BEHAVE_WHEN_ERROR TYPE BAPIFLAG-BAPIFLAG.
DATA:gs_logic_switch TYPE bapisdls.
*DATA TESTRUN TYPE BAPIFLAG-BAPIFLAG.
*DATA CONVERT TYPE BAPIFLAG-BAPIFLAG.
DATA:gs_salesdocument TYPE bapivbeln-vbeln.
DATA:gt_return TYPE STANDARD TABLE OF bapiret2.
DATA:gs_return TYPE bapiret2.
DATA:gt_order_items_in TYPE STANDARD TABLE OF bapisditm.
DATA:gs_order_items_in TYPE bapisditm.
DATA:gt_order_items_inx TYPE STANDARD TABLE OF bapisditmx.
DATA:gs_order_items_inx TYPE bapisditmx.
DATA:gt_order_partners TYPE STANDARD TABLE OF bapiparnr.
DATA:gs_order_partners TYPE bapiparnr.
DATA:gt_order_schedules_in TYPE STANDARD TABLE OF bapischdl.
DATA:gs_order_schedules_in TYPE bapischdl.
DATA:gt_order_schedules_inx TYPE STANDARD TABLE OF bapischdlx.
DATA:gs_order_schedules_inx TYPE bapischdlx.
DATA:gt_order_conditions_in TYPE STANDARD TABLE OF bapicond.
DATA:gs_order_conditions_in TYPE bapicond.
DATA:gt_order_conditions_inx TYPE STANDARD TABLE OF bapicondx.
DATA:gs_order_conditions_inx TYPE bapicondx.
*DATA ORDER_CFGS_REF TYPE STANDARD TABLE OF BAPICUCFG.
*DATA ORDER_CFGS_INST TYPE STANDARD TABLE OF BAPICUINS.
*DATA ORDER_CFGS_PART_OF TYPE STANDARD TABLE OF BAPICUPRT.
*DATA ORDER_CFGS_VALUE TYPE STANDARD TABLE OF BAPICUVAL.
*DATA ORDER_CFGS_BLOB TYPE STANDARD TABLE OF BAPICUBLB.
*DATA ORDER_CFGS_VK TYPE STANDARD TABLE OF BAPICUVK.
*DATA ORDER_CFGS_REFINST TYPE STANDARD TABLE OF BAPICUREF.
*DATA ORDER_CCARD TYPE STANDARD TABLE OF BAPICCARD.
*DATA ORDER_TEXT TYPE STANDARD TABLE OF BAPISDTEXT.
*DATA ORDER_KEYS TYPE STANDARD TABLE OF BAPISDKEY.
*DATA EXTENSIONIN TYPE STANDARD TABLE OF BAPIPAREX.
*DATA PARTNERADDRESSES TYPE STANDARD TABLE OF BAPIADDR1.
*DATA EXTENSIONEX TYPE STANDARD TABLE OF BAPIPAREX.
DATA:g_vbeln TYPE vbak-vbeln.
DATA:gt_vbap TYPE STANDARD TABLE OF vbap.
DATA:gs_vbap TYPE vbap.
DATA:gt_vbkd TYPE STANDARD TABLE OF vbkd.
DATA:gs_vbkd TYPE vbkd.
DATA:gs_vbak TYPE vbak.
DATA:gt_konv TYPE STANDARD TABLE OF konv.
DATA:gs_konv TYPE konv.
DATA:gv_bstkd TYPE bstkd.
DATA:g_zlsch TYPE vbkd-zlsch.
DATA:g_vsart TYPE vbkd-vsart.
*原销售订单
* g_vbeln = '0070000089'.
gv_bstkd = 'PS17110005'.
*根据DMS订单号抓取SAP的SO
SELECT SINGLE vbeln
FROM vbkd
INTO g_vbeln
WHERE bstkd = gv_bstkd.
*SO的抬头
SELECT SINGLE *
FROM vbak
INTO CORRESPONDING FIELDS OF gs_vbak.
*明细
SELECT *
FROM vbap
INTO CORRESPONDING FIELDS OF TABLE gt_vbap
WHERE vbeln = g_vbeln.
SELECT SINGLE zlsch
FROM vbkd
INTO g_zlsch
WHERE vbeln = g_vbeln.
SELECT SINGLE vsart
FROM vbkd
INTO g_vsart
WHERE vbeln = g_vbeln.
********抬头
gs_order_header_in-doc_type = 'ZARE'. "订单类型
gs_order_header_in-sales_org = '1000'. "销售组织
gs_order_header_in-distr_chan = '20'. "分销渠道
gs_order_header_in-division = '00'. "产品组
gs_order_header_in-doc_date = sy-datum. "凭证日期 (接收/发送日期)
gs_order_header_in-purch_date = sy-datum. "客户采购订单日期-退货日期
gs_order_header_in-pymt_meth = g_zlsch."付款方式
gs_order_header_in-purch_no_c = gv_bstkd.
gs_order_header_in-ship_type = g_vsart.
*参考单据号
gs_order_header_in-refdoc_cat = 'C'. "C 销售订单
gs_order_header_in-ref_doc = g_vbeln. "参考的单据号
gs_order_header_inx-doc_type = 'X'. "订单类型
gs_order_header_inx-refdoc_cat = 'X'. "报价单
gs_order_header_inx-ref_doc = 'X'. "参考的报价单
gs_order_header_inx-sales_org = 'X'. "销售组织
gs_order_header_inx-distr_chan = 'X'. "分销渠道
gs_order_header_inx-division = 'X'. "产品组
gs_order_header_inx-pymt_meth = 'X'."付款方式
gs_order_header_inx-purch_no_c = 'X'.
gs_order_header_inx-ship_type = 'X'.
*****定价
gs_logic_switch-pricing = 'B'. "定价类型 设置为B会自动带出来
gs_logic_switch-cond_handl = 'X'.
**********明细
*需要退货的物料
LOOP AT gt_vbap INTO gs_vbap WHERE matnr = 'BK3Q 9430CE'.
*匹配传入的退货物料
* READ TABLE 传入的物料内表
gs_order_items_in-itm_number = gs_vbap-posnr."行号
gs_order_items_in-ref_doc = gs_vbap-vbeln. "参考凭证号
gs_order_items_in-ref_doc_it = gs_vbap-posnr. "参考项目的项目号
gs_order_items_in-ref_doc_ca = 'C'. "销售订单
gs_order_items_in-material = gs_vbap-matnr. "物料号
gs_order_items_in-plant = gs_vbap-werks.
gs_order_items_in-target_qty = '1'. "退货物料
APPEND gs_order_items_in TO gt_order_items_in.
CLEAR gs_order_items_in.
gs_order_items_inx-ref_doc = 'X'. "参考凭证号
gs_order_items_inx-ref_doc_it = 'X'. "参考项目的项目号
gs_order_items_inx-ref_doc_ca = 'X'. "报价单
gs_order_items_inx-material = 'X'. "物料号
gs_order_items_inx-target_qty = 'X'. "数量
gs_order_items_inx-plant = 'X' .
APPEND gs_order_items_inx TO gt_order_items_inx.
CLEAR gs_order_items_inx.
********交货数量
gs_order_schedules_in-itm_number = gs_vbap-posnr."行号
gs_order_schedules_in-req_qty = 1. "退货物料
APPEND gs_order_schedules_in TO gt_order_schedules_in.
CLEAR gs_order_schedules_in.
gs_order_schedules_inx-itm_number = gs_vbap-posnr."行号
gs_order_schedules_inx-req_qty = 'X'. "数量
APPEND gs_order_schedules_inx TO gt_order_schedules_inx.
CLEAR gs_order_schedules_inx.
ENDLOOP.
******定价
* SELECT *
* FROM konv
* INTO CORRESPONDING FIELDS OF TABLE gt_konv
* WHERE stunr = gs_vbak-knumv
* AND kposn = gs_vbap-posnr.
*
**抬头的定价条件
* gs_order_conditions_in-cond_type = 'ZHD0'. "条件类型
* gs_order_conditions_in-cond_value = '30'. "金额
* gs_order_conditions_in-currency = 'CNY'. "货币
** GS_ORDER_CONDITIONS_IN-COND_UPDAT = 'X'.
* APPEND gs_order_conditions_in TO gt_order_conditions_in.
* CLEAR gs_order_conditions_in.
*
* gs_order_conditions_inx-cond_type = 'ZHD0'. "条件类型
* gs_order_conditions_inx-cond_value = '30'. "金额
* gs_order_conditions_inx-currency = 'CNY'. "货币
* gs_order_conditions_inx-updateflag = 'I'."更新标识
* APPEND gs_order_conditions_inx TO gt_order_conditions_inx.
* CLEAR gs_order_conditions_inx.
*
* gs_order_conditions_in-cond_type = 'ZHD1'. "条件类型
* gs_order_conditions_in-cond_value = '40'. "金额
* gs_order_conditions_in-currency = 'CNY'. "货币
** GS_ORDER_CONDITIONS_IN-COND_UPDAT = 'X'.
* APPEND gs_order_conditions_in TO gt_order_conditions_in.
* CLEAR gs_order_conditions_in.
*
* gs_order_conditions_inx-cond_type = 'ZHD1'. "条件类型
* gs_order_conditions_inx-cond_value = '40'. "金额
* gs_order_conditions_inx-currency = 'CNY'. "货币
* gs_order_conditions_inx-updateflag = 'I'."更新标识
* APPEND gs_order_conditions_inx TO gt_order_conditions_inx.
* CLEAR gs_order_conditions_inx.
******明细
* gs_order_conditions_in-itm_number = gs_vbap-posnr.
* gs_order_conditions_in-cond_st_no = '210'.
* gs_order_conditions_in-cond_count = '1'.
* gs_order_conditions_in-cond_type = 'ZHSJ'. "条件类型
* gs_order_conditions_in-cond_value = '200'. "金额
* gs_order_conditions_in-currency = 'CNY'. "货币
** GS_ORDER_CONDITIONS_IN-COND_UPDAT = 'X'.
* APPEND gs_order_conditions_in TO gt_order_conditions_in.
* CLEAR gs_order_conditions_in.
*
*
* gs_order_conditions_inx-itm_number = gs_vbap-posnr.
* gs_order_conditions_inx-cond_st_no = '210'.
* gs_order_conditions_inx-cond_count = '1'.
* gs_order_conditions_inx-cond_type = 'ZHSJ'. "条件类型
* gs_order_conditions_inx-cond_value = 'X'. "金额
* gs_order_conditions_inx-currency = 'X'. "货币
* gs_order_conditions_inx-updateflag = 'U'."更新标识
* APPEND gs_order_conditions_inx TO gt_order_conditions_inx.
* CLEAR gs_order_conditions_inx.
**********明细02
* READ TABLE gt_vbap INTO gs_vbap INDEX 2.
* gs_order_items_in-ref_doc = gs_vbap-vbeln. "参考凭证号
* gs_order_items_in-ref_doc_it = gs_vbap-posnr. "参考项目的项目号
* gs_order_items_in-ref_doc_ca = 'B'. "报价单
* gs_order_items_in-material = gs_vbap-matnr. "物料号
* gs_order_items_in-target_qu = gs_vbap-zieme. "单位
* APPEND gs_order_items_in TO gt_order_items_in.
* CLEAR gs_order_items_in.
*
*
* gs_order_items_inx-ref_doc = 'X'. "参考凭证号
* gs_order_items_inx-ref_doc_it = 'X'. "参考项目的项目号
* gs_order_items_inx-ref_doc_ca = 'X'. "报价单
* gs_order_items_inx-material = 'X'. "物料号
* gs_order_items_inx-target_qu = 'X'. "单位
* APPEND gs_order_items_inx TO gt_order_items_inx.
* CLEAR gs_order_items_inx.
*
*********数量
* gs_order_schedules_in-itm_number = gs_vbap-posnr.
* gs_order_schedules_in-req_qty = 1. "数量
* APPEND gs_order_schedules_in TO gt_order_schedules_in.
* CLEAR gs_order_schedules_in.
*
*
* gs_order_schedules_inx-itm_number = gs_vbap-posnr.
* gs_order_schedules_inx-req_qty = 'X'. "数量
* APPEND gs_order_schedules_inx TO gt_order_schedules_inx.
* CLEAR gs_order_schedules_inx.
*
*
*
*******************伙伴参数
*送达方
gs_order_partners-partn_role = 'WE'.
gs_order_partners-partn_numb = '0002112001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_order_partners-partn_numb
IMPORTING
output = gs_order_partners-partn_numb.
APPEND gs_order_partners TO gt_order_partners.
CLEAR gs_order_partners.
*付款方
gs_order_partners-partn_role = 'RG'.
gs_order_partners-partn_numb = '0002112001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_order_partners-partn_numb
IMPORTING
output = gs_order_partners-partn_numb.
APPEND gs_order_partners TO gt_order_partners.
CLEAR gs_order_partners.
*收票方
gs_order_partners-partn_role = 'RE'.
gs_order_partners-partn_numb = '0002112001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_order_partners-partn_numb
IMPORTING
output = gs_order_partners-partn_numb.
APPEND gs_order_partners TO gt_order_partners.
CLEAR gs_order_partners.
*售达方
gs_order_partners-partn_role = 'AG'.
gs_order_partners-partn_numb = '0002112001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_order_partners-partn_numb
IMPORTING
output = gs_order_partners-partn_numb.
APPEND gs_order_partners TO gt_order_partners.
CLEAR gs_order_partners.
***********定价条件
* GS_ORDER_CONDITIONS_IN-ITM_NUMBER = '10'.
* GS_ORDER_CONDITIONS_IN-ITM_NUMBER = '10'.
* GS_ORDER_CONDITIONS_IN-ITM_NUMBER = '10'.
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
EXPORTING
* SALESDOCUMENTIN = SALESDOCUMENTIN
return_header_in = gs_order_header_in
return_header_inx = gs_order_header_inx
* SENDER = SENDER
* BINARY_RELATIONSHIPTYPE = BINARY_RELATIONSHIPTYPE
* INT_NUMBER_ASSIGNMENT = INT_NUMBER_ASSIGNMENT
* BEHAVE_WHEN_ERROR = BEHAVE_WHEN_ERROR
logic_switch = gs_logic_switch
* TESTRUN = TESTRUN
* CONVERT = ' '
IMPORTING
salesdocument = gs_salesdocument
TABLES
return = gt_return
return_items_in = gt_order_items_in
return_items_inx = gt_order_items_inx
return_partners = gt_order_partners
return_schedules_in = gt_order_schedules_in
return_schedules_inx = gt_order_schedules_inx
* order_conditions_in = gt_order_conditions_in
* order_conditions_inx = gt_order_conditions_inx
* ORDER_CFGS_REF = ORDER_CFGS_REF
* ORDER_CFGS_INST = ORDER_CFGS_INST
* ORDER_CFGS_PART_OF = ORDER_CFGS_PART_OF
* ORDER_CFGS_VALUE = ORDER_CFGS_VALUE
* ORDER_CFGS_BLOB = ORDER_CFGS_BLOB
* ORDER_CFGS_VK = ORDER_CFGS_VK
* ORDER_CFGS_REFINST = ORDER_CFGS_REFINST
* ORDER_CCARD = ORDER_CCARD
* ORDER_TEXT = ORDER_TEXT
* ORDER_KEYS = ORDER_KEYS
* EXTENSIONIN = EXTENSIONIN
* PARTNERADDRESSES = PARTNERADDRESSES
* EXTENSIONEX = EXTENSIONEX
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT gt_return INTO gs_return.
WRITE: / gs_return-message.
ENDLOOP.
WRITE:/ gs_salesdocument.
基于销售订单的退货创建VA01
最新推荐文章于 2024-07-08 11:47:07 发布