关于本来要分几步做的接口业务强制要求集成到一步的那些抽象需求
- 已知 该接口要有几次调用中间出错要保存错误消息,不然哪一步出错都不知道。所以要建一个消息表,组件 接口调用的唯一标识 销售订单号 交货单号 过账状态 标记(E/W/S或者整个1-9记录哪一步出错) 消息
点击查看代码
DATA: BEGIN OF ls_zsdt067,
bstkd TYPE zsdt067-bstkd, ”zsdt067要去se11建 bstkd是放唯一标识
vbeln TYPE zsdt067-vbeln,
vbeln_vl TYPE zsdt067-vbeln_vl,
wbstk TYPE zsdt067-wbstk,
type TYPE zsdt067-type,
e_msg TYPE zsdt067-e_msg,
END OF ls_zsdt067.
DATA: lt_zsdt067 LIKE TABLE OF ls_zsdt067,
wa_zsdt067 LIKE LINE OF lt_zsdt067.
2.IT_VBAK 定义一个抬头结构/内标字段
| 销售订单号 | VBELN | VBAK-VBELN |
| 汇总号 | SUBMI | VBAK-SUBMI |
| 订单类型 | AUART | VBAK-AUART |
| 销售组织 | VKORG | VBAK-VKORG |
| 分销渠道 | VTWEG | VBAK-VTWEG |
| 产品组 | SPART | VBAK-SPART |
| 销售办公室 | VKBUR | VBAK-VKBUR |
| 销售组 | VKGRP | VBAK-VKGRP |
| 客户编号 | KUNNR | VBAK-KUNNR |
| 送达方 | KUNWE | VBAK-KUNWE |
| 客户PO | BSTKD | VBKD-BSTKD |
| 客户采购日期 | BSTDK | VBKD-BSTDK |
| 交货日期 | VDATU | VBAK-VDATU |
| 定价日期 | PRSDT | VBKD-PRSDT |
| 装运条件码 | VSBED | VBAK-VSBED |
| 交易货币 | WAERK | VBAK-WAERK |
| 付款条件码 | ZTERM | VBKD-ZTERM |
| 国际贸易条款 | INCO1 | VBKD-INCO1 |
| 国贸条款位置 1 | INCO2_L | VBKD-INCO2_L |
| 运费 | KBETR | PRCD_ELEMENTS-KBETR |
| 折扣(值) | KBETR | PRCD_ELEMENTS-KBETR |
| 订单状态 | ASTTX | ASTTX |
| 销售员 | ZSALEVE | VBPA-LIFNR |
| 销售跟单 | ZSALEZ1 | LFA1-SORTL |
| 销售经理 | ZSALEZ2 | LFA1-SORTL |
| 订单原因 | AUGRU | VBAK-AUGRU |
| 信贷出货标识 | CREDIT | IT_VBAK-CREDIT |
| 客户名称 | NAME1 | ADRC-NAME1 |
| 国家码 | COUNTRY | ADRC-COUNTRY |
| 城市 | CITY1 | ADRC-CITY1 |
| 地区码 | CITYP_CODE | ADRC-CITYP_CODE |
| 邮编 | POST_CODE1 | ADRC-POST_CODE1 |
| 街道地址 | STREET | ADRC-STREET |
| 电话 | TEL_NUMBER | ADRC-TEL_NUMBER |
3.IT_VBAP定义一个行项目结构/内标字段
| 销售订单号 | VBELN | VBAK-VBELN |
| 汇总号 | SUBMI | VBAK-SUBMI |
| 订单类型 | AUART | VBAK-AUART |
| 销售组织 | VKORG | VBAK-VKORG |
| 分销渠道 | VTWEG | VBAK-VTWEG |
| 产品组 | SPART | VBAK-SPART |
| 销售办公室 | VKBUR | VBAK-VKBUR |
| 销售组 | VKGRP | VBAK-VKGRP |
| 客户编号 | KUNNR | VBAK-KUNNR |
| 送达方 | KUNWE | VBAK-KUNWE |
| 客户PO | BSTKD | VBKD-BSTKD |
| 客户采购日期 | BSTDK | VBKD-BSTDK |
| 交货日期 | VDATU | VBAK-VDATU |
| 定价日期 | PRSDT | VBKD-PRSDT |
| 装运条件码 | VSBED | VBAK-VSBED |
| 交易货币 | WAERK | VBAK-WAERK |
| 付款条件码 | ZTERM | VBKD-ZTERM |
| 国际贸易条款 | INCO1 | VBKD-INCO1 |
| 国贸条款位置 1 | INCO2_L | VBKD-INCO2_L |
| 运费 | KBETR | PRCD_ELEMENTS-KBETR |
| 折扣(值) | KBETR | PRCD_ELEMENTS-KBETR |
| 订单状态 | ASTTX | ASTTX |
| 销售员 | ZSALEVE | VBPA-LIFNR |
| 销售跟单 | ZSALEZ1 | LFA1-SORTL |
| 销售经理 | ZSALEZ2 | LFA1-SORTL |
| 订单原因 | AUGRU | VBAK-AUGRU |
| 信贷出货标识 | CREDIT | IT_VBAK-CREDIT |
| 客户名称 | NAME1 | ADRC-NAME1 |
| 国家码 | COUNTRY | ADRC-COUNTRY |
| 城市 | CITY1 | ADRC-CITY1 |
| 地区码 | CITYP_CODE | ADRC-CITYP_CODE |
| 邮编 | POST_CODE1 | ADRC-POST_CODE1 |
| 街道地址 | STREET | ADRC-STREET |
| 电话 | TEL_NUMBER | ADRC-TEL_NUMBER |
| 销售订单号 | VBELN | VBAP-VBELN |
| 项目号 | POSNR | VBAP-POSNR |
| 参考凭证 | VGBEL | VBAP-VGBEL |
| 参考项目 | VGPOS | VBAP-VGPOS |
| 物料编号 | MATNR | VBAP-MATNR |
| 销售数量 | KWMENG | VBAP-KWMENG |
| 销售单位 | VRKME | VBAP-VRKME |
| 价格单位 | KPEIN | PRCD_ELEMENTS-KPEIN |
| 币别 | WAERS | PRCD_ELEMENTS-WAERS |
| 项目类别 | PSTYV | VBAP-PSTYV |
| 交货日期 | EDATU | VBEP-EDATU |
| 交货工厂 | WERKS | VBAP-WERKS |
| 存储地点 | LGORT | VBAP-LGORT |
| 退货批次 | CHARG | VBAP-CHARG |
| 价格类型1 | KSCHL | KONV-KSCHL |
| 交易指导价 | NETPR | VBAP-NETPR |
| 客户折扣% | KBETR3 | PRCD_ELEMENTS-KBETR |
| 拒绝原因 | ABGRU | VBAP-ABGRU |
| 促销折扣V | KBETR4 | PRCD_ELEMENTS-KBETR |
4.前期步骤已完成开敲
点击查看代码
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" VALUE(E_CODE) TYPE MSGTY
*" VALUE(E_MSG) TYPE MSGTXT
*" VALUE(VBELN) TYPE VBELN
*" VALUE(VBELN_VL) TYPE VBELN_VL
*" VALUE(WBSTK) TYPE WBSTK
*" TABLES
*" IT_VBAK STRUCTURE ZSDS_VBAK_067
*" IT_VBAP STRUCTURE ZSDS_VBAP_067
*" IT_TEXT STRUCTURE BAPISDTEXT
*"----------------------------------------------------------------------
*//
*// _oo8oo_
*// o8888888o
*// 88" . "88
*// (| -_- |)
*// 0\ = /0
*// ___/'==='\___
*// .' \\| |// '.
*// / \\||| : |||// \
*// / _||||| -:- |||||_ \
*// | | \\\ - /// | |
*// | \_| ''\---/'' |_/ |
*// \ .-\__ '-' __/-. /
*// ___'. .' /--.--\ '. .'___
*// ."" '< '.___\_<|>_/___.' >' "".
*// | | : `- \`.:`\ _ /`:.`/ -` : | |
*// \ \ `-. \_ __\ /__ _/ .-` / /
*// =====`-.____`.___ \_____/ ___.`____.-`=====
*// `=---=`
*//
*//
*//
*// 佛祖保佑 永无bug
*本地接口:
*dyxlin
*接口函数: ***
*接口功能:创建销售订单&交货单过帐
*接口方向:**->SAP
*"----------------------------------------------------------------------
zmac-rfc-log-b. "日志记录开始,函数进入时写
*** BAPI 參數
DATA: salesdocumentin TYPE bapivbeln-vbeln,
salesdocument TYPE bapivbeln-vbeln,
order_header_in TYPE bapisdhd1,
order_header_inx TYPE bapisdhd1x,
order_header_in2 TYPE bapisdh1,
order_header_inx2 TYPE bapisdh1x,
wa_logic_switch TYPE bapisdls.
***增加信贷标识字段
DATA:lt_vbfa TYPE TABLE OF vbfa,
wa_vbfa LIKE LINE OF lt_vbfa.
DATA: "增加成本中心字段
ls_extension TYPE bapiparex,
lt_extension TYPE TABLE OF bapiparex,
lt_extensionx TYPE TABLE OF bapiparex.
DATA lv_c TYPE c.
DATA lv_b TYPE c.
DATA: ls_bape_vbak TYPE bape_vbak,
ls_bape_vbakx TYPE bape_vbakx.
*ZSDT067
DATA: lt_zsdt067 LIKE TABLE OF zsdt067,
wa_zsdt067 LIKE LINE OF lt_zsdt067.
DATA: sd_return LIKE TABLE OF bapiret2 WITH HEADER LINE,
order_items_in LIKE TABLE OF bapisditm WITH HEADER LINE,
order_items_inx LIKE TABLE OF bapisditmx WITH HEADER LINE,
order_partners LIKE TABLE OF bapiparnr WITH HEADER LINE,
order_schedules_in LIKE TABLE OF bapischdl WITH HEADER LINE,
order_schedules_inx LIKE TABLE OF bapischdlx WITH HEADER LINE,
order_conditions_in LIKE TABLE OF bapicond WITH HEADER LINE,
order_conditions_inx LIKE TABLE OF bapicondx WITH HEADER LINE,
order_text LIKE TABLE OF bapisdtext WITH HEADER LINE,
order_partneraddresses LIKE TABLE OF bapiaddr1 WITH HEADER LINE.
RANGES: lr_kschl FOR konv-kschl.
DATA: lc_subrc TYPE sy-subrc,
lc_flag TYPE c,
lv_vbeln TYPE vbak-vbeln,
lv_value TYPE string,
msgtx TYPE string,
bapi_msg TYPE string.
DATA: wa_vbak LIKE LINE OF it_vbak,
wa_vbap LIKE LINE OF it_vbap.
DATA: lt_vbak LIKE TABLE OF vbak,
ws_vbak LIKE LINE OF lt_vbak,
lt_vbap LIKE TABLE OF vbap,
ws_vbap LIKE LINE OF lt_vbap,
lt_lips LIKE TABLE OF lips,
ws_lips LIKE LINE OF lt_lips.
DATA: lw_vbak TYPE vbak,
lw_vbap TYPE vbap,
lw_tvak TYPE tvak,
lw_tvko TYPE tvko,
lw_tvtw TYPE tvtw,
lw_tvkov TYPE tvkov,
lw_tvakz TYPE tvakz,
lw_kna1 TYPE kna1,
lw_knvv TYPE knvv,
lw_tvau TYPE tvau,
lw_tvaut TYPE tvaut,
lw_mara TYPE mara,
lw_makt TYPE makt,
lw_mvke TYPE mvke,
lw_marc TYPE marc,
lw_t683v TYPE t683v,
lw_tcurc TYPE tcurc,
lw_lfa1 TYPE lfa1.
DATA: ktokd TYPE kna1-ktokd,
updkz TYPE updkz,
item_msg TYPE msgtxt.
DATA: i_kalsm TYPE t683v-kalsm,
i_kalvg TYPE tvak-kalvg,
i_kalks TYPE knvv-kalks,
i_kzwi1 TYPE p DECIMALS 2,
i_kzwi2 TYPE p DECIMALS 3,
i_stat TYPE j_status,
i_objnr TYPE vbak-objnr.
*** 创建交货单要的参数
DATA: ship_point TYPE tvst-vstel, "装运点/接收点
num_deliveries TYPE vbnum, "创建的凭证数
lt_trans_items LIKE bapidlvreftosalesorder OCCURS 0 WITH HEADER LINE, "传输交货单对应的item
deliveries TYPE STANDARD TABLE OF bapishpdelivnumb, "交货号
extension_out TYPE STANDARD TABLE OF bapiparex, "BAPI 参数 ExtensionIn/ExtensionOut 的参考结构
lt_created_items LIKE TABLE OF bapidlvitemcreated, "发送个bapi生产DN的主要数据
ls_created_items LIKE bapidlvitemcreated,
serial_numbers LIKE bapidlvserialnumber OCCURS 0 WITH HEADER LINE , "序列号
lt_return1 TYPE STANDARD TABLE OF bapiret2, "返回参数
lf_vbeln TYPE vbeln_vl. "生成交货单号后返回的凭证
DATA: BEGIN OF ls_ship_point,
ship_point TYPE tvst-vstel,
END OF ls_ship_point.
DATA:lt_ship_point LIKE TABLE OF ls_ship_point,
wa_ship_point LIKE LINE OF lt_ship_point.
*** 拣配要的参数
DATA:lv_str TYPE string,
ls_vbkok TYPE vbkok,
lt_vbpok TYPE TABLE OF vbpok,
lt_prot TYPE TABLE OF prott.
*** 过账要的参数
DATA: i_header_data TYPE bapiobdlvhdrcon,
i_header_control TYPE bapiobdlvhdrctrlcon,
ls_header_deadlines TYPE bapidlvdeadln,
lt_header_deadlines TYPE TABLE OF bapidlvdeadln.
DATA: lw_return TYPE bapiret2,
lt_return3 TYPE TABLE OF bapiret2.
***
DATA: BEGIN OF it_t683s OCCURS 0.
INCLUDE STRUCTURE t683s.
DATA: vtext LIKE t683t-vtext,
END OF it_t683s.
DATA:ls_ztsd041 TYPE ztsd041.
REFRESH: it_t683s. " 取定价过程配置表
SELECT *
INTO TABLE it_t683s
FROM t683s
WHERE t683s~kvewe = 'A'
AND t683s~kappl = 'V'.
LOOP AT it_t683s.
SELECT SINGLE vtext INTO it_t683s-vtext FROM t683t WHERE spras = '1' AND kvewe = it_t683s-kvewe
AND kappl = it_t683s-kappl AND kalsm = it_t683s-kalsm AND stunr = it_t683s-stunr AND zaehk = it_t683s-zaehk.
IF sy-subrc NE 0.
SELECT SINGLE vtext INTO it_t683s-vtext FROM t685t WHERE spras = '1' AND kvewe = it_t683s-kvewe
AND kappl = it_t683s-kappl AND kschl = it_t683s-kschl.
ENDIF.
MODIFY it_t683s TRANSPORTING vtext.
ENDLOOP.
LOOP AT it_vbak INTO wa_vbak.
CLEAR: e_code,e_msg,ktokd,updkz.
CLEAR: i_kalsm,i_kalvg,i_kalks.
updkz = 'I'. " 默认创建销售订单
IF wa_vbak-vbeln IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_vbak-vbeln
IMPORTING
output = wa_vbak-vbeln.
CLEAR lw_vbak.
SELECT SINGLE * INTO lw_vbak FROM vbak WHERE vbeln = wa_vbak-vbeln.
IF sy-subrc EQ 0.
updkz = 'U'. " 修改销售订单
wa_vbak-auart = lw_vbak-auart.
ELSE.
e_code = 'E'.
CONCATENATE '销售订单' wa_vbak-vbeln '不存在!' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-bstkd IS INITIAL.
e_code = 'E'.
* CONCATENATE '请输入 出库单号/案例编号' INTO e_msg SEPARATED BY ''.
e_msg = '请输入 出库单号/案例编号'.
EXIT.
ENDIF.
IF wa_vbak-auart IS INITIAL.
e_code = 'E'.
e_msg = '请输入 订单类型'.
EXIT.
ELSE.
CLEAR lw_tvak.
SELECT SINGLE * INTO lw_tvak FROM tvak WHERE auart = wa_vbak-auart.
IF sy-subrc NE 0.
e_code = 'E'.
CONCATENATE '订单类型' wa_vbak-auart '不存在!' INTO e_msg SEPARATED BY ''.
EXIT.
ELSE.
i_kalvg = lw_tvak-kalvg.
ENDIF.
ENDIF.
IF wa_vbak-vkorg IS INITIAL.
e_code = 'E'.
e_msg = '请输入 销售组织'.
EXIT.
ELSE.
CLEAR lw_tvko.
SELECT SINGLE * INTO lw_tvko FROM tvko WHERE vkorg = wa_vbak-vkorg.
IF sy-subrc NE 0.
e_code = 'E'.
CONCATENATE '销售组织' wa_vbak-vkorg '不存在!' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-vtweg IS INITIAL.
e_code = 'E'.
e_msg = '请输入 分销渠道'.
EXIT.
ELSE.
CLEAR lw_tvtw.
SELECT SINGLE * INTO lw_tvtw FROM tvtw WHERE vtweg = wa_vbak-vtweg.
IF sy-subrc EQ 0.
CLEAR lw_tvkov.
SELECT SINGLE * INTO lw_tvkov FROM tvkov WHERE vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg.
IF sy-subrc NE 0.
e_code = 'E'.
CONCATENATE '销售组织' wa_vbak-vkorg ',不允许分销渠道' wa_vbak-vtweg INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ELSE.
e_code = 'E'.
CONCATENATE '分销渠道' wa_vbak-vtweg '不存在!' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-spart IS INITIAL.
wa_vbak-spart = '00'.
ENDIF.
IF wa_vbak-vkbur IS INITIAL.
e_code = 'E'.
e_msg = '请输入 销售办公室'.
EXIT.
ENDIF.
IF wa_vbak-vkgrp IS INITIAL.
e_code = 'E'.
e_msg = '请输入 销售组'.
EXIT.
ENDIF.
IF wa_vbak-kunnr IS INITIAL.
e_code = 'E'.
e_msg = '请输入 客户编码'.
EXIT.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_vbak-kunnr
IMPORTING
output = wa_vbak-kunnr.
CLEAR lw_kna1.
SELECT SINGLE * INTO lw_kna1 FROM kna1 WHERE kunnr = wa_vbak-kunnr.
IF sy-subrc EQ 0.
ktokd = lw_kna1-ktokd.
CLEAR lw_knvv.
SELECT SINGLE * INTO lw_knvv FROM knvv WHERE kunnr = wa_vbak-kunnr AND vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg AND spart = wa_vbak-spart.
IF sy-subrc NE 0.
e_code = 'E'.
CONCATENATE '客户编码' wa_vbak-kunnr '未针对销售区域' wa_vbak-vkorg wa_vbak-vtweg wa_vbak-spart '加以维护' INTO e_msg SEPARATED BY ''.
EXIT.
ELSE.
i_kalks = lw_knvv-kalks.
ENDIF.
ELSE.
e_code = 'E'.
CONCATENATE '客户编码' wa_vbak-kunnr '不存在!' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-kunwe IS INITIAL.
e_code = 'E'.
e_msg = '请输入 送达方'.
EXIT.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_vbak-kunwe
IMPORTING
output = wa_vbak-kunwe.
CLEAR lw_kna1.
SELECT SINGLE * INTO lw_kna1 FROM kna1 WHERE kunnr = wa_vbak-kunwe.
IF sy-subrc EQ 0.
CLEAR lw_knvv.
SELECT SINGLE * INTO lw_knvv FROM knvv WHERE kunnr = wa_vbak-kunwe AND vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg AND spart = wa_vbak-spart.
IF sy-subrc NE 0.
e_code = 'E'.
CONCATENATE '送达方' wa_vbak-kunwe '未针对销售区域' wa_vbak-vkorg wa_vbak-vtweg wa_vbak-spart '加以维护' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ELSE.
e_code = 'E'.
CONCATENATE '送达方' wa_vbak-kunwe '不存在!' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-bstkd IS INITIAL.
e_code = 'E'.
e_msg = '请输入 客户PO'.
EXIT.
ELSE.
SELECT SINGLE * FROM zsdt067 INTO @wa_zsdt067 WHERE bstkd = @wa_vbak-bstkd.
IF wa_zsdt067-vbeln IS NOT INITIAL.
e_code = 'E'.
e_msg = '客户PO' && wa_vbak-bstkd && '已建立单号' && wa_zsdt067-vbeln.
CLEAR wa_zsdt067.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-bstdk IS INITIAL.
e_code = 'E'.
e_msg = '请输入 客户采购日期'.
EXIT.
ENDIF.
IF wa_vbak-vdatu IS INITIAL.
e_code = 'E'.
e_msg = '请输入 要求交货日期'.
EXIT.
ELSE.
IF wa_vbak-vdatu < sy-datum AND wa_vbak-vbeln IS INITIAL.
e_code = 'E'.
CONCATENATE '交货日期' wa_vbak-vdatu '在过去,不能满足交货' INTO e_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-prsdt IS INITIAL.
e_code = 'E'.
e_msg = '请输入 定价日期'.
EXIT.
ENDIF.
* IF wa_vbak-vsbed IS INITIAL.
* e_code = 'E'.
* e_msg = '请输入 装运条件'.
* EXIT.
* ENDIF.
* IF wa_vbak-waerk IS INITIAL.
* e_code = 'E'.
* e_msg = '请输入 交易货币'.
* EXIT.
* ELSE.
* CLEAR lw_tcurc.
* SELECT SINGLE * INTO lw_tcurc FROM tcurc WHERE waers = wa_vbak-waerk.
* IF sy-subrc NE 0.
* e_code = 'E'.
* CONCATENATE '交易货币' wa_vbak-waerk '不存在!' INTO e_msg SEPARATED BY ''.
* EXIT.
* ENDIF.
* ENDIF.
* IF wa_vbak-zterm IS INITIAL.
* e_code = 'E'.
* e_msg = '请输入 付款条件码'.
* EXIT.
* ENDIF.
* IF wa_vbak-asttx IS INITIAL.
* wa_vbak-asttx = 'Z10'. " 订单抬头未审批状态
* ENDIF.
IF ktokd = 'Z010'. " 一次性客户
IF wa_vbak-name1 IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 客户名称'.
EXIT.
ENDIF.
IF wa_vbak-platform = ''.
IF wa_vbak-country IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 国家码'.
EXIT.
ENDIF.
IF wa_vbak-city1 IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 城市'.
EXIT.
ENDIF.
IF wa_vbak-cityp_code IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 地区码'.
EXIT.
ENDIF.
IF wa_vbak-post_code1 IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 邮编'.
EXIT.
ENDIF.
IF wa_vbak-street IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 街道地址'.
EXIT.
ENDIF.
IF wa_vbak-tel_number IS INITIAL.
e_code = 'E'.
e_msg = '一次性客户 请输入 电话'.
EXIT.
ENDIF.
ENDIF.
ENDIF.
CLEAR lw_t683v.
SELECT SINGLE * INTO lw_t683v FROM t683v WHERE vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg AND spart = wa_vbak-spart AND kalvg = i_kalvg AND kalks = i_kalks.
IF sy-subrc EQ 0.
i_kalsm = lw_t683v-kalsm.
ENDIF.
CLEAR item_msg.
LOOP AT it_vbap INTO wa_vbap.
CLEAR lw_vbap.
IF wa_vbap-posnr IS INITIAL.
item_msg = '请输入 项目号'.
EXIT.
ENDIF.
IF updkz = 'I'.
IF wa_vbap-vbeln IS NOT INITIAL.
item_msg = '创建销售订单 项目表销售订单号必须为空'.
EXIT.
ENDIF.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_vbap-vbeln
IMPORTING
output = wa_vbap-vbeln.
IF wa_vbak-vbeln <> wa_vbap-vbeln.
CONCATENATE '抬头销售订单' wa_vbak-vbeln '与项目销售订单' wa_vbap-vbeln '不一致' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
SELECT SINGLE * INTO lw_vbap FROM vbap WHERE vbeln = wa_vbap-vbeln AND posnr = wa_vbap-posnr.
IF sy-subrc NE 0.
CONCATENATE '销售订单' wa_vbap-vbeln '项目' wa_vbap-posnr '不存在!' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbap-matnr IS INITIAL.
CONCATENATE '项目' wa_vbap-posnr '请输入 物料编号' INTO item_msg SEPARATED BY ''.
EXIT.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = wa_vbap-matnr
IMPORTING
output = wa_vbap-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
CLEAR lw_mara.
SELECT SINGLE * INTO lw_mara FROM mara WHERE matnr = wa_vbap-matnr.
IF sy-subrc NE 0.
CONCATENATE '项目' wa_vbap-posnr '物料编号' wa_vbap-matnr '不存在' INTO item_msg SEPARATED BY ''.
EXIT.
ELSE.
CLEAR lw_mvke.
SELECT SINGLE * INTO lw_mvke FROM mvke WHERE matnr = wa_vbap-matnr AND vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg.
IF sy-subrc NE 0.
CONCATENATE '项目' wa_vbap-posnr '物料编号' wa_vbap-matnr '未对销售组织' wa_vbak-vkorg '分销渠道' wa_vbak-vtweg '定义' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
ENDIF.
IF wa_vbap-kwmeng <= 0.
CONCATENATE '项目' wa_vbap-posnr '请输入 销售数量' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-vrkme IS INITIAL.
CONCATENATE '项目' wa_vbap-posnr '请输入 销售单位' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-kpein IS INITIAL.
CONCATENATE '项目' wa_vbap-posnr '请输入 价格单位' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-pstyv IS INITIAL.
CONCATENATE '项目' wa_vbap-posnr '请输入 项目类别' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-edatu IS INITIAL.
CONCATENATE '项目' wa_vbap-posnr '请输入 交货日期' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-werks IS INITIAL.
CONCATENATE '项目' wa_vbap-posnr '请输入 交货工厂' INTO item_msg SEPARATED BY ''.
EXIT.
ELSE.
CLEAR lw_marc.
SELECT SINGLE * INTO lw_marc FROM marc WHERE matnr = wa_vbap-matnr AND werks = wa_vbap-werks.
IF sy-subrc NE 0.
CONCATENATE '项目' wa_vbap-posnr '物料编号' wa_vbap-matnr '在工厂' wa_vbap-werks '不存在' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
IF wa_vbak-auart = 'ZFD' OR wa_vbak-auart = 'ZSD'. "增加ZSD的订单类型
ELSE.
IF wa_vbap-netpr IS INITIAL AND ( wa_vbak-auart NE 'ZKB' AND wa_vbak-auart NE 'ZBH' ). "增加备货需求订单类型不检查交易指导价
IF wa_vbak-auart EQ 'ZRE' AND wa_vbap-pstyv EQ 'RENN'.
ELSE.
CONCATENATE '项目' wa_vbap-posnr '请输入 交易指导价' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
ENDIF.
ENDIF.
IF wa_vbak-auart EQ 'ZRE'.
IF wa_vbap-vgbel IS INITIAL AND wa_vbak-auart EQ 'ZRE'.
CONCATENATE '项目' wa_vbap-posnr '请输入 参考凭证' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-vgpos IS INITIAL AND wa_vbak-auart EQ 'ZRE'.
CONCATENATE '项目' wa_vbap-posnr '请输入 参考项目' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
IF wa_vbap-lgort IS INITIAL AND wa_vbak-auart EQ 'ZRE'.
CONCATENATE '项目' wa_vbap-posnr '请输入 存储地点' INTO item_msg SEPARATED BY ''.
EXIT.
ENDIF.
* IF wa_vbap-charg IS INITIAL AND wa_vbak-auart EQ 'ZRE'.
* CONCATENATE '项目' wa_vbap-posnr '请输入 退货批次' INTO item_msg SEPARATED BY ''.
* EXIT.
* ENDIF.
ENDIF.
ENDLOOP.
IF item_msg IS NOT INITIAL.
e_code = 'E'.
e_msg = item_msg.
EXIT.
ENDIF.
IF wa_vbak-auart EQ 'ZRE'.
SELECT mseg~matnr, mseg~charg FROM mseg FOR ALL ENTRIES IN @it_vbap WHERE mseg~kunnr EQ @wa_vbak-kunnr AND mseg~bwart = '601' AND mseg~matnr EQ @it_vbap-matnr INTO TABLE @DATA(lt_mseg).
SORT lt_mseg BY matnr.
ENDIF.
IF e_code IS INITIAL.
CLEAR: salesdocumentin,salesdocument,order_header_in,order_header_inx,order_header_in2,order_header_inx2,wa_logic_switch.
REFRESH: sd_return,order_items_in,order_items_inx,order_partners,order_schedules_in,order_schedules_inx,
order_conditions_in,order_conditions_inx,order_text,order_partneraddresses.
order_text[] = it_text[].
order_header_inx-updateflag = updkz.
order_header_in-doc_type = wa_vbak-auart.
order_header_inx-doc_type = 'X'.
order_header_in-sales_org = wa_vbak-vkorg.
order_header_inx-sales_org = 'X'.
order_header_in-distr_chan = wa_vbak-vtweg.
order_header_inx-distr_chan = 'X'.
order_header_in-division = wa_vbak-spart.
order_header_inx-division = 'X'.
CLEAR lw_tvak.
SELECT SINGLE * INTO lw_tvak FROM tvak WHERE auart = wa_vbak-auart.
order_header_in-sd_doc_cat = lw_tvak-vbtyp.
order_header_inx-sd_doc_cat = 'X'.
order_header_in-sales_off = wa_vbak-vkbur.
order_header_inx-sales_off = 'X'.
order_header_in-sales_grp = wa_vbak-vkgrp.
order_header_inx-sales_grp = 'X'.
order_header_in-purch_no_c = wa_vbak-bstkd.
order_header_inx-purch_no_c = 'X'.
IF wa_vbak-bstdk IS NOT INITIAL.
order_header_in-purch_date = wa_vbak-bstdk.
order_header_inx-purch_date = 'X'.
ENDIF.
order_header_in-req_date_h = wa_vbak-vdatu.
order_header_inx-req_date_h = 'X'.
order_header_in-price_date = wa_vbak-prsdt.
order_header_inx-price_date = 'X'.
IF wa_vbak-vsbed IS NOT INITIAL.
order_header_in-ship_cond = wa_vbak-vsbed.
order_header_inx-ship_cond = 'X'.
ENDIF.
IF wa_vbak-waerk IS INITIAL .
SELECT SINGLE knvv~waers FROM knvv INTO wa_vbak-waerk WHERE kunnr = wa_vbak-kunnr AND vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg.
ENDIF.
order_header_in-currency = wa_vbak-waerk.
order_header_inx-currency = 'X'.
IF wa_vbak-zterm IS NOT INITIAL.
order_header_in-pmnttrms = wa_vbak-zterm.
order_header_inx-pmnttrms = 'X'.
ENDIF.
IF wa_vbak-inco1 IS NOT INITIAL.
order_header_in-incoterms1 = wa_vbak-inco1.
order_header_inx-incoterms1 = 'X'.
ENDIF.
IF wa_vbak-inco2_l IS NOT INITIAL.
order_header_in-incoterms2l = wa_vbak-inco2_l.
order_header_inx-incoterms2l = 'X'.
ENDIF.
IF wa_vbak-augru IS NOT INITIAL.
order_header_in-ord_reason = wa_vbak-augru.
order_header_inx-ord_reason = 'X'.
ENDIF.
order_header_in-collect_no = wa_vbak-submi.
order_header_inx-collect_no = 'X'.
MOVE-CORRESPONDING order_header_in TO order_header_in2.
MOVE-CORRESPONDING order_header_inx TO order_header_inx2.
CLEAR lw_kna1.
SELECT SINGLE * INTO lw_kna1 FROM kna1 WHERE kunnr = wa_vbak-kunnr.
CLEAR order_partners.
order_partners-partn_role = 'AG'.
order_partners-partn_numb = wa_vbak-kunnr.
IF wa_vbak-name1 IS NOT INITIAL.
order_partners-name = wa_vbak-name1.
order_partners-country = wa_vbak-country.
order_partners-city = wa_vbak-city1.
order_partners-region = wa_vbak-cityp_code.
order_partners-postl_code = wa_vbak-post_code1.
order_partners-street = wa_vbak-street.
order_partners-telephone = wa_vbak-tel_number.
order_partners-langu = lw_kna1-spras.
ENDIF.
APPEND order_partners.
IF wa_vbak-kunwe IS NOT INITIAL.
CLEAR order_partners.
order_partners-partn_role = 'WE'.
order_partners-partn_numb = wa_vbak-kunnr.
APPEND order_partners.
ENDIF.
IF wa_vbak-zsaleve IS NOT INITIAL.
CLEAR order_partners.
order_partners-partn_role = 'VE'.
order_partners-partn_numb = wa_vbak-zsaleve.
APPEND order_partners.
ENDIF.
IF wa_vbak-zsalez1 IS NOT INITIAL.
CLEAR order_partners.
order_partners-partn_role = 'Z1'.
order_partners-partn_numb = wa_vbak-zsalez1.
APPEND order_partners.
ENDIF.
IF wa_vbak-zsalez2 IS NOT INITIAL.
CLEAR order_partners.
order_partners-partn_role = 'Z2'.
order_partners-partn_numb = wa_vbak-zsalez2.
APPEND order_partners.
ENDIF.
LOOP AT it_vbap INTO wa_vbap.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = wa_vbap-matnr
IMPORTING
output = wa_vbap-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = wa_vbap-vrkme
IMPORTING
output = wa_vbap-vrkme
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
CLEAR: order_items_in,order_items_inx.
order_items_in-itm_number = wa_vbap-posnr.
order_items_inx-itm_number = wa_vbap-posnr.
order_items_inx-updateflag = updkz.
order_items_in-material = wa_vbap-matnr.
order_items_inx-material = 'X'.
IF wa_vbap-arktx IS NOT INITIAL.
order_items_in-short_text = wa_vbap-arktx.
order_items_inx-short_text = 'X'.
ENDIF.
IF lv_c NE 'X'.
order_items_in-plant = wa_vbap-werks.
order_items_inx-plant = 'X'.
ENDIF.
IF wa_vbap-pstyv IS NOT INITIAL.
order_items_in-item_categ = wa_vbap-pstyv.
order_items_inx-item_categ = 'X'.
ENDIF.
IF wa_vbap-kdmat IS NOT INITIAL.
order_items_in-cust_mat35 = wa_vbap-kdmat.
order_items_inx-cust_mat35 = 'X'.
ENDIF.
IF wa_vbap-abgru IS NOT INITIAL.
order_items_in-reason_rej = wa_vbap-abgru.
order_items_inx-reason_rej = 'X'.
ENDIF.
IF lw_tvak-lfarv IS NOT INITIAL OR wa_vbak-auart = 'ZBH'. "备货的订单创建需要传计划行数据
CLEAR: order_schedules_in,order_schedules_inx.
order_schedules_in-itm_number = wa_vbap-posnr.
order_schedules_inx-itm_number = wa_vbap-posnr.
order_schedules_in-sched_line = '0001'.
order_schedules_inx-sched_line = '0001'.
order_schedules_inx-updateflag = updkz.
*** 控制计划行日期
IF lv_c NE 'X'.
order_schedules_in-req_date = wa_vbap-edatu.
order_schedules_inx-req_date = 'X'.
ENDIF.
***
order_schedules_in-req_qty = wa_vbap-kwmeng.
order_schedules_inx-req_qty = 'X'.
APPEND order_schedules_in.
APPEND order_schedules_inx.
ENDIF.
IF lw_tvak-vbtyp = 'K' OR lw_tvak-vbtyp = 'L'.
IF wa_vbap-kwmeng > 0.
order_items_in-target_qty = wa_vbap-kwmeng.
order_items_inx-target_qty = 'X'.
ENDIF.
IF wa_vbap-vrkme IS NOT INITIAL.
order_items_in-target_qu = wa_vbap-vrkme.
order_items_inx-target_qu = 'X'.
ENDIF.
ENDIF.
IF wa_vbap-vrkme IS NOT INITIAL.
order_items_in-sales_unit = wa_vbap-vrkme.
order_items_inx-sales_unit = 'X'.
ENDIF.
IF wa_vbap-vgbel IS NOT INITIAL AND wa_vbak-auart EQ 'ZRE'.
order_items_in-ref_doc = wa_vbap-vgbel.
order_items_inx-ref_doc = 'X'.
ENDIF.
IF wa_vbap-vgpos IS NOT INITIAL AND wa_vbak-auart EQ 'ZRE'.
order_items_in-ref_doc_it = wa_vbap-vgpos.
order_items_inx-ref_doc_it = 'X'.
ENDIF.
IF wa_vbap-lgort IS NOT INITIAL AND wa_vbak-auart EQ 'ZRE'.
order_items_in-store_loc = wa_vbap-lgort.
order_items_inx-store_loc = 'X'.
ENDIF.
IF wa_vbap-charg IS NOT INITIAL AND wa_vbak-auart EQ 'ZRE'.
order_items_in-batch = wa_vbap-charg.
order_items_inx-batch = 'X'.
ENDIF.
IF wa_vbap-charg IS INITIAL AND wa_vbak-auart EQ 'ZRE'.
READ TABLE lt_mseg INTO DATA(wa_mseg) WITH KEY matnr = wa_vbap-matnr BINARY SEARCH.
IF sy-subrc EQ 0.
order_items_in-batch = wa_mseg-charg.
order_items_inx-batch = 'X'.
ENDIF.
ENDIF.
APPEND order_items_in.
APPEND order_items_inx.
IF i_kalks EQ '1' .
wa_vbap-kschl = 'YPR1'.
ELSE.
wa_vbap-kschl = 'ZPR1'.
ENDIF.
IF wa_vbap-kschl IS NOT INITIAL and wa_vbak-auart ne 'ZSD' .
READ TABLE it_t683s WITH KEY kalsm = i_kalsm kschl = wa_vbap-kschl.
CLEAR order_conditions_in.
order_conditions_in-itm_number = wa_vbap-posnr.
order_conditions_in-cond_st_no = it_t683s-stunr.
order_conditions_in-cond_count = 1.
order_conditions_in-cond_type = wa_vbap-kschl.
order_conditions_in-cond_value = wa_vbap-netpr.
order_conditions_in-cond_p_unt = wa_vbap-kpein.
order_conditions_in-cond_unit = wa_vbap-vrkme.
IF wa_vbap-waers IS INITIAL .
SELECT SINGLE knvv~waers FROM knvv INTO wa_vbap-waers WHERE kunnr = wa_vbak-kunnr AND vkorg = wa_vbak-vkorg AND vtweg = wa_vbak-vtweg.
ENDIF.
order_conditions_in-currency = wa_vbap-waers.
order_conditions_in-cond_updat = 'X'.
order_conditions_in-condchaman = 'X'.
APPEND order_conditions_in.
CLEAR order_conditions_inx.
order_conditions_inx-itm_number = wa_vbap-posnr.
order_conditions_inx-cond_st_no = it_t683s-stunr.
order_conditions_inx-cond_count = 1.
order_conditions_inx-cond_type = wa_vbap-kschl.
order_conditions_inx-updateflag = 'U'.
order_conditions_inx-cond_value = 'X'.
order_conditions_inx-cond_p_unt = 'X'.
order_conditions_inx-cond_unit = 'X'.
order_conditions_inx-currency = 'X'.
APPEND order_conditions_inx.
ENDIF.
ENDLOOP.
IF wa_vbak-yk33_kbetr IS NOT INITIAL.
REFRESH: lr_kschl.
APPEND 'IEQYK33' TO lr_kschl.
APPEND 'IEQZK33' TO lr_kschl.
CLEAR i_kzwi1.
i_kzwi1 = wa_vbak-yk33_kbetr.
LOOP AT it_t683s WHERE kalsm = i_kalsm AND kschl IN lr_kschl.
CLEAR order_conditions_in.
order_conditions_in-itm_number = '000000'.
order_conditions_in-cond_type = it_t683s-kschl.
order_conditions_in-cond_value = i_kzwi1.
order_conditions_in-currency = wa_vbak-waerk.
* order_conditions_in-cond_updat = COND #( WHEN updkz = 'U' THEN 'X' ELSE '' ).
APPEND order_conditions_in.
CLEAR order_conditions_inx.
order_conditions_inx-itm_number = '000000'.
order_conditions_inx-cond_type = it_t683s-kschl.
order_conditions_inx-cond_value = 'X'.
order_conditions_inx-currency = 'X'.
order_conditions_inx-updateflag = COND #( WHEN updkz = 'U' THEN updkz ELSE '' ).
APPEND order_conditions_inx.
EXIT.
ENDLOOP.
ENDIF.
IF wa_vbak-hb00_kbetr IS NOT INITIAL.
REFRESH: lr_kschl.
APPEND 'IEQHB00' TO lr_kschl.
CLEAR i_kzwi1.
i_kzwi1 = wa_vbak-hb00_kbetr.
LOOP AT it_t683s WHERE kalsm = i_kalsm AND kschl IN lr_kschl.
CLEAR order_conditions_in.
order_conditions_in-itm_number = '000000'.
order_conditions_in-cond_type = it_t683s-kschl.
order_conditions_in-cond_value = i_kzwi1.
order_conditions_in-currency = wa_vbak-waerk.
* order_conditions_in-cond_updat = COND #( WHEN updkz = 'U' THEN 'X' ELSE '' ).
APPEND order_conditions_in.
CLEAR order_conditions_inx.
order_conditions_inx-itm_number = '000000'.
order_conditions_inx-cond_type = it_t683s-kschl.
order_conditions_inx-cond_value = 'X'.
order_conditions_inx-currency = 'X'.
order_conditions_inx-updateflag = COND #( WHEN updkz = 'U' THEN updkz ELSE '' ).
APPEND order_conditions_inx.
EXIT.
ENDLOOP.
ENDIF.
lc_flag = 'N'.
IF wa_vbak-auart EQ 'ZRE'. " 退货订单
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
EXPORTING
return_header_in = order_header_in
return_header_inx = order_header_inx
int_number_assignment = 'X'
logic_switch = wa_logic_switch
IMPORTING
salesdocument = salesdocument
TABLES
return = sd_return
return_items_in = order_items_in
return_items_inx = order_items_inx
return_partners = order_partners
return_schedules_in = order_schedules_in
return_schedules_inx = order_schedules_inx
return_conditions_in = order_conditions_in
return_text = order_text
partneraddresses = order_partneraddresses.
lc_subrc = sy-subrc.
ELSEIF lw_tvak-vbtyp = 'K' OR lw_tvak-vbtyp = 'L'. " 贷项订单 借项订单
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in = order_header_in
sales_header_inx = order_header_inx
int_number_assignment = 'X'
logic_switch = wa_logic_switch
IMPORTING
salesdocument_ex = salesdocument
TABLES
return = sd_return
sales_items_in = order_items_in
sales_items_inx = order_items_inx
sales_partners = order_partners
sales_conditions_in = order_conditions_in
sales_conditions_inx = order_conditions_inx
sales_text = order_text.
lc_subrc = sy-subrc.
ELSEIF lw_tvak-vbtyp = 'C' OR lw_tvak-vbtyp = 'I'. " 标准订单 不含费用的订单
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
salesdocumentin = salesdocumentin
order_header_in = order_header_in
order_header_inx = order_header_inx
int_number_assignment = 'X'
logic_switch = wa_logic_switch
IMPORTING
salesdocument = salesdocument
TABLES
return = sd_return
order_items_in = order_items_in
order_items_inx = order_items_inx
order_partners = order_partners
order_schedules_in = order_schedules_in
order_schedules_inx = order_schedules_inx
order_conditions_in = order_conditions_in
order_conditions_inx = order_conditions_inx
order_text = order_text
extensionin = lt_extension "增加成本中心字段
" extensionex = lt_extensionx "增加成本中心字段
partneraddresses = order_partneraddresses.
lc_subrc = sy-subrc.
ENDIF.
IF lc_subrc EQ 0.
READ TABLE sd_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
READ TABLE sd_return WITH KEY type = 'A'.
IF sy-subrc NE 0.
READ TABLE sd_return WITH KEY type = 'S'.
IF sy-subrc EQ 0.
lc_flag = 'Y'.
ELSE.
IF salesdocument IS NOT INITIAL.
lc_flag = 'Y'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR bapi_msg.
IF lc_flag = 'N'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
IF updkz = 'I'.
bapi_msg = '创建销售订单失败!'.
ELSEIF updkz = 'U'.
bapi_msg = '更改销售订单失败!'.
ENDIF.
IF lines( sd_return ) GT 0.
LOOP AT sd_return WHERE type = 'E' OR type = 'A'.
CLEAR msgtx.
MESSAGE ID sd_return-id TYPE sd_return-type NUMBER sd_return-number
WITH sd_return-message_v1 sd_return-message_v2
sd_return-message_v3 sd_return-message_v4
INTO msgtx.
CONCATENATE bapi_msg msgtx INTO bapi_msg SEPARATED BY ''.
ENDLOOP.
ELSE.
CLEAR msgtx.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO msgtx.
CONCATENATE bapi_msg msgtx INTO bapi_msg SEPARATED BY ''.
ENDIF.
e_code = 'E'.
e_msg = '销售订单创建失败' && bapi_msg.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = '00' .
wa_zsdt067-bstkd = wa_vbak-bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = ''.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'E'.
wa_zsdt067-e_msg = e_msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 1 SECONDS.
IF wa_vbak-asttx = 'Z20' AND lc_flag = 'Y'.
CLEAR: i_stat,i_objnr.
i_stat = 'E0002'.
SELECT SINGLE objnr INTO i_objnr FROM vbak WHERE vbeln = salesdocument.
CALL FUNCTION 'STATUS_CHANGE_EXTERN'
EXPORTING
objnr = i_objnr
user_status = i_stat
set_chgkz = 'X'
EXCEPTIONS
object_not_found = 1
status_inconsistent = 2
status_not_allowed = 3
OTHERS = 4.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
WAIT UP TO 1 SECONDS.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
salesdocument = |{ salesdocument ALPHA = IN }| .
e_msg = e_msg && salesdocument && '销售订单创建成功'.
CASE wa_vbak-auart.
WHEN 'ZRE'.
PERFORM frm_getdate1 TABLES lt_zsdt067
CHANGING salesdocument
wa_vbak-bstkd
lc_flag
e_msg
wa_zsdt067.
WHEN 'ZSV' .
PERFORM frm_getdate2 TABLES lt_zsdt067
CHANGING salesdocument
wa_vbak-bstkd
lc_flag
e_msg
wa_zsdt067.
WHEN OTHERS.
PERFORM frm_getdate3 TABLES lt_zsdt067
CHANGING salesdocument
wa_vbak-bstkd
lc_flag
e_msg
wa_zsdt067.
ENDCASE.
ENDIF.
LOOP AT lt_zsdt067 INTO wa_zsdt067.
vbeln_vl = wa_zsdt067-vbeln_vl && vbeln_vl.
wbstk = wa_zsdt067-wbstk && wbstk.
ENDLOOP.
vbeln = salesdocument.
MODIFY zsdt067 FROM TABLE lt_zsdt067.
COMMIT WORK.
IF lc_flag EQ 'Y' .
e_code = 'S'.
ELSE.
e_code = 'W'.
ENDIF.
ENDIF.
ENDLOOP.
zmac-rfc-log-e e_code e_msg vbeln vbeln_vl wbstk .
- 当然还有调用的子例程
点击查看代码
FORM frm_getdate TABLES lt_zsdt067 STRUCTURE zsdt067 " 分批次
CHANGING vbeln1 TYPE vbeln
vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
TYPES:
BEGIN OF ty_batch_split,
vbeln TYPE vbeln_vl,
posnr TYPE posnr_vl,
charg TYPE charg_d,
lgort TYPE lgort_d,
lfimg TYPE lfimg,
meins TYPE meins.
TYPES END OF ty_batch_split .
TYPES:
tty_batch_split TYPE TABLE OF ty_batch_split .
TYPES:
tty_lips TYPE TABLE OF lips .
DATA:ls_header_data TYPE bapiobdlvhdrchg,
ls_header_control TYPE bapiobdlvhdrctrlchg,
ls_techn_control TYPE bapidlvcontrol,
lt_item_data TYPE TABLE OF bapiobdlvitemchg,
lt_item_control TYPE TABLE OF bapiobdlvitemctrlchg,
lt_extension2 TYPE bapiextt.
DATA:lv_tabix TYPE sy-tabix,
lv_vposnr TYPE posnr_vl,
ls_batch_split TYPE ty_batch_split,
lt_batch_split TYPE tty_batch_split,
let_lips TYPE tty_lips.
DATA:lv_picking TYPE c,
lv_pstyv TYPE pstyv_vl,
lv_batch TYPE charg_d.
DATA:r_return TYPE bapiret2,
lt_return TYPE TABLE OF bapiret2.
CLEAR:lv_picking,r_return.
SELECT SINGLE * FROM likp INTO @DATA(ls_likp) WHERE vbeln = @vbeln.
SELECT * FROM lips
WHERE vbeln = @vbeln
INTO TABLE @DATA(t_lips).
ls_header_data-deliv_numb = vbeln.
ls_header_control-deliv_numb = vbeln.
ls_techn_control-upd_ind = 'U'.
SELECT SINGLE * FROM likp INTO @DATA(ls_likp1) WHERE vbeln = @vbeln.
IF ls_likp1-lifsk EQ 'Z0'.
ls_header_data-dlv_block = 'Z1'.
ls_header_control-dlv_block_flg = 'X'.
ENDIF.
lv_vposnr = 900000.
DATA(lt_lips_cashe) = t_lips[].
DATA(lt_lips) = t_lips[].
SORT lt_lips BY matnr werks lgort ASCENDING.
DELETE ADJACENT DUPLICATES FROM lt_lips COMPARING matnr werks lgort.
IF ls_likp-vbtyp EQ 'T'.
* IF line_exists( lt_lips[ charg = '' ] ).
LOOP AT lt_lips INTO DATA(ls_lips) WHERE charg IS INITIAL.
lv_batch = |{ sy-datum+2 }0001|.
SELECT SINGLE * FROM mcha
INTO @DATA(ls_mcha)
WHERE matnr = @ls_lips-matnr
AND werks = @ls_lips-werks
AND charg = @lv_batch.
IF sy-subrc = 0.
lv_batch = lv_batch.
ELSE.
REFRESH lt_return.
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = ls_lips-matnr
batch = lv_batch
plant = ls_lips-werks
batchattributes = sy-datum
IMPORTING
batch = lv_batch
TABLES
return = lt_return.
LOOP AT lt_return INTO DATA(ls_return) WHERE type CA 'EA'.
r_return-type = 'E'.
r_return-message = r_return-message && ls_return-message && ';'.
ENDLOOP.
IF r_return-type = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln1 .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg && r_return-message && '创建批次失败'.
APPEND wa_zsdt067 TO lt_zsdt067.
flag = 'N'.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 1 SECONDS.
flag = 'Y'.
ENDIF.
ENDIF.
APPEND VALUE #(
deliv_numb = ls_lips-vbeln
deliv_item = ls_lips-posnr
material = ls_lips-matnr
batch = lv_batch"'8888888888'
dlv_qty = ls_lips-lfimg
dlv_qty_imunit = ls_lips-lfimg
base_uom = ls_lips-meins
sales_unit = ls_lips-meins
fact_unit_nom = 1
fact_unit_denom = 1 ) TO lt_item_data.
APPEND VALUE #(
deliv_numb = ls_lips-vbeln
deliv_item = ls_lips-posnr
chg_delqty = abap_true
volume_flg = abap_true ) TO lt_item_control.
ENDLOOP.
* ELSE.
*
* r_return-type = 'S'.
* ENDIF.
ELSE.
SELECT mchb~matnr,
mchb~werks,
mchb~lgort,
mchb~charg,
mchb~ersda,
mchb~clabs
FROM @lt_lips AS it1 INNER JOIN mchb
ON it1~matnr = mchb~matnr
AND it1~werks = mchb~werks
AND it1~lgort = mchb~lgort
WHERE clabs > 0
INTO TABLE @DATA(lt_stock).
IF lt_stock[] IS NOT INITIAL.
SORT lt_stock BY matnr werks lgort ersda ASCENDING.
LOOP AT t_lips INTO ls_lips.
READ TABLE lt_stock ASSIGNING FIELD-SYMBOL(<fs_stock>)
WITH KEY matnr = ls_lips-matnr
werks = ls_lips-werks BINARY SEARCH.
IF sy-subrc = 0.
LOOP AT lt_stock ASSIGNING <fs_stock> FROM sy-tabix.
IF <fs_stock>-matnr <> ls_lips-matnr OR
<fs_stock>-werks <> ls_lips-werks ."
EXIT.
ENDIF.
IF <fs_stock>-clabs IS INITIAL. "防止一个单出现多行相同料的情况
CONTINUE.
ENDIF.
IF <fs_stock>-clabs >= ls_lips-lfimg.
<fs_stock>-clabs = <fs_stock>-clabs - ls_lips-lfimg.
ls_batch_split-lfimg = ls_lips-lfimg.
ls_lips-lfimg = 0.
ELSE.
ls_lips-lfimg = ls_lips-lfimg - <fs_stock>-clabs.
ls_batch_split-lfimg = <fs_stock>-clabs.
<fs_stock>-clabs = 0.
ENDIF.
ls_batch_split-vbeln = ls_lips-vbeln.
ls_batch_split-posnr = ls_lips-posnr.
ls_batch_split-lgort = <fs_stock>-lgort.
ls_batch_split-charg = <fs_stock>-charg.
APPEND ls_batch_split TO lt_batch_split.
IF ls_lips-lfimg = 0.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
MODIFY t_lips FROM ls_lips TRANSPORTING lfimg.
ENDLOOP.
ENDIF.
DELETE t_lips WHERE lfimg = 0.
* CHECK t_lips[] IS NOT INITIAL.
* CLEAR lt_batch_split[].
IF lt_batch_split[] IS INITIAL OR t_lips[] IS NOT INITIAL.
r_return-type = 'E'.
SORT t_lips BY matnr werks lgort ASCENDING.
DELETE ADJACENT DUPLICATES FROM t_lips COMPARING matnr werks lgort.
LOOP AT t_lips INTO DATA(ls_lips1).
r_return-message = r_return-message && ls_lips1-matnr && '-' && ls_lips1-werks && '-' && ls_lips1-lgort && ';'.
CONDENSE r_return-message.
ENDLOOP.
r_return-message = '批次库存不足!' && r_return-message.
flag = 'N'.
msg = msg && r_return-message.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln1 .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg && r_return-message && '创建批次失败'.
APPEND wa_zsdt067 TO lt_zsdt067.
flag = 'N'.
RETURN.
ENDIF.
SORT lt_batch_split BY vbeln posnr ASCENDING.
LOOP AT lt_lips INTO ls_lips.
"拆分批次行
READ TABLE lt_batch_split WITH KEY vbeln = ls_lips-vbeln
posnr = ls_lips-posnr
BINARY SEARCH
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
lv_tabix = sy-tabix.
LOOP AT lt_batch_split INTO ls_batch_split FROM lv_tabix.
IF ls_lips-vbeln <> ls_batch_split-vbeln
OR ls_lips-posnr <> ls_batch_split-posnr.
EXIT.
ENDIF.
lv_vposnr = lv_vposnr + 1.
APPEND VALUE #(
deliv_numb = ls_batch_split-vbeln
deliv_item = lv_vposnr
hieraritem = ls_batch_split-posnr
batch = ls_batch_split-charg
dlv_qty = ls_batch_split-lfimg
dlv_qty_imunit = ls_batch_split-lfimg
base_uom = ls_batch_split-meins
sales_unit = ls_batch_split-meins
fact_unit_nom = 1
fact_unit_denom = 1
usehieritm = '1' ) TO lt_item_data.
APPEND VALUE #(
deliv_numb = ls_batch_split-vbeln
deliv_item = lv_vposnr
chg_delqty = abap_true
volume_flg = abap_true ) TO lt_item_control.
ENDLOOP.
"修改原行数量
APPEND VALUE #(
deliv_numb = ls_lips-vbeln
deliv_item = ls_lips-posnr
dlv_qty = 0
dlv_qty_imunit = 0
batch = space
fact_unit_nom = 1
fact_unit_denom = 1
usehieritm = '' ) TO lt_item_data.
APPEND VALUE #(
deliv_numb = ls_lips-vbeln
deliv_item = ls_lips-posnr
chg_delqty = abap_true
volume_flg = abap_true ) TO lt_item_control.
ENDIF.
ENDLOOP.
ENDIF.
IF flag = 'Y'.
SORT lt_item_data BY deliv_numb hieraritem deliv_item.
SORT lt_item_control BY deliv_numb deliv_item.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
header_data = ls_header_data
header_control = ls_header_control
delivery = ls_header_data-deliv_numb
techn_control = ls_techn_control
TABLES
item_data = lt_item_data
item_control = lt_item_control
extension2 = lt_extension2
return = lt_return.
LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.
MESSAGE ID ls_return-id
TYPE 'E'
NUMBER ls_return-number
WITH ls_return-message_v1
ls_return-message_v2
ls_return-message_v3
ls_return-message_v4
INTO ls_return-message.
r_return-message = |{ r_return-message }/{ ls_return-message }|.
ENDLOOP.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln1 .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg && r_return-message && '分批次失败'.
APPEND wa_zsdt067 TO lt_zsdt067.
flag = 'N'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 1 SECONDS.
flag = 'Y'.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_getdate1
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- LF_VBELN
*& <-- LC_FLAG
*& <-- E_MSG
*&---------------------------------------------------------------------*
FORM frm_getdate1 TABLES lt_zsdt067 STRUCTURE zsdt067 " zre 的不用创建批次和拣配
CHANGING vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
DATA:l_jp TYPE c.
l_jp = ''.
PERFORM frm_xd CHANGING vbeln flag msg.
IF flag EQ 'Y'.
PERFORM frm_jh TABLES lt_zsdt067 CHANGING vbeln bstkd flag msg wa_zsdt067 l_jp.
ELSE.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = ''.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_xd
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- LF_VBELN
*& <-- LC_FLAG
*& <-- E_MSG
*&---------------------------------------------------------------------*
FORM frm_xd USING vbeln TYPE vbeln_VL " 信贷审批
flag TYPE c
msg TYPE msgtxt.
CALL FUNCTION 'SD_ORDER_CREDIT_RELEASE'
EXPORTING
vbeln = vbeln
EXCEPTIONS
error_message = 4.
IF sy-subrc <> 0.
flag = 'N'.
msg = msg && '信贷审批失败!'.
ELSE.
flag = 'Y'.
msg = msg && '信贷审批成功!'.
ENDIF.
ENDFORM.
FORM frm_jh TABLES lt_zsdt067 STRUCTURE zsdt067 " 交货 tmd 一个销售订单不止一个交付地点就有多个交货
CHANGING vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067
jp TYPE c.
*** 创建交货单要的参数
DATA: ship_point TYPE tvst-vstel, "装运点/接收点
num_deliveries TYPE vbnum, "创建的凭证数
lt_trans_items LIKE bapidlvreftosalesorder OCCURS 0 WITH HEADER LINE, "传输交货单对应的item
deliveries TYPE STANDARD TABLE OF bapishpdelivnumb, "交货号
extension_out TYPE STANDARD TABLE OF bapiparex, "BAPI 参数 ExtensionIn/ExtensionOut 的参考结构
lt_created_items LIKE TABLE OF bapidlvitemcreated, "发送个bapi生产DN的主要数据
ls_created_items LIKE bapidlvitemcreated,
serial_numbers LIKE bapidlvserialnumber OCCURS 0 WITH HEADER LINE , "序列号
lt_return1 TYPE STANDARD TABLE OF bapiret2, "返回参数
lf_vbeln TYPE vbeln_vl. "生成交货单号后返回的凭证
DATA: BEGIN OF ls_ship_point,
ship_point TYPE tvst-vstel,
END OF ls_ship_point.
DATA:lt_ship_point LIKE TABLE OF ls_ship_point,
wa_ship_point LIKE LINE OF lt_ship_point.
DATA: lt_vbap LIKE TABLE OF vbap,
ws_vbap LIKE LINE OF lt_vbap.
CLEAR: ship_point,lt_vbap,lt_ship_point.
REFRESH: lt_vbap,lt_ship_point,lt_created_items,extension_out,deliveries.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE @lt_vbap
FROM vbap
WHERE vbap~vbeln = @vbeln.
SORT lt_vbap BY vbeln.
LOOP AT lt_vbap INTO ws_vbap.
wa_ship_point-ship_point = ws_vbap-vstel.
APPEND wa_ship_point TO lt_ship_point.
ENDLOOP.
SORT lt_ship_point BY ship_point.
DELETE ADJACENT DUPLICATES FROM lt_ship_point COMPARING ship_point."" 要排序
LOOP AT lt_ship_point INTO wa_ship_point.
CLEAR lf_vbeln.
REFRESH: lt_trans_items,lt_return1.
IF flag = 'Y'.
LOOP AT lt_vbap INTO ws_vbap WHERE vstel = wa_ship_point-ship_point.
lt_trans_items-ref_doc = ws_vbap-vbeln. "参考凭证(调拨单)
lt_trans_items-ref_item = ws_vbap-posnr. "参考项(调拨单行项目)
lt_trans_items-dlv_qty = ws_vbap-kwmeng. "实际已交货数量(按销售单位)
lt_trans_items-sales_unit = ws_vbap-meins. "销售单位
APPEND lt_trans_items.
ENDLOOP.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
EXPORTING
ship_point = wa_ship_point-ship_point " 装运点
IMPORTING
delivery = lf_vbeln " 生成的交货单
TABLES
sales_order_items = lt_trans_items " 传输的内表数据
return = lt_return1. " 调用BAPI时反馈的消息内表
IF lf_vbeln IS NOT INITIAL. "不为空说明创建成功
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "提交事务
EXPORTING
wait = 'X'.
WAIT UP TO 1 SECONDS. "等待一秒
flag = 'Y'.
msg = msg && lf_vbeln && '交货单创建成功'.
IF jp EQ 'X'.
PERFORM frm_jp TABLES lt_zsdt067 CHANGING vbeln lf_vbeln bstkd flag msg wa_zsdt067.
ENDIF.
IF flag EQ 'Y'.
PERFORM frm_gz TABLES lt_zsdt067 CHANGING vbeln lf_vbeln bstkd flag msg wa_zsdt067.
ENDIF.
ELSE.
LOOP AT lt_return1 INTO DATA(wa_msg1) WHERE type EQ 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'."事务回滚
msg = msg && ' 交货单创建失败!' && wa_msg1-message.
CLEAR: wa_msg1.
EXIT.
ENDLOOP.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = ''.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg && msg.
APPEND wa_zsdt067 TO lt_zsdt067.
flag = 'N'.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
FORM frm_jp TABLES lt_zsdt067 STRUCTURE zsdt067 "拣配 流程
CHANGING vbeln1 TYPE vbeln
vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
PERFORM frm_getdate TABLES lt_zsdt067 CHANGING vbeln1 vbeln bstkd flag msg wa_zsdt067 .
IF flag EQ 'Y'.
PERFORM frm_getdate_jp TABLES lt_zsdt067 CHANGING vbeln1 vbeln bstkd flag msg wa_zsdt067 .
ENDIF.
ENDFORM.
FORM frm_gz TABLES lt_zsdt067 STRUCTURE zsdt067 "过账 流程
CHANGING vbeln1 TYPE vbeln
vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
DATA: i_header_data TYPE bapiobdlvhdrcon,
i_header_control TYPE bapiobdlvhdrctrlcon,
ls_header_deadlines TYPE bapidlvdeadln,
lt_header_deadlines TYPE TABLE OF bapidlvdeadln.
DATA: lw_return TYPE bapiret2,
lt_return3 TYPE TABLE OF bapiret2,
msgtx TYPE string.
REFRESH:lt_header_deadlines, lt_return3.
CLEAR:i_header_data,i_header_control, ls_header_deadlines,lw_return.
i_header_data-deliv_numb = vbeln. "交货单号
i_header_control-deliv_numb = vbeln. "交货单号
i_header_control-post_gi_flg = 'X'.
i_header_control-deliv_date_flg = 'X'.
ls_header_deadlines-deliv_numb = vbeln.
ls_header_deadlines-timetype = 'WSHDRWADTI'.
ls_header_deadlines-timezone = sy-zonlo.
CONVERT DATE sy-datum
INTO TIME STAMP ls_header_deadlines-timestamp_utc
TIME ZONE sy-zonlo.
APPEND ls_header_deadlines TO lt_header_deadlines.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
EXPORTING
header_data = i_header_data
header_control = i_header_control
delivery = vbeln
TABLES
header_deadlines = lt_header_deadlines
return = lt_return3.
READ TABLE lt_return3 INTO lw_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 1 SECONDS.
flag = 'Y'.
msg = msg && '过账成功!'.
CLEAR:wa_zsdt067.
SELECT SINGLE likp~wbstk INTO @wa_zsdt067-wbstk FROM likp WHERE likp~vbeln EQ @vbeln.
wa_zsdt067-vbeln = vbeln1 .
wa_zsdt067-bstkd = bstkd .
* wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'S'.
wa_zsdt067-e_msg = msg && msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ELSEIF sy-subrc EQ 0.
CLEAR msgtx.
MESSAGE ID lw_return-id TYPE lw_return-type NUMBER lw_return-number
WITH lw_return-message_v1 lw_return-message_v2
lw_return-message_v3 lw_return-message_v4
INTO msgtx.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
flag = 'N'.
msg = msg && '过账失败' && msgtx.
CLEAR:wa_zsdt067.
SELECT SINGLE likp~wbstk INTO @wa_zsdt067-wbstk FROM likp WHERE likp~vbeln EQ @vbeln.
wa_zsdt067-vbeln = vbeln1 .
wa_zsdt067-bstkd = bstkd .
* wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg && msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_getdate2
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- SALESDOCUMENT
*& <-- LC_FLAG
*& <-- E_MSG
*&---------------------------------------------------------------------*
FORM frm_getdate2 TABLES lt_zsdt067 STRUCTURE zsdt067 "ZSV TMD 啥都不用搞 建单及成功
CHANGING vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
PERFORM frm_xd CHANGING vbeln flag msg.
IF flag EQ 'Y'.
msg = msg && '过账成功! ZSV无交货单' .
CLEAR:wa_zsdt067.
* SELECT SINGLE likp~wbstk INTO @wa_zsdt067-wbstk FROM likp WHERE likp~vbeln EQ @vbeln.
wa_zsdt067-vbeln = vbeln .
wa_zsdt067-bstkd = bstkd .
* wa_zsdt067-wbstk = '' .
* wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'S'.
wa_zsdt067-e_msg = msg && msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ELSE.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = ''.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ENDIF.
ENDFORM.
FORM frm_getdate3 TABLES lt_zsdt067 STRUCTURE zsdt067 "其他的 TMD 啥都要搞
CHANGING vbeln TYPE vbeln
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
DATA:l_jp TYPE c.
l_jp = 'X'.
PERFORM frm_xd CHANGING vbeln flag msg.
IF flag EQ 'Y'.
PERFORM frm_jh TABLES lt_zsdt067 CHANGING vbeln bstkd flag msg wa_zsdt067 l_jp.
ELSE.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = ''.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg.
APPEND wa_zsdt067 TO lt_zsdt067.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_getdate_jp
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LT_ZSDT067
*& <-- VBELN1
*& <-- VBELN
*& <-- BSTKD
*& <-- FLAG
*& <-- MSG
*& <-- WA_ZSDT067
*&---------------------------------------------------------------------*
FORM frm_getdate_jp TABLES lt_zsdt067 STRUCTURE zsdt067 "拣配
CHANGING vbeln1 TYPE vbeln
vbeln TYPE vbeln_VL
bstkd TYPE bstkd
flag TYPE c
msg TYPE msgtxt
wa_zsdt067 TYPE zsdt067.
DATA:lv_str TYPE string,
ls_vbkok TYPE vbkok,
lt_vbpok TYPE TABLE OF vbpok,
lt_prot TYPE TABLE OF prott.
DATA:r_return LIKE TABLE OF bapiret2 WITH HEADER LINE.
CLEAR:lv_str,ls_vbkok.
REFRESH:lt_vbpok,lt_prot.
SELECT SINGLE * FROM likp
WHERE vbeln = @vbeln
INTO @DATA(ls_likp).
SELECT * FROM lips
WHERE vbeln = @vbeln
AND lfimg > 0
INTO TABLE @DATA(lt_lips).
ls_vbkok-vbeln_vl = vbeln.
LOOP AT lt_lips INTO DATA(ls_lips).
APPEND INITIAL LINE TO lt_vbpok ASSIGNING FIELD-SYMBOL(<fs_vbpok>).
<fs_vbpok>-vbeln_vl = ls_lips-vbeln.
<fs_vbpok>-posnr_vl = ls_lips-posnr.
<fs_vbpok>-vbeln = ls_lips-vbeln.
<fs_vbpok>-posnn = ls_lips-posnr.
<fs_vbpok>-pikmg = ls_lips-lfimg.
<fs_vbpok>-vrkme = ls_lips-vrkme.
<fs_vbpok>-meins = ls_lips-meins.
<fs_vbpok>-ndifm = 0.
<fs_vbpok>-taqui = ' '.
<fs_vbpok>-orpos = 0.
ENDLOOP.
CALL FUNCTION 'SD_DELIVERY_UPDATE_PICKING'
EXPORTING
vbkok_wa = ls_vbkok
synchron = 'X'
TABLES
vbpok_tab = lt_vbpok
prot = lt_prot.
IF sy-subrc = 0 AND ( lines( lt_prot ) EQ 0 OR ( NOT line_exists( lt_prot[ msgty = 'E' ] ) AND NOT line_exists( lt_prot[ msgty = 'A' ] ) ) ).
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "提交事务
EXPORTING
wait = 'X'.
WAIT UP TO '0.8' SECONDS.
flag = 'Y'.
ELSE.
REFRESH r_return.
LOOP AT lt_prot INTO DATA(ls_prot) WHERE msgty = 'E' OR msgty = 'A'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = ls_prot-msgid
msgnr = ls_prot-msgno
msgv1 = ls_prot-msgv1
msgv2 = ls_prot-msgv2
msgv3 = ls_prot-msgv3
msgv4 = ls_prot-msgv4
IMPORTING
message_text_output = lv_str.
r_return-message = r_return-message && '/' && lv_str.
ENDLOOP.
CLEAR:wa_zsdt067.
wa_zsdt067-vbeln = vbeln1 .
wa_zsdt067-bstkd = bstkd .
wa_zsdt067-wbstk = '' .
wa_zsdt067-vbeln_vl = vbeln.
wa_zsdt067-datum = sy-datum.
wa_zsdt067-type = 'W'.
wa_zsdt067-e_msg = msg && r_return-message && '拣配失败'.
APPEND wa_zsdt067 TO lt_zsdt067.
flag = 'N'.
ENDIF.
REFRESH:lt_lips.
ENDFORM.
先这样吧写完这β 代码 人都晕了 有什么错和可以优化的地方欢迎讨论
标签:wa,zsdt067,vbak,过账,lt,ls,交货,SAP,TYPE From: https://www.cnblogs.com/dyxlin-abap/p/18474374