移動代碼
01 -- MB01
02 -- MB31
03 -- MB1A
04 -- MB1B
05 -- MB1C
06 -- MB11
07 -- MB04
一、收貨(101)
說明:采購訂單、生産訂單收貨
[plain] view plain copy
- form recvfromord tables pt_tran structure zwttran.
- "移庫定義
- data: goodsmvt_header type bapi2017_gm_head_01,
- goodsmvt_code type bapi2017_gm_code,
- goodsmvt_headret type bapi2017_gm_head_ret,
- materialdocument type bapi2017_gm_head_ret-mat_doc,
- matdocumentyear type bapi2017_gm_head_ret-doc_year,
- goodsmvt_item type standard table of /afs/bapi2017_gm_item_create,
- return type standard table of bapiret2,
- w_creturn type bapiret2,
- w_goodsmvt_item type /afs/bapi2017_gm_item_create,
- w_return type bapiret2.
- data:lt_retmsg like table of bapiret2 with header line,
- lt_return like table of bapiret2 with header line.
- data:l_tran_nbr like zwttran-tran_nbr,
- l_tranpo like zwttran-tranpo,
- l_matdoc like zwttran-matdoc,
- l_flag like zwttran-flag,
- l_line_id type i.
- data:l_asn_nbr type ze_ref_field, "asn号
- l_po type ze_ref_field,"po号
- l_po_line(5) type n,"po行号
- l_matnr type matnr."貨号
- data:l_type type char1,"類型
- l_afpo type afpo,"生産訂單
- l_j_3abssi type j_3abssi,"生産訂單計劃行
- l_eket type eket,"采購訂單計劃行
- l_ekpo type ekpo."采購訂單行項目
- data:lt_bom like table of zwmbom with header line.
- refresh:t_tran_nbr.
- loop at pt_tran.
- clear :t_tran_nbr.
- t_tran_nbr-tran_nbr = pt_tran-tran_nbr.
- 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'.
- t_tran_nbr-po = pt_tran-ref_field_3.
- endif.
- append t_tran_nbr.
- endloop.
- sort t_tran_nbr by tran_nbr po.
- delete adjacent duplicates from t_tran_nbr.
- loop at t_tran_nbr.
- 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.
- refresh:lt_return.
- clear:goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.
- refresh:goodsmvt_item ,return.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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 and ref_field_3 = t_tran_nbr-po.
- if pt_tran-ref_field_6 = 'P'.
- l_tran_nbr = pt_tran-tran_nbr.
- "擷取asn号
- l_asn_nbr = pt_tran-ref_field_1.
- l_po = pt_tran-ref_field_3.
- concatenate l_tran_nbr l_po into l_tranpo.
- if pt_tran-ref_field_4 is not initial.
- l_po_line = pt_tran-ref_field_4.
- else.
- clear l_po_line.
- endif.
- l_matnr = pt_tran-matnr.
- clear:lt_retmsg.
- refresh:lt_retmsg.
- call function 'ZLC_GET_PREMOVE101'
- EXPORTING
- p_matnr = l_matnr
- p_po = l_po
- p_po_line = l_po_line
- IMPORTING
- p_type = l_type
- p_afpo = l_afpo
- p_j_3abssi = l_j_3abssi
- p_ekpo = l_ekpo
- p_eket = l_eket
- TABLES
- pt_retmsg = lt_retmsg.
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- case l_type.
- when 'E'.
- "事務代碼
- goodsmvt_code-gm_code = '02'. "mb31
- "明細
- w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.
- w_goodsmvt_item-move_type = '101'."移動類型
- w_goodsmvt_item-material = l_j_3abssi-matnr."大貨号
- w_goodsmvt_item-grid_value = l_j_3abssi-j_3asize."網格值
- w_goodsmvt_item-plant = g_plant."工廠
- w_goodsmvt_item-stge_loc = g_stge_loc."地點
- w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd."數量
- w_goodsmvt_item-orderid = l_j_3abssi-j_3absnr."訂單号
- w_goodsmvt_item-order_itno = l_j_3abssi-j_3ahbsp."行項目
- w_goodsmvt_item-sched_line_sku = l_j_3abssi-j_3aebsp."計劃行項目
- w_goodsmvt_item-mvt_ind = 'F'."生産訂單
- w_goodsmvt_item-stck_type = 'E'.
- w_goodsmvt_item-gr_rcpt = pt_tran-user_id.
- append w_goodsmvt_item to goodsmvt_item.
- when 'F'.
- "事務代碼
- goodsmvt_code-gm_code = '01'. "mb01
- "明細
- w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.
- l_line_id = w_goodsmvt_item-line_id.
- w_goodsmvt_item-move_type = '101'."移動類型
- w_goodsmvt_item-material = l_ekpo-matnr."大貨号
- w_goodsmvt_item-grid_value = l_eket-j_3asize."網格值
- w_goodsmvt_item-plant = g_plant."工廠
- w_goodsmvt_item-stge_loc = g_stge_loc."地點
- clear w_goodsmvt_item-vendor.
- w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd."數量
- clear w_goodsmvt_item-batch.
- w_goodsmvt_item-po_number = l_eket-ebeln."采購訂單
- w_goodsmvt_item-po_item = l_eket-ebelp."采購訂單行号
- w_goodsmvt_item-sched_line_sku = l_eket-etenr."計劃行
- clear:w_goodsmvt_item-parent_id,w_goodsmvt_item-line_depth.
- w_goodsmvt_item-mvt_ind = 'B'."采購訂單
- w_goodsmvt_item-stck_type = 'E'."庫存類型
- w_goodsmvt_item-gr_rcpt = pt_tran-user_id.
- append w_goodsmvt_item to goodsmvt_item.
- refresh:lt_bom.
- call function 'ZLC_GET_BOM'
- EXPORTING
- p_ebeln = l_eket-ebeln
- p_ebelp = l_eket-ebelp
- p_etenr = l_eket-etenr
- TABLES
- pt_bom = lt_bom.
- if lines( lt_bom ) > 0.
- loop at lt_bom.
- w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.
- w_goodsmvt_item-move_type = '543'."移動類型
- w_goodsmvt_item-material = lt_bom-matnr."貨号
- if lt_bom-grdv is not initial.
- w_goodsmvt_item-grid_value = lt_bom-grdv.
- else.
- clear w_goodsmvt_item-grid_value.
- endif.
- w_goodsmvt_item-plant = '1000'."工廠
- clear w_goodsmvt_item-stge_loc.
- w_goodsmvt_item-vendor = lt_bom-vendor."供應商
- w_goodsmvt_item-entry_qnt = lt_bom-entry_qnt * pt_tran-units_rcvd."數量
- if lt_bom-charg is not initial.
- w_goodsmvt_item-batch = lt_bom-charg.
- else.
- clear w_goodsmvt_item-batch.
- endif.
- w_goodsmvt_item-parent_id = l_line_id.
- w_goodsmvt_item-line_depth = 1.
- w_goodsmvt_item-mvt_ind = 'B'."采購訂單
- w_goodsmvt_item-stck_type = 'E'."庫存類型
- w_goodsmvt_item-gr_rcpt = pt_tran-user_id.
- append w_goodsmvt_item to goodsmvt_item.
- endloop.
- endif.
- endcase.
- else.
- append lines of lt_retmsg to lt_return.
- endif.
- endif.
- endloop.
- read table lt_return with key type = 'E'.
- if sy-subrc <> 0.
- if goodsmvt_item[] is not initial.
- "删除日志
- perform deletepixtranlog using l_tranpo.
- "執行操作
- call function '/AFS/BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- afs_goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- "送出
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- l_flag = 'F'.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tranpo = l_tranpo.
- if l_flag = 'F'.
- perform writepixtranlog tables return using l_tranpo.
- endif.
- endif.
- else.
- update zwttran set flag = 'F' where tranpo = l_tranpo.
- perform writepixtranlog tables lt_return using l_tranpo.
- endif.
- endloop.
- endform. "recvfromord
二、移庫、當機、解凍、内部領用、盤點、報廢、轉包、門店退貨等
[plain] view plain copy
- form dopixtran tables pt_tran structure zwttran.
- data: l_tran_nbr like zwttran-tran_nbr,
- l_matdoc like zwttran-matdoc,
- l_flag like zwttran-flag,
- l_mara like mara,
- lt_mard like table of mard with header line.
- data:goodsmvt_header type bapi2017_gm_head_01,
- goodsmvt_code type bapi2017_gm_code,
- goodsmvt_headret type bapi2017_gm_head_ret,
- materialdocument type bapi2017_gm_head_ret-mat_doc,
- matdocumentyear type bapi2017_gm_head_ret-doc_year,
- goodsmvt_item type standard table of bapi2017_gm_item_create,
- return type standard table of bapiret2,
- w_goodsmvt_item type bapi2017_gm_item_create,
- w_return type bapiret2.
- data:lt_retmsg like table of bapiret2 with header line.
- refresh:t_tran_nbr.
- loop at pt_tran.
- clear:t_tran_nbr.
- t_tran_nbr-tran_nbr = pt_tran-tran_nbr.
- collect t_tran_nbr.
- endloop.
- sort t_tran_nbr by tran_nbr.
- loop at t_tran_nbr.
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 從3,4倉移庫到物流中心倉庫
- "&--------------------------------------------------------------------------------------------------------------&
- clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.
- refresh:goodsmvt_item ,return.
- "事物碼
- goodsmvt_code-gm_code = '04'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-ref_field_6 = 'Y'.
- l_tran_nbr = pt_tran-tran_nbr.
- w_goodsmvt_item-move_type = '311'."移庫
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = pt_tran-ref_field_7.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd.
- w_goodsmvt_item-move_plant = g_plant.
- w_goodsmvt_item-move_stloc = g_stge_loc.
- append w_goodsmvt_item to goodsmvt_item.
- endif.
- endloop.
- "執行操作
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 移入
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 從物流中心倉庫移至3,4倉
- "&--------------------------------------------------------------------------------------------------------------&
- clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.
- refresh:goodsmvt_item ,return.
- "事物碼
- goodsmvt_code-gm_code = '04'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-rsn_code = 'YC'.
- l_tran_nbr = pt_tran-tran_nbr.
- w_goodsmvt_item-move_type = '311'."移庫
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.
- w_goodsmvt_item-move_plant = g_plant.
- w_goodsmvt_item-move_stloc = pt_tran-ref_field_5.
- append w_goodsmvt_item to goodsmvt_item.
- endif.
- endloop.
- "執行操作
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 移出
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& begin 當機庫存
- "&--------------------------------------------------------------------------------------------------------------&
- clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.
- refresh:goodsmvt_item ,return.
- "事物碼
- goodsmvt_code-gm_code = '04'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- l_tran_nbr = pt_tran-tran_nbr.
- w_goodsmvt_item-move_type = '344'."當機庫存
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.
- append w_goodsmvt_item to goodsmvt_item.
- endloop.
- "執行操作
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 當機庫存
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& begin 解凍庫存
- "&--------------------------------------------------------------------------------------------------------------&
- clear:l_tran_nbr,l_flag,l_matdoc,goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.
- refresh:goodsmvt_item ,return.
- "事物碼
- goodsmvt_code-gm_code = '04'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- l_tran_nbr = pt_tran-tran_nbr.
- w_goodsmvt_item-move_type = '343'."解凍庫存
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.
- append w_goodsmvt_item to goodsmvt_item.
- endloop.
- "執行操作
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 解凍庫存
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 内部領用
- "&--------------------------------------------------------------------------------------------------------------&
- data:l_kostl like csks-kostl,"成本中心
- l_prctr like cepc-prctr,"利潤中心
- l_csks like csks,"成本中心結構
- l_cepc like cepc."利潤中心結構
- data:lt_tpmsg like table of bapiret2 with header line.
- clear:l_kostl,l_prctr,l_csks,l_cepc.
- 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.
- refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.
- "事物碼
- goodsmvt_code-gm_code = '03'. "MB1A
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-rsn_code = 'NL'.
- clear:l_kostl,l_csks,lt_tpmsg.
- refresh:lt_tpmsg.
- l_tran_nbr = pt_tran-tran_nbr.
- l_kostl = pt_tran-ref_field_5.
- call function 'ZLC_GET_CSKS'
- EXPORTING
- P_KOKRS = '1000'
- P_KOSTL = l_kostl
- IMPORTING
- p_csks = l_csks
- TABLES
- pt_retmsg = lt_tpmsg.
- read table lt_tpmsg with key type = 'E'.
- if sy-subrc <> 0.
- w_goodsmvt_item-move_type = '201'."内部領用
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.
- w_goodsmvt_item-costcenter = l_kostl."成本中心
- w_goodsmvt_item-profit_ctr = l_csks-prctr."利潤中心
- append w_goodsmvt_item to goodsmvt_item.
- else.
- append lines of lt_tpmsg to lt_retmsg.
- endif.
- endif.
- endloop.
- "執行操作
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- else.
- update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 内部領用
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 内部領用退回
- "&--------------------------------------------------------------------------------------------------------------&
- clear:l_kostl,l_prctr,l_csks,l_cepc.
- 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.
- refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.
- "事物碼
- goodsmvt_code-gm_code = '03'. "MB1A
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-ref_field_6 = 'N'.
- clear:l_kostl,l_csks,lt_tpmsg.
- refresh:lt_tpmsg.
- l_tran_nbr = pt_tran-tran_nbr.
- l_kostl = pt_tran-ref_field_5.
- call function 'ZLC_GET_CSKS'
- EXPORTING
- P_KOKRS = '1000'
- P_KOSTL = l_kostl
- IMPORTING
- p_csks = l_csks
- TABLES
- pt_retmsg = lt_tpmsg.
- read table lt_tpmsg with key type = 'E'.
- if sy-subrc <> 0.
- w_goodsmvt_item-move_type = '202'."内部領用沖銷
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd.
- w_goodsmvt_item-costcenter = l_kostl."成本中心
- w_goodsmvt_item-profit_ctr = l_csks-prctr."利潤中心
- append w_goodsmvt_item to goodsmvt_item.
- else.
- append lines of lt_tpmsg to lt_retmsg.
- endif.
- endif.
- endloop.
- "執行操作
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- else.
- update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 内部領用退回
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 報廢
- "&--------------------------------------------------------------------------------------------------------------&
- clear:l_kostl,l_prctr,l_csks,l_cepc.
- 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.
- refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.
- "事物碼
- goodsmvt_code-gm_code = '03'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-rsn_code = 'BF'.
- clear:l_prctr,l_cepc.
- refresh:lt_tpmsg.
- l_tran_nbr = pt_tran-tran_nbr.
- l_prctr = pt_tran-ref_field_5.
- call function 'ZLC_GET_CEPC'
- EXPORTING
- p_kokrs = '1000'
- p_prctr = l_prctr
- IMPORTING
- p_cepc = l_cepc
- TABLES
- pt_retmsg = lt_tpmsg.
- read table lt_tpmsg with key type = 'E'.
- if sy-subrc <> 0.
- w_goodsmvt_item-move_type = '551'."報廢
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.
- w_goodsmvt_item-profit_ctr = l_prctr."利潤中心
- append w_goodsmvt_item to goodsmvt_item.
- else.
- append lines of lt_tpmsg to lt_retmsg.
- endif.
- endif.
- endloop.
- "執行操作
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- else.
- update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 報廢
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 轉包
- "&--------------------------------------------------------------------------------------------------------------&
- data:l_lifnr like lfa1-lifnr.
- 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.
- refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.
- "事物碼
- goodsmvt_code-gm_code = '04'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-rsn_code = 'ZB'.
- clear:l_lifnr.
- refresh:lt_tpmsg.
- l_tran_nbr = pt_tran-tran_nbr.
- l_lifnr = pt_tran-ref_field_5.
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- EXPORTING
- input = l_lifnr
- IMPORTING
- output = l_lifnr.
- select count(*) from lfa1 where lifnr = l_lifnr.
- if sy-subrc <> 0.
- lt_tpmsg-type = 'E'.
- concatenate '供應商' l_lifnr '不存在!' into lt_tpmsg-message.
- append lt_tpmsg.
- endif.
- read table lt_tpmsg with key type = 'E'.
- if sy-subrc <> 0.
- w_goodsmvt_item-move_type = '541'."轉包
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-invn_adjmt_qty.
- w_goodsmvt_item-vendor = l_lifnr."供應商
- append w_goodsmvt_item to goodsmvt_item.
- else.
- append lines of lt_tpmsg to lt_retmsg.
- endif.
- endif.
- endloop.
- "執行操作
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- else.
- update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 轉包
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 轉包沖銷
- "&--------------------------------------------------------------------------------------------------------------&
- 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.
- refresh:goodsmvt_item,return,lt_tpmsg,lt_retmsg.
- "事物碼
- goodsmvt_code-gm_code = '04'.
- "頭
- goodsmvt_header-pstng_date = sy-datum.
- goodsmvt_header-doc_date = sy-datum.
- "明細
- 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.
- if pt_tran-ref_field_6 = 'T'.
- clear:l_lifnr.
- refresh:lt_tpmsg.
- l_tran_nbr = pt_tran-tran_nbr.
- l_lifnr = pt_tran-ref_field_7.
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- EXPORTING
- input = l_lifnr
- IMPORTING
- output = l_lifnr.
- select count(*) from lfa1 where lifnr = l_lifnr.
- if sy-subrc <> 0.
- lt_tpmsg-type = 'E'.
- concatenate '供應商' l_lifnr '不存在!' into lt_tpmsg-message.
- append lt_tpmsg.
- endif.
- read table lt_tpmsg with key type = 'E'.
- if sy-subrc <> 0.
- w_goodsmvt_item-move_type = '542'."轉包沖銷
- w_goodsmvt_item-plant = g_plant.
- w_goodsmvt_item-stge_loc = g_stge_loc.
- w_goodsmvt_item-material = pt_tran-matnr.
- w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd.
- w_goodsmvt_item-vendor = l_lifnr."供應商
- append w_goodsmvt_item to goodsmvt_item.
- else.
- append lines of lt_tpmsg to lt_retmsg.
- endif.
- endif.
- endloop.
- "執行操作
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- if goodsmvt_item[] is not initial.
- l_flag = 'F'.
- call function 'BAPI_GOODSMVT_CREATE'
- EXPORTING
- goodsmvt_header = goodsmvt_header
- goodsmvt_code = goodsmvt_code
- IMPORTING
- goodsmvt_headret = goodsmvt_headret
- materialdocument = materialdocument
- matdocumentyear = matdocumentyear
- TABLES
- goodsmvt_item = goodsmvt_item
- return = return.
- read table return with key type = 'E' into w_return.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- if materialdocument is not initial.
- l_flag = 'S'.
- l_matdoc = materialdocument.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- perform writepixtranlog tables return using l_tran_nbr.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc where tran_nbr = l_tran_nbr.
- endif.
- else.
- update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- "&--------------------------------------------------------------------------------------------------------------&
- "& END 轉包沖銷
- "&--------------------------------------------------------------------------------------------------------------&
- "&--------------------------------------------------------------------------------------------------------------&
- "& BEGIN 盤點
- "&--------------------------------------------------------------------------------------------------------------&
- data:l_physinv_head type bapi_physinv_create_head,
- lt_physinv_item like table of bapi_physinv_create_items with header line.
- data:it_count_item like table of bapi_physinv_count_items with header line,
- lt_temp like table of bapi_physinv_count_items with header line,
- l_invdoc type iblnr,
- l_nblnr(10) type c,
- l_count type i.
- "&--------------------------------------------盤點-------------------------------------------------------------&
- "初始化
- 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.
- refresh:lt_physinv_item, lt_retmsg,lt_temp,it_count_item.
- "盤點單頭
- l_physinv_head-plant = g_plant.
- l_physinv_head-stge_loc = g_stge_loc.
- l_physinv_head-doc_date = sy-datum.
- l_physinv_head-plan_date = sy-datum.
- loop at pt_tran where ( ( tran_type = '300' and ( tran_code = '04' or tran_code = '01') and actn_code = '14' )
- or ( tran_type = '300' and tran_code = '04' and actn_code = '' ) ) and invn_adjmt_qty > 0 and tran_nbr = t_tran_nbr-tran_nbr.
- clear:lt_temp.
- l_tran_nbr = pt_tran-tran_nbr.
- "盤點單計數
- lt_temp-material = pt_tran-matnr.
- case pt_tran-invn_adjmt_type.
- when 'A'.
- lt_temp-entry_qnt = pt_tran-invn_adjmt_qty.
- when 'S'.
- lt_temp-entry_qnt = - pt_tran-invn_adjmt_qty.
- endcase.
- collect lt_temp.
- endloop.
- loop at lt_temp.
- add 1 to l_count.
- "初始化
- clear:lt_mard.
- refresh:lt_mard.
- "擷取目前庫存
- call function 'ZLC_GET_STOCK'
- EXPORTING
- p_matnr = lt_temp-material
- p_werks = g_plant
- p_lgort = g_stge_loc
- TABLES
- pt_mard = lt_mard.
- read table lt_mard index 1.
- "盤點處理
- if sy-subrc = 0.
- "盤點單物料
- lt_physinv_item-material = lt_temp-material.
- append lt_physinv_item.
- "盤點單計數
- it_count_item-item = l_count.
- it_count_item-material = lt_temp-material.
- it_count_item-entry_qnt = lt_mard-labst + lt_temp-entry_qnt.
- clear:l_mara.
- call function 'ZLC_GET_MARA'
- EXPORTING
- p_matnr = lt_temp-material
- IMPORTING
- p_mara = l_mara.
- if l_mara is not initial.
- it_count_item-entry_uom = l_mara-meins.
- endif.
- append it_count_item.
- else.
- clear:lt_retmsg.
- lt_retmsg-type = 'E'.
- concatenate '商品' lt_temp-material ',' g_plant ',' g_stge_loc '不存在!' into lt_retmsg-message.
- append lt_retmsg.
- endif.
- endloop.
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- if it_count_item[] is not initial.
- l_flag = 'F'.
- clear:lt_retmsg.
- refresh:lt_retmsg.
- call function 'BAPI_MATPHYSINV_CREATE_MULT'"建立盤點憑證
- exporting
- head = l_physinv_head
- tables
- items = lt_physinv_item
- return = lt_retmsg.
- loop at lt_retmsg.
- if lt_retmsg-type = 'S' and lt_retmsg-id = 'M7'
- and lt_retmsg-number = '710'.
- l_nblnr = lt_retmsg-message_v1.
- shift l_nblnr right deleting trailing space.
- overlay l_nblnr with '0000000000'.
- l_invdoc = l_nblnr.
- endif.
- endloop.
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- clear:lt_retmsg.
- refresh:lt_retmsg.
- call function 'BAPI_MATPHYSINV_COUNT'"輸入盤點數量
- exporting
- physinventory = l_invdoc
- fiscalyear = sy-datum+0(4)
- count_date = sy-datum
- tables
- items = it_count_item
- return = lt_retmsg.
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- clear:lt_retmsg.
- refresh:lt_retmsg.
- call function 'BAPI_MATPHYSINV_POSTDIFF'"處理差異
- exporting
- physinventory = l_invdoc
- fiscalyear = sy-datum+0(4)
- pstng_date = sy-datum
- tables
- return = lt_retmsg.
- read table lt_retmsg with key type = 'E'.
- if sy-subrc <> 0.
- call function 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = 'X'.
- loop at lt_retmsg.
- if lt_retmsg-type = 'S' and lt_retmsg-id = 'M7'
- and lt_retmsg-number = '716'.
- l_nblnr = lt_retmsg-message_v2.
- shift l_nblnr right deleting trailing space.
- overlay l_nblnr with '0000000000'.
- l_matdoc = l_nblnr.
- endif.
- endloop.
- l_flag = 'S'.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- endif.
- update zwttran set flag = l_flag matdoc = l_matdoc iblnr = l_invdoc where tran_nbr = l_tran_nbr.
- if l_flag = 'F'.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- endif.
- else.
- update zwttran set flag = 'F' where tran_nbr = l_tran_nbr.
- perform writepixtranlog tables lt_retmsg using l_tran_nbr.
- endif.
- " &--------------------------------------------------------------------------------------------------------------&
- " & end 報損、報溢、盤點
- " &--------------------------------------------------------------------------------------------------------------&
- endloop.