修改交货单做批次拆分
作者:互联网
*&---------------------------------------------------------------------* *& Form frm_dn_batch *&---------------------------------------------------------------------* *& 批次拆分 *&---------------------------------------------------------------------* *& --> LT_TEMP *&---------------------------------------------------------------------* FORM frm_dn_batch TABLES pt_data TYPE tyt_out. TYPES: BEGIN OF ty_ck, ebeln TYPE ekko-ebeln, ebelp TYPE ekpo-ebelp, charg TYPE mseg-charg, menge TYPE mseg-menge, END OF ty_ck. DATA: ls_ck TYPE ty_ck, lt_ck TYPE TABLE OF ty_ck, ls_rk TYPE ty_ck, lt_rk TYPE TABLE OF ty_ck. TYPES: BEGIN OF ty_lips, vbeln TYPE lips-vbeln, posnr TYPE lips-posnr, vgbel TYPE lips-vgbel, vgpos TYPE lips-vgpos, matnr TYPE lips-matnr, lfimg TYPE lips-lfimg, lgort TYPE lips-lgort, umvkz TYPE lips-umvkz, umvkn TYPE lips-umvkn, meins TYPE lips-meins, vrkme TYPE lips-vrkme, END OF ty_lips. DATA: ls_lips_temp TYPE ty_lips, lt_lips_temp TYPE TABLE OF ty_lips, ls_lips TYPE ty_lips, lt_lips TYPE TABLE OF ty_lips. TYPES: BEGIN OF ty_ebeln, zebeln TYPE zmmt0186-zebeln, zebelp TYPE zmmt0186-zebelp, zmatnr TYPE zmmt0186-zmatnr, zlfimg TYPE zmmt0186-zlfimg, zlgort TYPE zmmt0186-zlgort, END OF ty_ebeln. DATA: ls_ebeln TYPE ty_ebeln, lt_ebeln TYPE TABLE OF ty_ebeln. DATA: lv_delivery TYPE bapishpdelivnumb-deliv_numb, ls_item_data TYPE bapiobdlvitemchg, lt_item_data TYPE TABLE OF bapiobdlvitemchg, ls_item_control TYPE bapiobdlvitemctrlchg, lt_item_control TYPE TABLE OF bapiobdlvitemctrlchg, ls_item_data_spl TYPE /spe/bapiobdlvitemchg, lt_item_data_spl TYPE TABLE OF /spe/bapiobdlvitemchg, lt_return TYPE TABLE OF bapiret2, ls_header_data TYPE bapiobdlvhdrchg, ls_header_control TYPE bapiobdlvhdrctrlchg, ls_techn_control TYPE bapidlvcontrol, "TECHN_CONTROL ls_likp TYPE likp, lt_ekpo TYPE TABLE OF ekpo, lv_tabix TYPE sy-tabix, lv_lfimg TYPE lips-lfimg, lv_flag TYPE char1 VALUE 'X', lv_mes TYPE string, lv_updat TYPE sy-datum, lv_uptim TYPE sy-uzeit, lv_upnam TYPE sy-uname, lv_contactid TYPE zmmt0186-contactid, lcl_error TYPE REF TO cx_sy_open_sql_db, lv_error_text TYPE string, ls_data TYPE ty_out, lv_lgort TYPE lips-lgort. DATA: lv_ebeln TYPE ekko-ebeln, lv_vbeln TYPE likp-vbeln, lv_posnr TYPE lips-posnr VALUE '900000'. FIELD-SYMBOLS <fs_ck> TYPE ty_ck. DEFINE mcr_input_data. ls_item_data-deliv_numb = ls_lips-vbeln. ls_item_data-deliv_item = &1. "项目号 ls_item_data-material = ls_lips-matnr. " ls_item_data-dlv_qty = &2. "数量 " ls_item_data-dlv_qty_imunit = &2. ls_item_data-fact_unit_nom = ls_lips-umvkz. "销售数量转换成SKU的分子(因子) ls_item_data-fact_unit_denom = ls_lips-umvkn. "销售数量转换为 SKU 的值(除数) ls_item_data-base_uom = ls_lips-meins. "基本单位 ls_item_data-sales_unit = ls_lips-vrkme. "销售单位 ls_item_data-batch = &3. "新批次 ls_item_data-hieraritem = &4. "上级行项目 ls_item_data-usehieritm = &5. APPEND ls_item_data TO lt_item_data. ls_item_data_spl-deliv_numb = ls_lips-vbeln. ls_item_data_spl-deliv_item = &1. ls_item_data_spl-stge_loc = lv_lgort. APPEND ls_item_data_spl TO lt_item_data_spl. ls_item_control-deliv_numb = ls_lips-vbeln. ls_item_control-deliv_item = &1. ls_item_control-chg_delqty = 'X'. APPEND ls_item_control TO lt_item_control. END-OF-DEFINITION. IF sy-batch = 'X'. WAIT UP TO 10 SECONDS. ENDIF. READ TABLE pt_data INTO ls_data INDEX 1. IF ls_data-dnflg_b = 'X' OR ls_data-dnflg = ''. RETURN. ENDIF. lv_contactid = ls_data-contactid. lv_ebeln = ls_data-zebeln. lv_vbeln = ls_data-vbeln. *&-----知心出库数量 SELECT ebeln ebelp charg SUM( menge ) INTO TABLE lt_ck FROM ekbe WHERE ebeln = lv_ebeln AND bwart in ('161','674') GROUP BY ebeln ebelp charg. *&-----蜀南入库数量 SELECT ebeln ebelp charg SUM( menge ) INTO TABLE lt_rk FROM ekbe WHERE ebeln = lv_ebeln AND bwart in ('673','162') GROUP BY ebeln ebelp charg. *&-----库存 SORT lt_ck BY ebeln ebelp charg. SORT lt_rk BY ebeln ebelp charg. LOOP AT lt_ck ASSIGNING <fs_ck>. READ TABLE lt_rk INTO ls_rk WITH KEY ebeln = <fs_ck>-ebeln ebelp = <fs_ck>-ebelp BINARY SEARCH. IF sy-subrc = 0. <fs_ck>-menge = <fs_ck>-menge - ls_rk-menge. ENDIF. ENDLOOP. *&-----取交货明细合并 SELECT SINGLE * INTO ls_likp FROM likp WHERE vbeln = lv_vbeln. SELECT a~vbeln a~posnr a~vgbel a~vgpos a~matnr a~lfimg a~lgort a~umvkz a~umvkn a~meins a~vrkme INTO TABLE lt_lips_temp FROM lips AS a WHERE vbeln = lv_vbeln. LOOP AT pt_data INTO ls_data. ls_ebeln-zebeln = ls_data-zebeln. ls_ebeln-zebelp = ls_data-zebelp. ls_ebeln-zmatnr = ls_data-zmatnr. ls_ebeln-zlfimg = ls_data-zlfimg. ls_ebeln-zlgort = ls_data-zlgort. COLLECT ls_ebeln INTO lt_ebeln. ENDLOOP. LOOP AT lt_lips_temp INTO ls_lips. LOOP AT lt_ebeln INTO ls_ebeln WHERE zebeln = ls_lips-vgbel AND zebelp = ls_lips-vgpos. * ls_lips-lfimg = ls_ebeln-zlfimg. ls_lips-lgort = ls_ebeln-zlgort. APPEND ls_lips TO lt_lips. ENDLOOP. ENDLOOP. *&----- 批次拆分过账 lv_delivery = lv_vbeln. ls_header_data-deliv_numb = lv_delivery. ls_header_control-deliv_numb = lv_delivery. * BREAK-POINT. LOOP AT lt_lips INTO ls_lips. lv_lgort = ls_lips-lgort. CLEAR lv_tabix. lv_lfimg = ls_lips-lfimg. LOOP AT lt_ck ASSIGNING <fs_ck> WHERE ebeln = ls_lips-vgbel AND ebelp = ls_lips-vgpos AND menge > 0. lv_tabix = lv_tabix + 1. IF lv_lfimg <= <fs_ck>-menge. IF lv_tabix = 1. *&----- 满足,不用批次拆分. mcr_input_data ls_lips-posnr lv_lfimg <fs_ck>-charg '' ''. ELSE. *&-----拆分批次行 lv_posnr = lv_posnr + 1. mcr_input_data lv_posnr lv_lfimg <fs_ck>-charg ls_lips-posnr '1'. ENDIF. <fs_ck>-menge = <fs_ck>-menge - lv_lfimg. lv_lfimg = 0. CONTINUE. ELSE. *&-----不满足,如果启用批次,需用批次拆分. IF <fs_ck>-charg IS INITIAL. mcr_input_data ls_lips-posnr lv_lfimg <fs_ck>-charg '' ''. ELSE. *&-----主行 IF lv_tabix = 1. mcr_input_data ls_lips-posnr 0 '' '' ''. ENDIF. *&-----拆分批次行 lv_posnr = lv_posnr + 1. mcr_input_data lv_posnr <fs_ck>-menge <fs_ck>-charg ls_lips-posnr '1'. ENDIF. *&----- lv_lfimg = lv_lfimg - <fs_ck>-menge. <fs_ck>-menge = 0. ENDIF. ENDLOOP. IF lv_lfimg <> 0. lv_mes = lv_delivery && '批次库存不够拆分'. lv_flag = ''. ENDIF. ENDLOOP. IF lv_flag = 'X'. CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE' EXPORTING header_data = ls_header_data header_control = ls_header_control delivery = lv_delivery techn_control = ls_techn_control TABLES item_data = lt_item_data item_control = lt_item_control item_data_spl = lt_item_data_spl return = lt_return. LOOP AT lt_return INTO DATA(ls_return) WHERE type = 'E'. IF ls_return-message IS INITIAL. MESSAGE ID ls_return-id TYPE ls_return-type NUMBER ls_return-number INTO ls_return-message WITH ls_return-message_v1 ls_return-message_v2 ls_return-message_v3 ls_return-message_v4. ENDIF. CONCATENATE lv_mes ls_return-message INTO lv_mes SEPARATED BY '/'. ENDLOOP. IF sy-subrc = 0. "创建失败 CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. lv_flag = ''. ELSE. "创建成功 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. lv_flag = 'X'. ENDIF. ENDIF. lv_updat = sy-datum. lv_uptim = sy-uzeit. lv_upnam = sy-uname. LOOP AT pt_data ASSIGNING FIELD-SYMBOL(<fs_temp>). UPDATE zmmt0186 SET dnflg_b = lv_flag dndat_b = sy-datum dntim_b = sy-uzeit dnnam_b = sy-uname dnmes_b = lv_mes WHERE contactid = <fs_temp>-contactid AND receiptkey = <fs_temp>-receiptkey AND receiptkeyno = <fs_temp>-receiptkeyno. <fs_temp>-dnflg_b = lv_flag. <fs_temp>-dndat_b = sy-datum. <fs_temp>-dntim_b = sy-uzeit. <fs_temp>-dnnam_b = sy-uname. <fs_temp>-dnmes_b = lv_mes. READ TABLE gt_out ASSIGNING FIELD-SYMBOL(<fs_data>) WITH KEY contactid = <fs_temp>-contactid receiptkey = <fs_temp>-receiptkey receiptkeyno = <fs_temp>-receiptkeyno. IF sy-subrc = 0. <fs_data>-dnflg_b = lv_flag. <fs_data>-dndat_b = sy-datum. <fs_data>-dntim_b = sy-uzeit. <fs_data>-dnnam_b = sy-uname. <fs_data>-dnmes_b = lv_mes. ENDIF. ENDLOOP. COMMIT WORK AND WAIT. ENDFORM.
标签:批次,data,lv,item,lips,ls,拆分,交货单,TYPE 来源: https://www.cnblogs.com/rainysblog/p/11028484.html