*&---------------------------------------------------------------------*
*& Progarm : zmm_goods_issue_311 Author : Jimmy Wong
*& Created : 16 Apr 2013 App : MM
*& Title : Mass inventory transfer - 311
*& Description : Mass inventory transfer - 311
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 16 Apr 2013 the first version
*& the last update time 2013.04.16 19:00
*&---------------------------------------------------------------------*
report zmm_goods_issue_311.
tables:mseg,mkpf.
data:begin of it_mchb occurs 0,
group type c length 30 ,
matnr like mara-matnr, "material
werks like marc-werks, "Plant
lgort like mchb-lgort,
lgort_t like mchb-lgort,
charg like mchb-charg ,
sobkz like mspr-sobkz,
pspnr like mspr-pspnr,
lifnr like mkol-lifnr,
clabs like mchb-clabs, "
mtart like mara-mtart,
message type c length 255,
end of it_mchb.
data: itab like table of it_mchb with header line.
data:begin of it_gp occurs 0,
group type c length 30 ,
werks like marc-werks,
lgort like mchb-lgort,
sobkz like mspr-sobkz,
message type c length 255,
end of it_gp.
constants: c_per type i value '50'.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
define alv_field.
clear:wa_hier.
wa_hier-fieldname = &1.
wa_hier-seltext_m = &2.
wa_hier-seltext_l = &3.
wa_hier-outputlen = &4.
wa_hier-just = &5.
wa_hier-do_sum = &6.
wa_hier-ref_tabname = &7 .
wa_hier-ref_fieldname = &8 .
append wa_hier to fc_hier.
end-of-definition.
selection-screen begin of block 1 with frame title text-001.
parameters:p_werks like mseg-werks default '8101' obligatory.
select-options: s_matnr for mseg-matnr,
s_lgort for mseg-lgort,
s_charg FOR mseg-charg.
parameters:p_lgort like mseg-lgort obligatory.
parameters: p_test as checkbox default 'X'.
selection-screen end of block 1.
start-of-selection.
perform get_stock_data.
if it_mchb[] is initial.
message i003(zmm).
exit.
endif.
perform get_data.
if p_test is initial.
perform process_data.
endif.
perform display_data.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_stock_data .
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Data........'.
" main stock
select a~matnr a~werks a~lgort a~charg a~clabs b~mtart
into corresponding fields of table it_mchb
from mchb as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks = p_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~clabs > 0.
" project stock - Q
select a~matnr a~werks a~lgort a~charg a~sobkz a~pspnr a~prlab as clabs b~mtart
appending corresponding fields of table it_mchb
from mspr as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks = p_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~prlab > 0.
" project stock - K
select a~matnr a~werks a~lgort a~charg a~sobkz a~lifnr a~slabs as clabs b~mtart
appending corresponding fields of table it_mchb
from mkol as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks = p_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~slabs > 0.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
data:lv_i type i,
lv_j type i,
lv_lgort like mseg-lgort,
lv_sobkz like mseg-sobkz.
sort it_mchb by werks sobkz lgort .
loop at it_mchb.
if lv_i > c_per or lv_lgort ne it_mchb-lgort or lv_sobkz ne it_mchb-sobkz .
lv_i = 1.
lv_j = lv_j + 1.
endif.
it_mchb-group = lv_j .
condense it_mchb-group.
concatenate 'A' it_mchb-group into it_mchb-group.
it_mchb-lgort_t = p_lgort.
move-corresponding it_mchb to itab.
move-corresponding it_mchb to it_gp.
collect it_gp.
append itab.
lv_lgort = it_mchb-lgort .
lv_sobkz = it_mchb-sobkz.
lv_i = lv_i + 1.
endloop.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
data:it_gdmvt_head like bapi2017_gm_head_01,
it_afs_item like bapi2017_gm_item_create
occurs 0 with header line,
it_serial like bapi2017_gm_serialnumber occurs 0 with header line,
lv_mdoc like bapi2017_gm_head_ret-mat_doc,
lv_year like bapi2017_gm_head_ret-doc_year,
it_ret like bapi2017_gm_head_ret.
data:it_gdmvt_code like bapi2017_gm_code value '04'.
data:it_return like bapiret2 occurs 0 with header line.
data: lv_sernr type mase-lsernr,
lv_j type i,
lv_posid like prps-posid,
lv_tabix like sy-tabix.
loop at it_gp.
lv_tabix = sy-tabix.
it_gdmvt_head-pstng_date = sy-datum. " posting date
it_gdmvt_head-doc_date = sy-datum. "docmunt date
loop at itab where group = it_gp-group and werks = it_gp-werks and lgort = it_gp-lgort and sobkz = it_gp-sobkz.
clear: lv_sernr,lv_j,lv_posid.
select single lsernr into lv_sernr
from mase
where matnr = itab-matnr.
if sy-subrc ne 0.
lv_sernr = 0.
endif.
if it_gp-sobkz = 'Q'.
it_afs_item-spec_stock = itab-sobkz. "Special Stock
perform transform_wbs using itab-pspnr 'X' changing lv_posid.
it_afs_item-val_wbs_elem = lv_posid."Production Lot
it_afs_item-wbs_elem = lv_posid."Production Lot
elseif it_gp-sobkz = 'K'.
it_afs_item-spec_stock = itab-sobkz. "Special Stock
it_afs_item-vendor = itab-lifnr."Vendor
endif.
it_afs_item-material = itab-matnr. " Material Code
it_afs_item-plant = itab-werks . "Plant
it_afs_item-stge_loc = itab-lgort. "Storage Location
it_afs_item-batch = itab-charg. "goodsmvt_data-rfid_batch' .
it_afs_item-move_type = '311'. "Move type"
it_afs_item-entry_qnt = itab-clabs . " Quantity
it_afs_item-move_stloc = itab-lgort_t. "Tranfer Storage Location
append it_afs_item.
"80* 85* material
lv_j = itab-clabs.
do lv_j times .
lv_sernr = lv_sernr + 1 .
it_serial-matdoc_itm = 1.
it_serial-serialno = lv_sernr.
perform add_pre_zero using it_serial-serialno
changing it_serial-serialno.
append it_serial.
clear:it_serial.
enddo.
endloop.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = it_gdmvt_head
goodsmvt_code = it_gdmvt_code
importing
materialdocument = lv_mdoc
matdocumentyear = lv_year
tables
goodsmvt_item = it_afs_item
goodsmvt_serialnumber = it_serial
return = it_return.
read table it_return with key type = 'E'.
if sy-subrc eq 0.
loop at it_return where type = 'E'.
concatenate it_gp-message ' E: ' it_return-message into it_gp-message.
endloop.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
it_gp-message = lv_mdoc.
endif.
modify it_gp index lv_tabix .
clear: it_gdmvt_head,lv_mdoc,lv_year,it_afs_item,it_afs_item[],it_serial,it_return,it_serial[],it_return[].
endloop.
loop at itab.
read table it_gp with key group = itab-group binary search.
if sy-subrc eq 0 .
itab-message = it_gp-message.
modify itab.
endif .
endloop.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
refresh: fc_hier.
alv_field 'WERKS' '' 'Plant' '6' 'L' '' '' ''.
alv_field 'MATNR' '' 'Material' '18' 'L' '' 'MARA' 'MATNR'.
alv_field 'LGORT' '' 'Stor. Loc.' '10' 'L' '' '' ''.
alv_field 'LGORT_T' '' 'Tran. Stor. Loc.' '10' 'L' '' '' ''.
alv_field 'CHARG' '' 'Batch' '10' 'L' '' '' ''.
alv_field 'SOBKZ' '' 'Special Stock' '6' 'L' '' '' ''.
alv_field 'PSPNR' '' 'WBS Element' '10' 'L' '' 'PRPS' 'PSPNR'.
alv_field 'LIFNR' '' 'Vendor' '10' 'L' '' 'LIFNR' 'LFA1'.
alv_field 'CLABS' '' 'Qty' '15' 'R' '' '' ''.
alv_field 'MESSAGE' 'Message' '' '50' 'L' '' '' ''.
sort itab by werks matnr sobkz lgort .
perform display_alv tables fc_hier itab using 'A'.
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FC_HIER text
* -->ITAB text
* -->P_SAVE text
*----------------------------------------------------------------------*
form display_alv tables fc_hier itab
using p_save .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
i_save = p_save
i_callback_program = sy-repid
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
endform. "display_alv
*&---------------------------------------------------------------------*
*& Form ADD_PRE_ZERO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_RECORD_CHARG text
* <--P_IT_RECORD_CHARG text
*----------------------------------------------------------------------*
form add_pre_zero using p_old
changing p_new .
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = p_old
importing
output = p_new.
endform. " ADD_PRE_ZERO
*&---------------------------------------------------------------------*
*& Form transform_wbs
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_OLD text
* -->P_OUTPUT text
* -->P_NEW text
*----------------------------------------------------------------------*
form transform_wbs using p_old
p_output
changing p_new.
check p_old is not initial.
if p_output = 'X'.
call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
exporting
input = p_old
importing
output = p_new.
else.
data:lv_input type c length 50.
lv_input = p_old.
translate lv_input to upper case.
call function 'CONVERSION_EXIT_ABPSP_INPUT'
exporting
input = lv_input
importing
output = p_new
exceptions
not_found = 1
others = 2.
if sy-subrc <> 0.
clear:p_new.
endif.
endif.
endform. "transform_wbs
*& Progarm : zmm_goods_issue_311 Author : Jimmy Wong
*& Created : 16 Apr 2013 App : MM
*& Title : Mass inventory transfer - 311
*& Description : Mass inventory transfer - 311
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 16 Apr 2013 the first version
*& the last update time 2013.04.16 19:00
*&---------------------------------------------------------------------*
report zmm_goods_issue_311.
tables:mseg,mkpf.
data:begin of it_mchb occurs 0,
group type c length 30 ,
matnr like mara-matnr, "material
werks like marc-werks, "Plant
lgort like mchb-lgort,
lgort_t like mchb-lgort,
charg like mchb-charg ,
sobkz like mspr-sobkz,
pspnr like mspr-pspnr,
lifnr like mkol-lifnr,
clabs like mchb-clabs, "
mtart like mara-mtart,
message type c length 255,
end of it_mchb.
data: itab like table of it_mchb with header line.
data:begin of it_gp occurs 0,
group type c length 30 ,
werks like marc-werks,
lgort like mchb-lgort,
sobkz like mspr-sobkz,
message type c length 255,
end of it_gp.
constants: c_per type i value '50'.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
define alv_field.
clear:wa_hier.
wa_hier-fieldname = &1.
wa_hier-seltext_m = &2.
wa_hier-seltext_l = &3.
wa_hier-outputlen = &4.
wa_hier-just = &5.
wa_hier-do_sum = &6.
wa_hier-ref_tabname = &7 .
wa_hier-ref_fieldname = &8 .
append wa_hier to fc_hier.
end-of-definition.
selection-screen begin of block 1 with frame title text-001.
parameters:p_werks like mseg-werks default '8101' obligatory.
select-options: s_matnr for mseg-matnr,
s_lgort for mseg-lgort,
s_charg FOR mseg-charg.
parameters:p_lgort like mseg-lgort obligatory.
parameters: p_test as checkbox default 'X'.
selection-screen end of block 1.
start-of-selection.
perform get_stock_data.
if it_mchb[] is initial.
message i003(zmm).
exit.
endif.
perform get_data.
if p_test is initial.
perform process_data.
endif.
perform display_data.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_stock_data .
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Data........'.
" main stock
select a~matnr a~werks a~lgort a~charg a~clabs b~mtart
into corresponding fields of table it_mchb
from mchb as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks = p_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~clabs > 0.
" project stock - Q
select a~matnr a~werks a~lgort a~charg a~sobkz a~pspnr a~prlab as clabs b~mtart
appending corresponding fields of table it_mchb
from mspr as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks = p_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~prlab > 0.
" project stock - K
select a~matnr a~werks a~lgort a~charg a~sobkz a~lifnr a~slabs as clabs b~mtart
appending corresponding fields of table it_mchb
from mkol as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks = p_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~slabs > 0.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
data:lv_i type i,
lv_j type i,
lv_lgort like mseg-lgort,
lv_sobkz like mseg-sobkz.
sort it_mchb by werks sobkz lgort .
loop at it_mchb.
if lv_i > c_per or lv_lgort ne it_mchb-lgort or lv_sobkz ne it_mchb-sobkz .
lv_i = 1.
lv_j = lv_j + 1.
endif.
it_mchb-group = lv_j .
condense it_mchb-group.
concatenate 'A' it_mchb-group into it_mchb-group.
it_mchb-lgort_t = p_lgort.
move-corresponding it_mchb to itab.
move-corresponding it_mchb to it_gp.
collect it_gp.
append itab.
lv_lgort = it_mchb-lgort .
lv_sobkz = it_mchb-sobkz.
lv_i = lv_i + 1.
endloop.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
data:it_gdmvt_head like bapi2017_gm_head_01,
it_afs_item like bapi2017_gm_item_create
occurs 0 with header line,
it_serial like bapi2017_gm_serialnumber occurs 0 with header line,
lv_mdoc like bapi2017_gm_head_ret-mat_doc,
lv_year like bapi2017_gm_head_ret-doc_year,
it_ret like bapi2017_gm_head_ret.
data:it_gdmvt_code like bapi2017_gm_code value '04'.
data:it_return like bapiret2 occurs 0 with header line.
data: lv_sernr type mase-lsernr,
lv_j type i,
lv_posid like prps-posid,
lv_tabix like sy-tabix.
loop at it_gp.
lv_tabix = sy-tabix.
it_gdmvt_head-pstng_date = sy-datum. " posting date
it_gdmvt_head-doc_date = sy-datum. "docmunt date
loop at itab where group = it_gp-group and werks = it_gp-werks and lgort = it_gp-lgort and sobkz = it_gp-sobkz.
clear: lv_sernr,lv_j,lv_posid.
select single lsernr into lv_sernr
from mase
where matnr = itab-matnr.
if sy-subrc ne 0.
lv_sernr = 0.
endif.
if it_gp-sobkz = 'Q'.
it_afs_item-spec_stock = itab-sobkz. "Special Stock
perform transform_wbs using itab-pspnr 'X' changing lv_posid.
it_afs_item-val_wbs_elem = lv_posid."Production Lot
it_afs_item-wbs_elem = lv_posid."Production Lot
elseif it_gp-sobkz = 'K'.
it_afs_item-spec_stock = itab-sobkz. "Special Stock
it_afs_item-vendor = itab-lifnr."Vendor
endif.
it_afs_item-material = itab-matnr. " Material Code
it_afs_item-plant = itab-werks . "Plant
it_afs_item-stge_loc = itab-lgort. "Storage Location
it_afs_item-batch = itab-charg. "goodsmvt_data-rfid_batch' .
it_afs_item-move_type = '311'. "Move type"
it_afs_item-entry_qnt = itab-clabs . " Quantity
it_afs_item-move_stloc = itab-lgort_t. "Tranfer Storage Location
append it_afs_item.
"80* 85* material
lv_j = itab-clabs.
do lv_j times .
lv_sernr = lv_sernr + 1 .
it_serial-matdoc_itm = 1.
it_serial-serialno = lv_sernr.
perform add_pre_zero using it_serial-serialno
changing it_serial-serialno.
append it_serial.
clear:it_serial.
enddo.
endloop.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = it_gdmvt_head
goodsmvt_code = it_gdmvt_code
importing
materialdocument = lv_mdoc
matdocumentyear = lv_year
tables
goodsmvt_item = it_afs_item
goodsmvt_serialnumber = it_serial
return = it_return.
read table it_return with key type = 'E'.
if sy-subrc eq 0.
loop at it_return where type = 'E'.
concatenate it_gp-message ' E: ' it_return-message into it_gp-message.
endloop.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
it_gp-message = lv_mdoc.
endif.
modify it_gp index lv_tabix .
clear: it_gdmvt_head,lv_mdoc,lv_year,it_afs_item,it_afs_item[],it_serial,it_return,it_serial[],it_return[].
endloop.
loop at itab.
read table it_gp with key group = itab-group binary search.
if sy-subrc eq 0 .
itab-message = it_gp-message.
modify itab.
endif .
endloop.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
refresh: fc_hier.
alv_field 'WERKS' '' 'Plant' '6' 'L' '' '' ''.
alv_field 'MATNR' '' 'Material' '18' 'L' '' 'MARA' 'MATNR'.
alv_field 'LGORT' '' 'Stor. Loc.' '10' 'L' '' '' ''.
alv_field 'LGORT_T' '' 'Tran. Stor. Loc.' '10' 'L' '' '' ''.
alv_field 'CHARG' '' 'Batch' '10' 'L' '' '' ''.
alv_field 'SOBKZ' '' 'Special Stock' '6' 'L' '' '' ''.
alv_field 'PSPNR' '' 'WBS Element' '10' 'L' '' 'PRPS' 'PSPNR'.
alv_field 'LIFNR' '' 'Vendor' '10' 'L' '' 'LIFNR' 'LFA1'.
alv_field 'CLABS' '' 'Qty' '15' 'R' '' '' ''.
alv_field 'MESSAGE' 'Message' '' '50' 'L' '' '' ''.
sort itab by werks matnr sobkz lgort .
perform display_alv tables fc_hier itab using 'A'.
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FC_HIER text
* -->ITAB text
* -->P_SAVE text
*----------------------------------------------------------------------*
form display_alv tables fc_hier itab
using p_save .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
i_save = p_save
i_callback_program = sy-repid
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
endform. "display_alv
*&---------------------------------------------------------------------*
*& Form ADD_PRE_ZERO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_RECORD_CHARG text
* <--P_IT_RECORD_CHARG text
*----------------------------------------------------------------------*
form add_pre_zero using p_old
changing p_new .
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = p_old
importing
output = p_new.
endform. " ADD_PRE_ZERO
*&---------------------------------------------------------------------*
*& Form transform_wbs
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_OLD text
* -->P_OUTPUT text
* -->P_NEW text
*----------------------------------------------------------------------*
form transform_wbs using p_old
p_output
changing p_new.
check p_old is not initial.
if p_output = 'X'.
call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
exporting
input = p_old
importing
output = p_new.
else.
data:lv_input type c length 50.
lv_input = p_old.
translate lv_input to upper case.
call function 'CONVERSION_EXIT_ABPSP_INPUT'
exporting
input = lv_input
importing
output = p_new
exceptions
not_found = 1
others = 2.
if sy-subrc <> 0.
clear:p_new.
endif.
endif.
endform. "transform_wbs

此程序实现批量库存转移311操作,通过获取指定物料、工厂、仓位等信息,进行库存转移,并生成相关数据记录。
1151

被折叠的 条评论
为什么被折叠?



