SAP货物移动BAPI BAPI_GOODSMVT_CREATE(WMS TO SAP)

移动代码

01 -- MB01
02 -- MB31
03 -- MB1A
04 -- MB1B
05 -- MB1C
06 -- MB11
07 -- MB04

一、收货(101)

说明:采购订单、生产订单收货

[plain]  view plain  copy
  1. form recvfromord tables pt_tran structure zwttran.  
  2.   "移库定义  
  3.   data: goodsmvt_header  type   bapi2017_gm_head_01,  
  4.         goodsmvt_code    type   bapi2017_gm_code,  
  5.         goodsmvt_headret type   bapi2017_gm_head_ret,  
  6.         materialdocument type   bapi2017_gm_head_ret-mat_doc,  
  7.         matdocumentyear  type   bapi2017_gm_head_ret-doc_year,  
  8.         goodsmvt_item    type standard table of   /afs/bapi2017_gm_item_create,  
  9.         return           type standard table of   bapiret2,  
  10.         w_creturn        type   bapiret2,  
  11.         w_goodsmvt_item  type                     /afs/bapi2017_gm_item_create,  
  12.         w_return         type   bapiret2.  
  13.   data:lt_retmsg like table of bapiret2 with header line,  
  14.        lt_return like table of bapiret2 with header line.  
  15.   data:l_tran_nbr like zwttran-tran_nbr,  
  16.        l_tranpo   like zwttran-tranpo,  
  17.        l_matdoc   like zwttran-matdoc,  
  18.        l_flag     like zwttran-flag,  
  19.        l_line_id type i.  
  20.   data:l_asn_nbr type ze_ref_field, "asn号  
  21.        l_po type ze_ref_field,"po号  
  22.        l_po_line(5) type n,"po行号  
  23.        l_matnr type matnr."货号  
  24.   data:l_type type char1,"类型  
  25.        l_afpo type afpo,"生产订单  
  26.        l_j_3abssi type  j_3abssi,"生产订单计划行  
  27.        l_eket type eket,"采购订单计划行  
  28.        l_ekpo type ekpo."采购订单行项目  
  29.   data:lt_bom like table of zwmbom with header line.  
  30.   refresh:t_tran_nbr.  
  31.   loop at pt_tran.  
  32.     clear :t_tran_nbr.  
  33.     t_tran_nbr-tran_nbr = pt_tran-tran_nbr.  
  34.     if pt_tran-tran_type = '603' and pt_tran-tran_code = '02' and pt_tran-proc_stat_code = '10'  and pt_tran-ref_field_6 = 'P'.  
  35.       t_tran_nbr-po = pt_tran-ref_field_3.  
  36.     endif.  
  37.     append t_tran_nbr.  
  38.   endloop.  
  39.   sort t_tran_nbr by tran_nbr po.  
  40.   delete adjacent duplicates from t_tran_nbr.  
  41.   
  42.   loop at t_tran_nbr.  
  43.     clear:l_tran_nbr,l_matdoc,l_matnr,l_asn_nbr,l_po,l_matnr,l_type,l_afpo,l_j_3abssi,l_eket,l_ekpo,l_tranpo,lt_retmsg,lt_return,pt_tran.  
  44.     refresh:lt_return.  
  45.   
  46.     clear:goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.  
  47.     refresh:goodsmvt_item ,return.  
  48.     "头  
  49.     goodsmvt_header-pstng_date = sy-datum.  
  50.     goodsmvt_header-doc_date = sy-datum.  
  51.     "明细  
  52.     loop at pt_tran where tran_type = '603' and tran_code = '02'  and proc_stat_code = '10' and units_rcvd > 0  
  53.                       and tran_nbr = t_tran_nbr-tran_nbr and ref_field_3 = t_tran_nbr-po.  
  54.       if pt_tran-ref_field_6 = 'P'.  
  55.         l_tran_nbr =  pt_tran-tran_nbr.  
  56.         "获取asn号  
  57.         l_asn_nbr = pt_tran-ref_field_1.  
  58.         l_po = pt_tran-ref_field_3.  
  59.         concatenate l_tran_nbr l_po into l_tranpo.  
  60.         if pt_tran-ref_field_4 is not initial.  
  61.           l_po_line = pt_tran-ref_field_4.  
  62.         else.  
  63.           clear l_po_line.  
  64.         endif.  
  65.         l_matnr = pt_tran-matnr.  
  66.         clear:lt_retmsg.  
  67.         refresh:lt_retmsg.  
  68.         call function 'ZLC_GET_PREMOVE101'  
  69.           EXPORTING  
  70.             p_matnr    = l_matnr  
  71.             p_po       = l_po  
  72.             p_po_line  = l_po_line  
  73.           IMPORTING  
  74.             p_type     = l_type  
  75.             p_afpo     = l_afpo  
  76.             p_j_3abssi = l_j_3abssi  
  77.             p_ekpo     = l_ekpo  
  78.             p_eket     = l_eket  
  79.           TABLES  
  80.             pt_retmsg  = lt_retmsg.  
  81.         read table lt_retmsg with key type = 'E'.  
  82.         if sy-subrc <> 0.  
  83.           case l_type.  
  84.             when 'E'.  
  85.               "事务代码  
  86.               goodsmvt_code-gm_code = '02'.                 "mb31  
  87.               "明细  
  88.               w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.  
  89.               w_goodsmvt_item-move_type = '101'."移动类型  
  90.               w_goodsmvt_item-material = l_j_3abssi-matnr."大货号  
  91.               w_goodsmvt_item-grid_value = l_j_3abssi-j_3asize."网格值  
  92.   
  93.               w_goodsmvt_item-plant = g_plant."工厂  
  94.               w_goodsmvt_item-stge_loc = g_stge_loc."地点  
  95.   
  96.               w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd."数量  
  97.   
  98.               w_goodsmvt_item-orderid = l_j_3abssi-j_3absnr."订单号  
  99.               w_goodsmvt_item-order_itno = l_j_3abssi-j_3ahbsp."行项目  
  100.               w_goodsmvt_item-sched_line_sku = l_j_3abssi-j_3aebsp."计划行项目  
  101.   
  102.               w_goodsmvt_item-mvt_ind = 'F'."生产订单  
  103.               w_goodsmvt_item-stck_type = 'E'.  
  104.               w_goodsmvt_item-gr_rcpt  = pt_tran-user_id.  
  105.               append w_goodsmvt_item to goodsmvt_item.  
  106.             when 'F'.  
  107.               "事务代码  
  108.               goodsmvt_code-gm_code = '01'.                 "mb01  
  109.               "明细  
  110.               w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.  
  111.               l_line_id = w_goodsmvt_item-line_id.  
  112.               w_goodsmvt_item-move_type = '101'."移动类型  
  113.               w_goodsmvt_item-material = l_ekpo-matnr."大货号  
  114.               w_goodsmvt_item-grid_value = l_eket-j_3asize."网格值  
  115.   
  116.               w_goodsmvt_item-plant = g_plant."工厂  
  117.               w_goodsmvt_item-stge_loc = g_stge_loc."地点  
  118.               clear w_goodsmvt_item-vendor.  
  119.               w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd."数量  
  120.               clear w_goodsmvt_item-batch.  
  121.               w_goodsmvt_item-po_number = l_eket-ebeln."采购订单  
  122.               w_goodsmvt_item-po_item = l_eket-ebelp."采购订单行号  
  123.               w_goodsmvt_item-sched_line_sku = l_eket-etenr."计划行  
  124.   
  125.               clear:w_goodsmvt_item-parent_id,w_goodsmvt_item-line_depth.  
  126.               w_goodsmvt_item-mvt_ind = 'B'."采购订单  
  127.               w_goodsmvt_item-stck_type = 'E'."库存类型  
  128.               w_goodsmvt_item-gr_rcpt  = pt_tran-user_id.  
  129.               append w_goodsmvt_item to goodsmvt_item.  
  130.   
  131.               refresh:lt_bom.  
  132.               call function 'ZLC_GET_BOM'  
  133.                 EXPORTING  
  134.                   p_ebeln = l_eket-ebeln  
  135.                   p_ebelp = l_eket-ebelp  
  136.                   p_etenr = l_eket-etenr  
  137.                 TABLES  
  138.                   pt_bom  = lt_bom.  
  139.               if lines( lt_bom ) > 0.  
  140.                 loop at lt_bom.  
  141.                   w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.  
  142.                   w_goodsmvt_item-move_type = '543'."移动类型  
  143.                   w_goodsmvt_item-material = lt_bom-matnr."货号  
  144.                   if lt_bom-grdv is not initial.  
  145.                     w_goodsmvt_item-grid_value = lt_bom-grdv.  
  146.                   else.  
  147.                     clear w_goodsmvt_item-grid_value.  
  148.                   endif.  
  149.                   w_goodsmvt_item-plant = '1000'."工厂  
  150.                   clear w_goodsmvt_item-stge_loc.  
  151.                   w_goodsmvt_item-vendor = lt_bom-vendor."供应商  
  152.                   w_goodsmvt_item-entry_qnt = lt_bom-entry_qnt * pt_tran-units_rcvd."数量  
  153.   
  154.                   if lt_bom-charg is not initial.  
  155.                     w_goodsmvt_item-batch = lt_bom-charg.  
  156.                   else.  
  157.                     clear w_goodsmvt_item-batch.  
  158.                   endif.  
  159.                   w_goodsmvt_item-parent_id = l_line_id.  
  160.                   w_goodsmvt_item-line_depth = 1.  
  161.                   w_goodsmvt_item-mvt_ind = 'B'."采购订单  
  162.                   w_goodsmvt_item-stck_type = 'E'."库存类型  
  163.                   w_goodsmvt_item-gr_rcpt  = pt_tran-user_id.  
  164.                   append w_goodsmvt_item to goodsmvt_item.  
  165.                 endloop.  
  166.               endif.  
  167.           endcase.  
  168.         else.  
  169.           append lines of lt_retmsg to lt_return.  
  170.         endif.  
  171.       endif.  
  172.     endloop.  
  173.   
  174.     read table lt_return with key type = 'E'.  
  175.     if sy-subrc <> 0.  
  176.       if goodsmvt_item[] is not initial.  
  177.         "删除日志  
  178.         perform deletepixtranlog using l_tranpo.  
  179.         "执行操作  
  180.         call function '/AFS/BAPI_GOODSMVT_CREATE'  
  181.           EXPORTING  
  182.             goodsmvt_header   = goodsmvt_header  
  183.             goodsmvt_code     = goodsmvt_code  
  184.           IMPORTING  
  185.             goodsmvt_headret  = goodsmvt_headret  
  186.             materialdocument  = materialdocument  
  187.             matdocumentyear   = matdocumentyear  
  188.           TABLES  
  189.             afs_goodsmvt_item = goodsmvt_item  
  190.             return            = return.  
  191.         read table return with key type = 'E' into w_return.  
  192.         if sy-subrc <> 0.  
  193.           "提交  
  194.           call function 'BAPI_TRANSACTION_COMMIT'  
  195.             EXPORTING  
  196.               wait = 'X'.  
  197.           l_flag = 'S'.  
  198.           l_matdoc = materialdocument.  
  199.         else.  
  200.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  201.           l_flag = 'F'.  
  202.         endif.  
  203.         update zwttran set flag = l_flag matdoc = l_matdoc where tranpo = l_tranpo.  
  204.         if l_flag = 'F'.  
  205.           perform writepixtranlog tables return using l_tranpo.  
  206.         endif.  
  207.       endif.  
  208.     else.  
  209.       update zwttran set flag = 'F' where tranpo = l_tranpo.  
  210.       perform writepixtranlog tables lt_return using l_tranpo.  
  211.     endif.  
  212.   endloop.  
  213. endform.                    "recvfromord  

二、移库、冻结、解冻、内部领用、盘点、报废、转包、门店退货等
[plain]  view plain  copy
  1. form dopixtran tables pt_tran structure zwttran.  
  2.   data: l_tran_nbr like zwttran-tran_nbr,  
  3.         l_matdoc   like zwttran-matdoc,  
  4.         l_flag     like zwttran-flag,  
  5.         l_mara     like mara,  
  6.         lt_mard like table of mard with header line.  
  7.   data:goodsmvt_header  type   bapi2017_gm_head_01,  
  8.         goodsmvt_code    type   bapi2017_gm_code,  
  9.         goodsmvt_headret type   bapi2017_gm_head_ret,  
  10.         materialdocument type   bapi2017_gm_head_ret-mat_doc,  
  11.         matdocumentyear  type   bapi2017_gm_head_ret-doc_year,  
  12.         goodsmvt_item    type standard table of   bapi2017_gm_item_create,  
  13.         return           type standard table of   bapiret2,  
  14.         w_goodsmvt_item  type                     bapi2017_gm_item_create,  
  15.         w_return         type bapiret2.  
  16.   data:lt_retmsg like table of bapiret2 with header line.  
  17.   refresh:t_tran_nbr.  
  18.   loop at pt_tran.  
  19.     clear:t_tran_nbr.  
  20.     t_tran_nbr-tran_nbr = pt_tran-tran_nbr.  
  21.     collect t_tran_nbr.  
  22.   endloop.  
  23.   sort t_tran_nbr by tran_nbr.  
  24.   
  25.   loop at t_tran_nbr.  
  26.     "&--------------------------------------------------------------------------------------------------------------&  
  27.     "& BEGIN 从3,4仓移库到物流中心仓库  
  28.     "&--------------------------------------------------------------------------------------------------------------&  
  29.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.  
  30.     refresh:goodsmvt_item ,return.  
  31.     "事物码  
  32.     goodsmvt_code-gm_code = '04'.  
  33.     "头  
  34.     goodsmvt_header-pstng_date = sy-datum.  
  35.     goodsmvt_header-doc_date = sy-datum.  
  36.     "明细  
  37.     loop at pt_tran where tran_type = '603' and tran_code = '02' and proc_stat_code = '10' and units_rcvd > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  38.       if pt_tran-ref_field_6 = 'Y'.  
  39.         l_tran_nbr = pt_tran-tran_nbr.  
  40.         w_goodsmvt_item-move_type = '311'."移库  
  41.         w_goodsmvt_item-plant = g_plant.  
  42.         w_goodsmvt_item-stge_loc = pt_tran-ref_field_7.  
  43.         w_goodsmvt_item-material = pt_tran-matnr.  
  44.         w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd.  
  45.         w_goodsmvt_item-move_plant = g_plant.  
  46.         w_goodsmvt_item-move_stloc = g_stge_loc.  
  47.         append w_goodsmvt_item to goodsmvt_item.  
  48.       endif.  
  49.     endloop.  
  50.     "执行操作  
  51.     if goodsmvt_item[] is not initial.  
  52.       l_flag = 'F'.  
  53.       call function 'BAPI_GOODSMVT_CREATE'  
  54.         EXPORTING  
  55.           goodsmvt_header  = goodsmvt_header  
  56.           goodsmvt_code    = goodsmvt_code  
  57.         IMPORTING  
  58.           goodsmvt_headret = goodsmvt_headret  
  59.           materialdocument = materialdocument  
  60.           matdocumentyear  = matdocumentyear  
  61.         TABLES  
  62.           goodsmvt_item    = goodsmvt_item  
  63.           return           = return.  
  64.       read table return with key type = 'E' into w_return.  
  65.       if sy-subrc <> 0.  
  66.         call function 'BAPI_TRANSACTION_COMMIT'  
  67.           EXPORTING  
  68.             wait = 'X'.  
  69.         if materialdocument is not initial.  
  70.           l_flag = 'S'.  
  71.           l_matdoc = materialdocument.  
  72.         endif.  
  73.       else.  
  74.         call function 'BAPI_TRANSACTION_ROLLBACK'.  
  75.         perform writepixtranlog tables return using l_tran_nbr.  
  76.       endif.  
  77.       update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  78.     endif.  
  79.     "&--------------------------------------------------------------------------------------------------------------&  
  80.     "& END 移入  
  81.     "&--------------------------------------------------------------------------------------------------------------&  
  82.   
  83.     "&--------------------------------------------------------------------------------------------------------------&  
  84.     "& BEGIN 从物流中心仓库移至3,4仓  
  85.     "&--------------------------------------------------------------------------------------------------------------&  
  86.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.  
  87.     refresh:goodsmvt_item ,return.  
  88.     "事物码  
  89.     goodsmvt_code-gm_code = '04'.  
  90.     "头  
  91.     goodsmvt_header-pstng_date = sy-datum.  
  92.     goodsmvt_header-doc_date = sy-datum.  
  93.     "明细  
  94.     loop at pt_tran where  tran_type = '300' and tran_code = '01' and actn_code = '07'and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  95.       if pt_tran-rsn_code = 'YC'.  
  96.         l_tran_nbr = pt_tran-tran_nbr.  
  97.         w_goodsmvt_item-move_type = '311'."移库  
  98.         w_goodsmvt_item-plant = g_plant.  
  99.         w_goodsmvt_item-stge_loc =  g_stge_loc.  
  100.         w_goodsmvt_item-material = pt_tran-matnr.  
  101.         w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.  
  102.         w_goodsmvt_item-move_plant = g_plant.  
  103.         w_goodsmvt_item-move_stloc = pt_tran-ref_field_5.  
  104.         append w_goodsmvt_item to goodsmvt_item.  
  105.       endif.  
  106.     endloop.  
  107.     "执行操作  
  108.     if goodsmvt_item[] is not initial.  
  109.       l_flag = 'F'.  
  110.       call function 'BAPI_GOODSMVT_CREATE'  
  111.         EXPORTING  
  112.           goodsmvt_header  = goodsmvt_header  
  113.           goodsmvt_code    = goodsmvt_code  
  114.         IMPORTING  
  115.           goodsmvt_headret = goodsmvt_headret  
  116.           materialdocument = materialdocument  
  117.           matdocumentyear  = matdocumentyear  
  118.         TABLES  
  119.           goodsmvt_item    = goodsmvt_item  
  120.           return           = return.  
  121.       read table return with key type = 'E' into w_return.  
  122.       if sy-subrc <> 0.  
  123.         call function 'BAPI_TRANSACTION_COMMIT'  
  124.           EXPORTING  
  125.             wait = 'X'.  
  126.         if materialdocument is not initial.  
  127.           l_flag = 'S'.  
  128.           l_matdoc = materialdocument.  
  129.         endif.  
  130.       else.  
  131.         call function 'BAPI_TRANSACTION_ROLLBACK'.  
  132.         perform writepixtranlog tables return using l_tran_nbr.  
  133.       endif.  
  134.       update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  135.     endif.  
  136.     "&--------------------------------------------------------------------------------------------------------------&  
  137.     "& END 移出  
  138.     "&--------------------------------------------------------------------------------------------------------------&  
  139.   
  140.     "&--------------------------------------------------------------------------------------------------------------&  
  141.     "& begin 冻结库存  
  142.     "&--------------------------------------------------------------------------------------------------------------&  
  143.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.  
  144.     refresh:goodsmvt_item ,return.  
  145.     "事物码  
  146.     goodsmvt_code-gm_code = '04'.  
  147.     "头  
  148.     goodsmvt_header-pstng_date = sy-datum.  
  149.     goodsmvt_header-doc_date = sy-datum.  
  150.     "明细  
  151.     loop at pt_tran where tran_type = '300' and tran_code = '01' and actn_code = '05' and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  152.       l_tran_nbr = pt_tran-tran_nbr.  
  153.       w_goodsmvt_item-move_type = '344'."冻结库存  
  154.       w_goodsmvt_item-plant = g_plant.  
  155.       w_goodsmvt_item-stge_loc = g_stge_loc.  
  156.       w_goodsmvt_item-material = pt_tran-matnr.  
  157.       w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.  
  158.       append w_goodsmvt_item to goodsmvt_item.  
  159.     endloop.  
  160.     "执行操作  
  161.     if goodsmvt_item[] is not initial.  
  162.       l_flag = 'F'.  
  163.       call function 'BAPI_GOODSMVT_CREATE'  
  164.         EXPORTING  
  165.           goodsmvt_header  = goodsmvt_header  
  166.           goodsmvt_code    = goodsmvt_code  
  167.         IMPORTING  
  168.           goodsmvt_headret = goodsmvt_headret  
  169.           materialdocument = materialdocument  
  170.           matdocumentyear  = matdocumentyear  
  171.         TABLES  
  172.           goodsmvt_item    = goodsmvt_item  
  173.           return           = return.  
  174.       read table return with key type = 'E' into w_return.  
  175.       if sy-subrc <> 0.  
  176.         call function 'BAPI_TRANSACTION_COMMIT'  
  177.           EXPORTING  
  178.             wait = 'X'.  
  179.         if materialdocument is not initial.  
  180.           l_flag = 'S'.  
  181.           l_matdoc = materialdocument.  
  182.         endif.  
  183.       else.  
  184.         call function 'BAPI_TRANSACTION_ROLLBACK'.  
  185.         perform writepixtranlog tables return using l_tran_nbr.  
  186.       endif.  
  187.       update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  188.     endif.  
  189.     "&--------------------------------------------------------------------------------------------------------------&  
  190.     "& END 冻结库存  
  191.     "&--------------------------------------------------------------------------------------------------------------&  
  192.   
  193.     "&--------------------------------------------------------------------------------------------------------------&  
  194.     "& begin 解冻库存  
  195.     "&--------------------------------------------------------------------------------------------------------------&  
  196.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.  
  197.     refresh:goodsmvt_item ,return.  
  198.     "事物码  
  199.     goodsmvt_code-gm_code = '04'.  
  200.     "头  
  201.     goodsmvt_header-pstng_date = sy-datum.  
  202.     goodsmvt_header-doc_date = sy-datum.  
  203.     "明细  
  204.     loop at pt_tran where tran_type = '606' and tran_code = '02' and actn_code = '06' and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  205.       l_tran_nbr = pt_tran-tran_nbr.  
  206.       w_goodsmvt_item-move_type = '343'."解冻库存  
  207.       w_goodsmvt_item-plant = g_plant.  
  208.       w_goodsmvt_item-stge_loc = g_stge_loc.  
  209.       w_goodsmvt_item-material = pt_tran-matnr.  
  210.       w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.  
  211.       append w_goodsmvt_item to goodsmvt_item.  
  212.     endloop.  
  213.     "执行操作  
  214.     if goodsmvt_item[] is not initial.  
  215.       l_flag = 'F'.  
  216.       call function 'BAPI_GOODSMVT_CREATE'  
  217.         EXPORTING  
  218.           goodsmvt_header  = goodsmvt_header  
  219.           goodsmvt_code    = goodsmvt_code  
  220.         IMPORTING  
  221.           goodsmvt_headret = goodsmvt_headret  
  222.           materialdocument = materialdocument  
  223.           matdocumentyear  = matdocumentyear  
  224.         TABLES  
  225.           goodsmvt_item    = goodsmvt_item  
  226.           return           = return.  
  227.       read table return with key type = 'E' into w_return.  
  228.       if sy-subrc <> 0.  
  229.         call function 'BAPI_TRANSACTION_COMMIT'  
  230.           EXPORTING  
  231.             wait = 'X'.  
  232.         if materialdocument is not initial.  
  233.           l_flag = 'S'.  
  234.           l_matdoc = materialdocument.  
  235.         endif.  
  236.       else.  
  237.         call function 'BAPI_TRANSACTION_ROLLBACK'.  
  238.         perform writepixtranlog tables return using l_tran_nbr.  
  239.       endif.  
  240.       update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  241.     endif.  
  242.     "&--------------------------------------------------------------------------------------------------------------&  
  243.     "& END 解冻库存  
  244.     "&--------------------------------------------------------------------------------------------------------------&  
  245.   
  246.     "&--------------------------------------------------------------------------------------------------------------&  
  247.     "& BEGIN 内部领用  
  248.     "&--------------------------------------------------------------------------------------------------------------&  
  249.     data:l_kostl like csks-kostl,"成本中心  
  250.          l_prctr like cepc-prctr,"利润中心  
  251.          l_csks like csks,"成本中心结构  
  252.          l_cepc like cepc."利润中心结构  
  253.     data:lt_tpmsg like table of bapiret2 with header line.  
  254.     clear:l_kostl,l_prctr,l_csks,l_cepc.  
  255.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return,lt_tpmsg,lt_retmsg.  
  256.     refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.  
  257.     "事物码  
  258.     goodsmvt_code-gm_code = '03'.                           "MB1A  
  259.     "头  
  260.     goodsmvt_header-pstng_date = sy-datum.  
  261.     goodsmvt_header-doc_date = sy-datum.  
  262.     "明细  
  263.     loop at pt_tran where  tran_type = '300' and tran_code = '01' and actn_code = '07'and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  264.       if pt_tran-rsn_code = 'NL'.  
  265.         clear:l_kostl,l_csks,lt_tpmsg.  
  266.         refresh:lt_tpmsg.  
  267.         l_tran_nbr = pt_tran-tran_nbr.  
  268.         l_kostl = pt_tran-ref_field_5.  
  269.         call function 'ZLC_GET_CSKS'  
  270.           EXPORTING  
  271.             P_KOKRS   = '1000'  
  272.             P_KOSTL   = l_kostl  
  273.           IMPORTING  
  274.             p_csks    = l_csks  
  275.           TABLES  
  276.             pt_retmsg = lt_tpmsg.  
  277.         read table lt_tpmsg with key type = 'E'.  
  278.         if sy-subrc <> 0.  
  279.           w_goodsmvt_item-move_type = '201'."内部领用  
  280.           w_goodsmvt_item-plant = g_plant.  
  281.           w_goodsmvt_item-stge_loc = g_stge_loc.  
  282.           w_goodsmvt_item-material = pt_tran-matnr.  
  283.           w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.  
  284.           w_goodsmvt_item-costcenter = l_kostl."成本中心  
  285.           w_goodsmvt_item-profit_ctr = l_csks-prctr."利润中心  
  286.           append w_goodsmvt_item to goodsmvt_item.  
  287.         else.  
  288.           append lines of lt_tpmsg to lt_retmsg.  
  289.         endif.  
  290.       endif.  
  291.     endloop.  
  292.     "执行操作  
  293.     read table lt_retmsg with key type = 'E'.  
  294.     if sy-subrc <> 0.  
  295.       if goodsmvt_item[] is not initial.  
  296.         l_flag = 'F'.  
  297.         call function 'BAPI_GOODSMVT_CREATE'  
  298.           EXPORTING  
  299.             goodsmvt_header  = goodsmvt_header  
  300.             goodsmvt_code    = goodsmvt_code  
  301.           IMPORTING  
  302.             goodsmvt_headret = goodsmvt_headret  
  303.             materialdocument = materialdocument  
  304.             matdocumentyear  = matdocumentyear  
  305.           TABLES  
  306.             goodsmvt_item    = goodsmvt_item  
  307.             return           = return.  
  308.         read table return with key type = 'E' into w_return.  
  309.         if sy-subrc <> 0.  
  310.           call function 'BAPI_TRANSACTION_COMMIT'  
  311.             EXPORTING  
  312.               wait = 'X'.  
  313.           if materialdocument is not initial.  
  314.             l_flag = 'S'.  
  315.             l_matdoc = materialdocument.  
  316.           endif.  
  317.         else.  
  318.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  319.           perform writepixtranlog tables return using l_tran_nbr.  
  320.         endif.  
  321.         update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  322.       endif.  
  323.     else.  
  324.       update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.  
  325.       perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  326.     endif.  
  327.     "&--------------------------------------------------------------------------------------------------------------&  
  328.     "& END 内部领用  
  329.     "&--------------------------------------------------------------------------------------------------------------&  
  330.   
  331.     "&--------------------------------------------------------------------------------------------------------------&  
  332.     "& BEGIN 内部领用退回  
  333.     "&--------------------------------------------------------------------------------------------------------------&  
  334.     clear:l_kostl,l_prctr,l_csks,l_cepc.  
  335.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return,lt_tpmsg,lt_retmsg.  
  336.     refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.  
  337.     "事物码  
  338.     goodsmvt_code-gm_code = '03'.                           "MB1A  
  339.     "头  
  340.     goodsmvt_header-pstng_date = sy-datum.  
  341.     goodsmvt_header-doc_date = sy-datum.  
  342.     "明细  
  343.     loop at pt_tran where tran_type = '603' and tran_code = '02' and proc_stat_code = '10' and units_rcvd > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  344.       if pt_tran-ref_field_6 = 'N'.  
  345.         clear:l_kostl,l_csks,lt_tpmsg.  
  346.         refresh:lt_tpmsg.  
  347.         l_tran_nbr = pt_tran-tran_nbr.  
  348.         l_kostl = pt_tran-ref_field_5.  
  349.         call function 'ZLC_GET_CSKS'  
  350.           EXPORTING  
  351.             P_KOKRS   = '1000'  
  352.             P_KOSTL   = l_kostl  
  353.           IMPORTING  
  354.             p_csks    = l_csks  
  355.           TABLES  
  356.             pt_retmsg = lt_tpmsg.  
  357.         read table lt_tpmsg with key type = 'E'.  
  358.         if sy-subrc <> 0.  
  359.           w_goodsmvt_item-move_type = '202'."内部领用冲销  
  360.           w_goodsmvt_item-plant = g_plant.  
  361.           w_goodsmvt_item-stge_loc = g_stge_loc.  
  362.           w_goodsmvt_item-material = pt_tran-matnr.  
  363.           w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd.  
  364.           w_goodsmvt_item-costcenter = l_kostl."成本中心  
  365.           w_goodsmvt_item-profit_ctr = l_csks-prctr."利润中心  
  366.           append w_goodsmvt_item to goodsmvt_item.  
  367.         else.  
  368.           append lines of lt_tpmsg to lt_retmsg.  
  369.         endif.  
  370.       endif.  
  371.     endloop.  
  372.     "执行操作  
  373.     read table lt_retmsg with key type = 'E'.  
  374.     if sy-subrc <> 0.  
  375.       if goodsmvt_item[] is not initial.  
  376.         l_flag = 'F'.  
  377.         call function 'BAPI_GOODSMVT_CREATE'  
  378.           EXPORTING  
  379.             goodsmvt_header  = goodsmvt_header  
  380.             goodsmvt_code    = goodsmvt_code  
  381.           IMPORTING  
  382.             goodsmvt_headret = goodsmvt_headret  
  383.             materialdocument = materialdocument  
  384.             matdocumentyear  = matdocumentyear  
  385.           TABLES  
  386.             goodsmvt_item    = goodsmvt_item  
  387.             return           = return.  
  388.         read table return with key type = 'E' into w_return.  
  389.         if sy-subrc <> 0.  
  390.           call function 'BAPI_TRANSACTION_COMMIT'  
  391.             EXPORTING  
  392.               wait = 'X'.  
  393.           if materialdocument is not initial.  
  394.             l_flag = 'S'.  
  395.             l_matdoc = materialdocument.  
  396.           endif.  
  397.         else.  
  398.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  399.           perform writepixtranlog tables return using l_tran_nbr.  
  400.         endif.  
  401.         update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  402.       endif.  
  403.     else.  
  404.       update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.  
  405.       perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  406.     endif.  
  407.     "&--------------------------------------------------------------------------------------------------------------&  
  408.     "& END 内部领用退回  
  409.     "&--------------------------------------------------------------------------------------------------------------&  
  410.   
  411.     "&--------------------------------------------------------------------------------------------------------------&  
  412.     "& BEGIN 报废  
  413.     "&--------------------------------------------------------------------------------------------------------------&  
  414.     clear:l_kostl,l_prctr,l_csks,l_cepc.  
  415.     clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return,lt_tpmsg,lt_retmsg.  
  416.     refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.  
  417.     "事物码  
  418.     goodsmvt_code-gm_code = '03'.  
  419.     "头  
  420.     goodsmvt_header-pstng_date = sy-datum.  
  421.     goodsmvt_header-doc_date = sy-datum.  
  422.     "明细  
  423.     loop at pt_tran where  tran_type = '300' and tran_code = '01' and actn_code = '07'and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  424.       if pt_tran-rsn_code = 'BF'.  
  425.         clear:l_prctr,l_cepc.  
  426.         refresh:lt_tpmsg.  
  427.         l_tran_nbr = pt_tran-tran_nbr.  
  428.         l_prctr = pt_tran-ref_field_5.  
  429.         call function 'ZLC_GET_CEPC'  
  430.           EXPORTING  
  431.             p_kokrs   = '1000'  
  432.             p_prctr   = l_prctr  
  433.           IMPORTING  
  434.             p_cepc    = l_cepc  
  435.           TABLES  
  436.             pt_retmsg = lt_tpmsg.  
  437.         read table lt_tpmsg with key type = 'E'.  
  438.         if sy-subrc <> 0.  
  439.           w_goodsmvt_item-move_type = '551'."报废  
  440.           w_goodsmvt_item-plant = g_plant.  
  441.           w_goodsmvt_item-stge_loc = g_stge_loc.  
  442.           w_goodsmvt_item-material = pt_tran-matnr.  
  443.           w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.  
  444.           w_goodsmvt_item-profit_ctr = l_prctr."利润中心  
  445.           append w_goodsmvt_item to goodsmvt_item.  
  446.         else.  
  447.           append lines of lt_tpmsg to lt_retmsg.  
  448.         endif.  
  449.       endif.  
  450.     endloop.  
  451.     "执行操作  
  452.     read table lt_retmsg with key type = 'E'.  
  453.     if sy-subrc <> 0.  
  454.       if goodsmvt_item[] is not initial.  
  455.         l_flag = 'F'.  
  456.         call function 'BAPI_GOODSMVT_CREATE'  
  457.           EXPORTING  
  458.             goodsmvt_header  = goodsmvt_header  
  459.             goodsmvt_code    = goodsmvt_code  
  460.           IMPORTING  
  461.             goodsmvt_headret = goodsmvt_headret  
  462.             materialdocument = materialdocument  
  463.             matdocumentyear  = matdocumentyear  
  464.           TABLES  
  465.             goodsmvt_item    = goodsmvt_item  
  466.             return           = return.  
  467.         read table return with key type = 'E' into w_return.  
  468.         if sy-subrc <> 0.  
  469.           call function 'BAPI_TRANSACTION_COMMIT'  
  470.             EXPORTING  
  471.               wait = 'X'.  
  472.           if materialdocument is not initial.  
  473.             l_flag = 'S'.  
  474.             l_matdoc = materialdocument.  
  475.           endif.  
  476.         else.  
  477.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  478.           perform writepixtranlog tables return using l_tran_nbr.  
  479.         endif.  
  480.         update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  481.       endif.  
  482.     else.  
  483.       update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.  
  484.       perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  485.     endif.  
  486.     "&--------------------------------------------------------------------------------------------------------------&  
  487.     "& END 报废  
  488.     "&--------------------------------------------------------------------------------------------------------------&  
  489.   
  490.     "&--------------------------------------------------------------------------------------------------------------&  
  491.     "& BEGIN 转包  
  492.     "&--------------------------------------------------------------------------------------------------------------&  
  493.     data:l_lifnr like lfa1-lifnr.  
  494.     clear:l_lifnr,l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return,lt_tpmsg,lt_retmsg.  
  495.     refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.  
  496.     "事物码  
  497.     goodsmvt_code-gm_code = '04'.  
  498.     "头  
  499.     goodsmvt_header-pstng_date = sy-datum.  
  500.     goodsmvt_header-doc_date = sy-datum.  
  501.     "明细  
  502.     loop at pt_tran where  tran_type = '300' and tran_code = '01' and actn_code = '07'and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  503.       if pt_tran-rsn_code = 'ZB'.  
  504.         clear:l_lifnr.  
  505.         refresh:lt_tpmsg.  
  506.         l_tran_nbr = pt_tran-tran_nbr.  
  507.         l_lifnr = pt_tran-ref_field_5.  
  508.         call function 'CONVERSION_EXIT_ALPHA_INPUT'  
  509.           EXPORTING  
  510.             input  = l_lifnr  
  511.           IMPORTING  
  512.             output = l_lifnr.  
  513.         select count(*) from lfa1 where lifnr = l_lifnr.  
  514.         if sy-subrc <> 0.  
  515.           lt_tpmsg-type = 'E'.  
  516.           concatenate '供应商' l_lifnr '不存在!' into lt_tpmsg-message.  
  517.           append lt_tpmsg.  
  518.         endif.  
  519.         read table lt_tpmsg with key type = 'E'.  
  520.         if sy-subrc <> 0.  
  521.           w_goodsmvt_item-move_type = '541'."转包  
  522.           w_goodsmvt_item-plant = g_plant.  
  523.           w_goodsmvt_item-stge_loc = g_stge_loc.  
  524.           w_goodsmvt_item-material = pt_tran-matnr.  
  525.           w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.  
  526.           w_goodsmvt_item-vendor = l_lifnr."供应商  
  527.           append w_goodsmvt_item to goodsmvt_item.  
  528.         else.  
  529.           append lines of lt_tpmsg to lt_retmsg.  
  530.         endif.  
  531.       endif.  
  532.     endloop.  
  533.     "执行操作  
  534.     read table lt_retmsg with key type = 'E'.  
  535.     if sy-subrc <> 0.  
  536.       if goodsmvt_item[] is not initial.  
  537.         l_flag = 'F'.  
  538.         call function 'BAPI_GOODSMVT_CREATE'  
  539.           EXPORTING  
  540.             goodsmvt_header  = goodsmvt_header  
  541.             goodsmvt_code    = goodsmvt_code  
  542.           IMPORTING  
  543.             goodsmvt_headret = goodsmvt_headret  
  544.             materialdocument = materialdocument  
  545.             matdocumentyear  = matdocumentyear  
  546.           TABLES  
  547.             goodsmvt_item    = goodsmvt_item  
  548.             return           = return.  
  549.         read table return with key type = 'E' into w_return.  
  550.         if sy-subrc <> 0.  
  551.           call function 'BAPI_TRANSACTION_COMMIT'  
  552.             EXPORTING  
  553.               wait = 'X'.  
  554.           if materialdocument is not initial.  
  555.             l_flag = 'S'.  
  556.             l_matdoc = materialdocument.  
  557.           endif.  
  558.         else.  
  559.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  560.           perform writepixtranlog tables return using l_tran_nbr.  
  561.         endif.  
  562.         update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  563.       endif.  
  564.     else.  
  565.       update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.  
  566.       perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  567.     endif.  
  568.     "&--------------------------------------------------------------------------------------------------------------&  
  569.     "& END 转包  
  570.     "&--------------------------------------------------------------------------------------------------------------&  
  571.   
  572.     "&--------------------------------------------------------------------------------------------------------------&  
  573.     "& BEGIN 转包冲销  
  574.     "&--------------------------------------------------------------------------------------------------------------&  
  575.     clear:l_lifnr,l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return,lt_tpmsg,lt_retmsg.  
  576.     refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.  
  577.     "事物码  
  578.     goodsmvt_code-gm_code = '04'.  
  579.     "头  
  580.     goodsmvt_header-pstng_date = sy-datum.  
  581.     goodsmvt_header-doc_date = sy-datum.  
  582.     "明细  
  583.     loop at pt_tran where tran_type = '603' and tran_code = '02' and proc_stat_code = '10' and units_rcvd > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  584.       if pt_tran-ref_field_6 = 'T'.  
  585.         clear:l_lifnr.  
  586.         refresh:lt_tpmsg.  
  587.         l_tran_nbr = pt_tran-tran_nbr.  
  588.         l_lifnr = pt_tran-ref_field_7.  
  589.         call function 'CONVERSION_EXIT_ALPHA_INPUT'  
  590.           EXPORTING  
  591.             input  = l_lifnr  
  592.           IMPORTING  
  593.             output = l_lifnr.  
  594.         select count(*) from lfa1 where lifnr = l_lifnr.  
  595.         if sy-subrc <> 0.  
  596.           lt_tpmsg-type = 'E'.  
  597.           concatenate '供应商' l_lifnr '不存在!' into lt_tpmsg-message.  
  598.           append lt_tpmsg.  
  599.         endif.  
  600.         read table lt_tpmsg with key type = 'E'.  
  601.         if sy-subrc <> 0.  
  602.           w_goodsmvt_item-move_type = '542'."转包冲销  
  603.           w_goodsmvt_item-plant = g_plant.  
  604.           w_goodsmvt_item-stge_loc = g_stge_loc.  
  605.           w_goodsmvt_item-material = pt_tran-matnr.  
  606.           w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd.  
  607.           w_goodsmvt_item-vendor = l_lifnr."供应商  
  608.           append w_goodsmvt_item to goodsmvt_item.  
  609.         else.  
  610.           append lines of lt_tpmsg to lt_retmsg.  
  611.         endif.  
  612.       endif.  
  613.     endloop.  
  614.     "执行操作  
  615.     read table lt_retmsg with key type = 'E'.  
  616.     if sy-subrc <> 0.  
  617.       if goodsmvt_item[] is not initial.  
  618.         l_flag = 'F'.  
  619.         call function 'BAPI_GOODSMVT_CREATE'  
  620.           EXPORTING  
  621.             goodsmvt_header  = goodsmvt_header  
  622.             goodsmvt_code    = goodsmvt_code  
  623.           IMPORTING  
  624.             goodsmvt_headret = goodsmvt_headret  
  625.             materialdocument = materialdocument  
  626.             matdocumentyear  = matdocumentyear  
  627.           TABLES  
  628.             goodsmvt_item    = goodsmvt_item  
  629.             return           = return.  
  630.         read table return with key type = 'E' into w_return.  
  631.         if sy-subrc <> 0.  
  632.           call function 'BAPI_TRANSACTION_COMMIT'  
  633.             EXPORTING  
  634.               wait = 'X'.  
  635.           if materialdocument is not initial.  
  636.             l_flag = 'S'.  
  637.             l_matdoc = materialdocument.  
  638.           endif.  
  639.         else.  
  640.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  641.           perform writepixtranlog tables return using l_tran_nbr.  
  642.         endif.  
  643.         update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.  
  644.       endif.  
  645.     else.  
  646.       update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.  
  647.       perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  648.     endif.  
  649.     "&--------------------------------------------------------------------------------------------------------------&  
  650.     "& END 转包冲销  
  651.     "&--------------------------------------------------------------------------------------------------------------&  
  652.   
  653.     "&--------------------------------------------------------------------------------------------------------------&  
  654.     "& BEGIN 盘点  
  655.     "&--------------------------------------------------------------------------------------------------------------&  
  656.     data:l_physinv_head type bapi_physinv_create_head,  
  657.          lt_physinv_item   like table of bapi_physinv_create_items with header line.  
  658.     data:it_count_item like table of bapi_physinv_count_items with header line,  
  659.          lt_temp like table of bapi_physinv_count_items with header line,  
  660.          l_invdoc type iblnr,  
  661.          l_nblnr(10) type c,  
  662.          l_count type i.  
  663.     "&--------------------------------------------盘点-------------------------------------------------------------&  
  664.     "初始化  
  665.     clear:l_tran_nbr,l_flag,l_matdoc,l_physinv_head,lt_physinv_item, lt_retmsg,it_count_item,lt_temp,l_invdoc,l_nblnr,l_count.  
  666.     refresh:lt_physinv_item, lt_retmsg,lt_temp,it_count_item.  
  667.     "盘点单头  
  668.     l_physinv_head-plant = g_plant.  
  669.     l_physinv_head-stge_loc = g_stge_loc.  
  670.     l_physinv_head-doc_date = sy-datum.  
  671.     l_physinv_head-plan_date = sy-datum.  
  672.   
  673.     loop at pt_tran where  ( ( tran_type = '300' and ( tran_code = '04' or tran_code = '01') and actn_code = '14' )  
  674.       or ( tran_type = '300' and tran_code = '04' and actn_code = '' ) ) and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.  
  675.       clear:lt_temp.  
  676.       l_tran_nbr = pt_tran-tran_nbr.  
  677.       "盘点单计数  
  678.       lt_temp-material = pt_tran-matnr.  
  679.       case pt_tran-invn_adjmt_type.  
  680.         when 'A'.  
  681.           lt_temp-entry_qnt = pt_tran-invn_adjmt_qty.  
  682.         when 'S'.  
  683.           lt_temp-entry_qnt = - pt_tran-invn_adjmt_qty.  
  684.       endcase.  
  685.       collect lt_temp.  
  686.     endloop.  
  687.   
  688.     loop at lt_temp.  
  689.       add 1 to l_count.  
  690.       "初始化  
  691.       clear:lt_mard.  
  692.       refresh:lt_mard.  
  693.       "获取当前库存  
  694.       call function 'ZLC_GET_STOCK'  
  695.         EXPORTING  
  696.           p_matnr = lt_temp-material  
  697.           p_werks = g_plant  
  698.           p_lgort = g_stge_loc  
  699.         TABLES  
  700.           pt_mard = lt_mard.  
  701.       read table lt_mard index 1.  
  702.       "盘点处理  
  703.       if sy-subrc = 0.  
  704.         "盘点单物料  
  705.         lt_physinv_item-material = lt_temp-material.  
  706.         append lt_physinv_item.  
  707.         "盘点单计数  
  708.         it_count_item-item = l_count.  
  709.         it_count_item-material = lt_temp-material.  
  710.         it_count_item-entry_qnt = lt_mard-labst + lt_temp-entry_qnt.  
  711.         clear:l_mara.  
  712.         call function 'ZLC_GET_MARA'  
  713.           EXPORTING  
  714.             p_matnr = lt_temp-material  
  715.           IMPORTING  
  716.             p_mara  = l_mara.  
  717.         if l_mara is not initial.  
  718.           it_count_item-entry_uom = l_mara-meins.  
  719.         endif.  
  720.         append it_count_item.  
  721.       else.  
  722.         clear:lt_retmsg.  
  723.         lt_retmsg-type = 'E'.  
  724.         concatenate '商品' lt_temp-material ',' g_plant ',' g_stge_loc  '不存在!' into lt_retmsg-message.  
  725.         append lt_retmsg.  
  726.       endif.  
  727.     endloop.  
  728.   
  729.     read table lt_retmsg with key type = 'E'.  
  730.     if sy-subrc <> 0.  
  731.       if it_count_item[] is not initial.  
  732.         l_flag = 'F'.  
  733.         clear:lt_retmsg.  
  734.         refresh:lt_retmsg.  
  735.         call function 'BAPI_MATPHYSINV_CREATE_MULT'"创建盘点凭证  
  736.         exporting  
  737.           head   = l_physinv_head  
  738.         tables  
  739.           items  = lt_physinv_item  
  740.           return = lt_retmsg.  
  741.   
  742.         loop at lt_retmsg.  
  743.           if lt_retmsg-type = 'S' and lt_retmsg-id = 'M7'  
  744.           and lt_retmsg-number = '710'.  
  745.             l_nblnr = lt_retmsg-message_v1.  
  746.             shift l_nblnr right deleting trailing space.  
  747.             overlay l_nblnr with '0000000000'.  
  748.             l_invdoc = l_nblnr.  
  749.           endif.  
  750.         endloop.  
  751.   
  752.         read table lt_retmsg with key type = 'E'.  
  753.         if sy-subrc <> 0.  
  754.   
  755.           call function 'BAPI_TRANSACTION_COMMIT'  
  756.             EXPORTING  
  757.               wait = 'X'.  
  758.   
  759.           clear:lt_retmsg.  
  760.           refresh:lt_retmsg.  
  761.           call function 'BAPI_MATPHYSINV_COUNT'"输入盘点数量  
  762.           exporting  
  763.             physinventory = l_invdoc  
  764.             fiscalyear    = sy-datum+0(4)  
  765.             count_date    = sy-datum  
  766.           tables  
  767.             items         = it_count_item  
  768.             return        = lt_retmsg.  
  769.   
  770.           read table lt_retmsg with key type = 'E'.  
  771.           if sy-subrc <> 0.  
  772.             call function 'BAPI_TRANSACTION_COMMIT'  
  773.               EXPORTING  
  774.                 wait = 'X'.  
  775.   
  776.             clear:lt_retmsg.  
  777.             refresh:lt_retmsg.  
  778.             call function 'BAPI_MATPHYSINV_POSTDIFF'"处理差异  
  779.             exporting  
  780.               physinventory = l_invdoc  
  781.               fiscalyear    = sy-datum+0(4)  
  782.               pstng_date    = sy-datum  
  783.             tables  
  784.               return        = lt_retmsg.  
  785.   
  786.             read table lt_retmsg with key type = 'E'.  
  787.             if sy-subrc <> 0.  
  788.               call function 'BAPI_TRANSACTION_COMMIT'  
  789.                 EXPORTING  
  790.                   wait = 'X'.  
  791.               loop at lt_retmsg.  
  792.                 if lt_retmsg-type = 'S' and lt_retmsg-id = 'M7'  
  793.                 and lt_retmsg-number = '716'.  
  794.                   l_nblnr = lt_retmsg-message_v2.  
  795.                   shift l_nblnr right deleting trailing space.  
  796.                   overlay l_nblnr with '0000000000'.  
  797.                   l_matdoc = l_nblnr.  
  798.                 endif.  
  799.               endloop.  
  800.               l_flag = 'S'.  
  801.             else.  
  802.               call function 'BAPI_TRANSACTION_ROLLBACK'.  
  803.             endif.  
  804.           else.  
  805.             call function 'BAPI_TRANSACTION_ROLLBACK'.  
  806.           endif.  
  807.         else.  
  808.           call function 'BAPI_TRANSACTION_ROLLBACK'.  
  809.         endif.  
  810.         update zwttran set flag = l_flag matdoc = l_matdoc iblnr = l_invdoc where tran_nbr = l_tran_nbr.  
  811.         if l_flag = 'F'.  
  812.           perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  813.         endif.  
  814.       endif.  
  815.     else.  
  816.       update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.  
  817.       perform writepixtranlog tables lt_retmsg using l_tran_nbr.  
  818.     endif.  
  819.     "  &--------------------------------------------------------------------------------------------------------------&  
  820.     "  & end 报损、报溢、盘点  
  821.     "  &--------------------------------------------------------------------------------------------------------------&  
  822.   endloop.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值