REPORT ZEF_SKUS .
selection-screen begin of block list with frame title text-001.
parameters: filenam(128) default
'C:\Inetpub\ftproot\comercial\EasyFact\',
sep default '|'.
selection-screen end of block list.
data: int_wmdvsx type table of bapiwmdvs with header line,
int_wmdvex type table of bapiwmdve with header line,
d_wkbst like bapicm61v-wkbst.
data: begin of i_mard occurs 0,
matnr like mard-matnr,
werks like mard-werks,
lgort like mard-lgort,
labst like mard-labst,
meins like mara-meins,
end of i_mard.
data: begin of i_out occurs 0,
line(1000),
end of i_out.
data texto(1000).
data: begin of it_data occurs 0,
matnr like mara-matnr,
bismt like mara-bismt,
matkl like mara-matkl,
meins like mara-meins,
mtart like mara-mtart,
maktx like makt-maktx,
werks like marc-werks,
bwkey like mbew-bwkey,
zplpr like mbew-zplpr,
stprs like mbew-stprs,
verpr like mbew-verpr,
vplpr like mbew-vplpr,
zplpr2 like mbew-zplpr,
peinh like mbew-peinh,
losgr like marc-losgr,
ferth like mara-ferth,
end of it_data.
START-OF-SELECTION.
*MATERIAL AVAILABILITY
perform obtiene_datos.
perform procesa_datos.
perform descarga_datos.
*LISTADO DE MATERIALES
perform obtiene_datos2.
perform procesa_datos2.
perform descarga_datos2.
message s368(00) with 'Terminado'.
*&---------------------------------------------------------------------*
*& Form obtiene_datos
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM obtiene_datos.
select mard~matnr werks lgort labst mara~meins into table i_mard
from mard
inner join mara on mard~matnr = mara~matnr.
ENDFORM. " obtiene_datos
*&---------------------------------------------------------------------*
*& Form procesa_datos
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM procesa_datos.
loop at i_mard.
clear int_wmdvex.
refresh int_wmdvex.
call function 'BAPI_MATERIAL_AVAILABILITY'
exporting
plant = i_mard-werks
material = i_mard-matnr
unit = i_mard-meins
stge_loc = i_mard-lgort
check_rule = 'B'
importing
av_qty_plt = d_wkbst
tables
wmdvsx = int_wmdvsx
wmdvex = int_wmdvex.
read table int_wmdvex index 1.
i_mard-labst = int_wmdvex-com_qty.
if i_mard-labst = 9999999999.
i_mard-labst = 0.
endif.
modify i_mard.
endloop.
delete i_mard where labst = 0.
data tlabst(20).
loop at i_mard.
tlabst = i_mard-labst.
concatenate
i_mard-matnr sep
i_mard-werks sep
i_mard-lgort sep
tlabst sep
i_mard-meins sep
into i_out-line.
condense i_out-line.
append i_out.
endloop.
ENDFORM. " procesa_datos
*&---------------------------------------------------------------------*
*& Form descarga_datos
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM descarga_datos.
data filenam2 like filenam.
concatenate filenam 'MATERIAL_AVAILABILITY.TXT' into filenam2.
open dataset filenam2 for output in text mode.
loop at i_out.
transfer i_out to filenam2.
endloop.
close dataset filenam2.
ENDFORM. " descarga_datos
*&---------------------------------------------------------------------*
*& Form obtiene_datos2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM obtiene_datos2.
select
mara~matnr mara~bismt mara~matkl mara~meins
mara~mtart makt~maktx marc~werks mbew~bwkey
mbew~lplpr mbew~stprs mbew~verpr mbew~vplpr
mbew~zplpr mbew~peinh marc~losgr mara~ferth
into table it_data
from mara
inner join makt
on makt~matnr = mara~matnr
inner join marc
on marc~matnr = makt~matnr
inner join mbew
on mbew~matnr = marc~matnr
and mbew~bwkey = marc~werks.
*where mara~matnr in s_matnr
*and mara~mtart in s_mtart
*and makt~maktx in s_maktx
*and marc~werks in s_werks
*and mbew~stprs in s_stprs
*and mbew~verpr in s_verpr.
ENDFORM. " obtiene_datos2
*&---------------------------------------------------------------------*
*& Form descarga_datos2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM descarga_datos2.
data filenam2 like filenam.
concatenate filenam 'SKU.TXT' into filenam2.
open dataset filenam2 for output in text mode.
loop at i_out.
transfer i_out to filenam2.
endloop.
close dataset filenam2.
ENDFORM. " descarga_datos2
*&---------------------------------------------------------------------*
*& Form procesa_datos2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM procesa_datos2.
data: t1(20),t2(20),t3(20),t4(20),t5(20),t6(20),t7(20).
clear i_out.
refresh i_out.
loop at it_data.
t1 = it_data-zplpr.
t2 = it_data-stprs.
t3 = it_data-verpr.
t4 = it_data-vplpr.
t5 = it_data-zplpr2.
t6 = it_data-peinh.
t7 = it_data-losgr.
concatenate
it_data-matnr sep
it_data-bismt sep
it_data-matkl sep
it_data-meins sep
it_data-mtart sep
it_data-maktx sep
it_data-werks sep
it_data-bwkey sep
t1 sep
t2 sep
t3 sep
t4 sep
t5 sep
t6 sep
t7 sep
it_data-ferth sep
into i_out-line.
condense i_out-line.
append i_out.
endloop.
ENDFORM. " procesa_datos2