report y_salidas_de_almacen
no standard page heading
message-id zm
line-count 065
line-size 080.
***************************** ALV **************************************
type-pools: slis.
data: alv_fieldtab type slis_t_fieldcat_alv,
alv_heading type slis_t_listheader,
alv_layout type slis_layout_alv,
alv_events type slis_t_event,
alv_sort type slis_t_sortinfo_alv,
alv_filter type slis_t_filter_alv,
alv_repname like sy-repid,
alv_f2code like sy-ucomm value '&ETA',
alv_g_save(1) type c,
alv_g_exit(1) type c,
alv_g_variant like disvariant,
alv_gx_variant like disvariant.
data: alv_fieldcat type slis_fieldcat_alv.
************************************************************************
*------TABLAS/ESTRUCTURAS----------------------------------------------*
tables: ekbe,
mseg,
ekko,
ekpo,
mkpf,
lfa1,
makt.
*------TABLAS INTERNAS-------------------------------------------------*
* tablas internas
data: begin of i_pedidos occurs 100,
charg like mseg-charg,
lifnr like mseg-lifnr,
matnr like mseg-matnr,
ebeln like anek-ebeln,
ebelp like anek-ebelp,
budat like ekbe-budat,
menge like ekpo-menge, "Cantidad original
meins like ekpo-meins,
bwart like mseg-bwart,
mblnr like iseg-mblnr,
mjahr like iseg-mjahr,
zeile like iseg-zeile,
cmov like ekpo-menge,
crest like ekpo-menge,
end of i_pedidos.
data: begin of i_listado occurs 100,
lifnr like mseg-lifnr,
matnr like mseg-matnr,
bwart like mseg-bwart,
mblnr like iseg-mblnr,
mjahr like iseg-mjahr,
zeile like iseg-zeile,
budat_e like ekbe-budat,
ebeln like anek-ebeln,
ebelp like anek-ebelp,
menge_e like ekpo-menge, "Cantidad original
meins like ekpo-meins,
charg like mseg-charg,
budat_s like ekbe-budat,
menge_s like ekpo-menge, "Cantidad original
color type slis_t_specialcol_alv,
end of i_listado.
data: begin of i_aux occurs 100,
charg like mseg-charg,
lifnr like mseg-lifnr,
matnr like mseg-matnr,
ebeln like anek-ebeln,
ebelp like anek-ebelp,
cmov like ekpo-menge,
end of i_aux.
*------VARIABLES-------------------------------------------------------*
data: l_listado_ant like i_listado.
*------PARAMETER/SELECT-OPTIONS EN PANTALLA----------------------------*
selection-screen begin of block blk_par with frame title text-002. "Pará
select-options: s_bukrs for ekko-bukrs default '1120',
s_lifnr for ekko-lifnr, "Proveedor
s_matnr for ekpo-matnr, "Material
s_charg for mseg-charg.
selection-screen end of block blk_par.
**************************** ALV ***************************************
data p_vari like disvariant-variant. "Display variant
************************************************************************
************************************************************************
*
* LOGICA DEL PROGRAMA
*
************************************************************************
*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
initialization.
**************************** ALV ***************************************
alv_repname = sy-repid.
perform initialize_fieldcat1 using alv_fieldtab[].
perform alv_build_eventtab using alv_events[] '1'.
* PERFORM BUILD_COMMENT USING ALV_HEADING[].
perform alv_initialize_variant.
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
* PERFORM alv_f4_for_variant.
************************************************************************
at selection-screen.
***************************** ALV **************************************
* perform alv_pai_of_selection_screen.
************************************************************************
*----------------------------------------------------------------------
* START-OF-SELECTION.
*----------------------------------------------------------------------*
start-of-selection.
perform seleccion_datos.
***************************** ALV **************************************
perform alv_build_layout using alv_layout.
perform alv_sortinfo tables alv_sort.
alv_layout-coltab_fieldname = 'COLOR'.
perform alv_write_output tables i_listado using 'I_LISTADO'.
************************************************************************
************************************************************************
*
* FORMS ADICIONALES
*
************************************************************************
*&---------------------------------------------------------------------*
*& Form SELECCION_DATOS
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form seleccion_datos.
data: i_mseg like mseg occurs 20 with header line,
i_ekbe like ekbe occurs 20 with header line.
data: l_cmov like ekpo-menge,
l_crest like ekpo-menge,
l_menge like ekpo-menge.
* Recuperamos todos los 101
select * from mseg
into table i_mseg
where xauto = ''
and bwart in ('101','102')
and charg in s_charg
and matnr in s_matnr
and lifnr in s_lifnr.
sort i_mseg.
free i_ekbe.
loop at i_mseg.
select * from ekbe
appending table i_ekbe
where gjahr = i_mseg-gjahr
and belnr = i_mseg-mblnr
and buzei = i_mseg-zeile
and bwart = i_mseg-bwart.
endloop.
sort i_ekbe.
free i_pedidos.
loop at i_ekbe.
at new ebelp.
select single lifnr from ekko
into ekko-lifnr
where ebeln = i_ekbe-ebeln.
select single menge meins from ekpo
into (ekpo-menge, ekpo-meins)
where ebeln = i_ekbe-ebeln
and ebelp = i_ekbe-ebelp.
clear l_crest.
endat.
clear i_pedidos.
i_pedidos-ebeln = i_ekbe-ebeln.
i_pedidos-ebelp = i_ekbe-ebelp.
i_pedidos-menge = ekpo-menge.
i_pedidos-meins = ekpo-meins.
i_pedidos-charg = i_ekbe-charg.
i_pedidos-matnr = i_ekbe-matnr.
i_pedidos-lifnr = ekko-lifnr.
i_pedidos-budat = i_ekbe-budat.
i_pedidos-bwart = i_ekbe-bwart.
i_pedidos-mblnr = i_ekbe-belnr.
i_pedidos-mjahr = i_ekbe-gjahr.
i_pedidos-zeile = i_ekbe-buzei.
if i_ekbe-bwart = '101'.
i_pedidos-cmov = i_ekbe-menge.
add i_ekbe-menge to l_crest.
else.
i_pedidos-cmov = - i_ekbe-menge.
subtract i_ekbe-menge from l_crest.
endif.
i_pedidos-crest = l_crest.
append i_pedidos.
move-corresponding i_pedidos to i_aux.
collect i_aux.
endloop.
sort i_pedidos.
select * from mseg
into table i_mseg
where xauto = ''
and bwart in ('411','412')
and charg in s_charg
and matnr in s_matnr
and lifnr in s_lifnr.
sort i_mseg.
loop at i_mseg.
select single budat from mkpf
into mkpf-budat
where mblnr = i_mseg-mblnr
and mjahr = i_mseg-mjahr.
sort i_aux.
loop at i_aux where charg = i_mseg-charg
and lifnr = i_mseg-lifnr
and matnr = i_mseg-matnr.
if i_mseg-bwart = '411' and
i_aux-cmov >= i_mseg-menge.
move-corresponding i_aux to i_pedidos.
i_pedidos-budat = mkpf-budat.
i_pedidos-bwart = i_mseg-bwart.
i_pedidos-mblnr = i_mseg-mblnr.
i_pedidos-mjahr = i_mseg-mjahr.
i_pedidos-zeile = i_mseg-zeile.
i_pedidos-cmov = - i_mseg-menge.
i_pedidos-crest = i_aux-cmov - i_mseg-menge.
move-corresponding i_pedidos to i_aux.
collect i_aux.
append i_pedidos.
exit.
endif.
if i_mseg-bwart = '412' and
i_aux-cmov > i_mseg-menge.
move-corresponding i_aux to i_pedidos.
i_pedidos-budat = mkpf-budat.
i_pedidos-bwart = i_mseg-bwart.
i_pedidos-mblnr = i_mseg-mblnr.
i_pedidos-mjahr = i_mseg-mjahr.
i_pedidos-zeile = i_mseg-zeile.
i_pedidos-cmov = i_mseg-menge.
i_pedidos-crest = i_aux-cmov + i_mseg-menge.
move-corresponding i_pedidos to i_aux.
collect i_aux.
append i_pedidos.
exit.
endif.
endloop.
if sy-subrc ne 0.
clear i_pedidos.
i_pedidos-meins = 'ST'.
i_pedidos-budat = mkpf-budat.
i_pedidos-charg = i_mseg-charg.
i_pedidos-matnr = i_mseg-matnr.
i_pedidos-lifnr = i_mseg-lifnr.
i_pedidos-bwart = i_mseg-bwart.
i_pedidos-mblnr = i_mseg-mblnr.
i_pedidos-mjahr = i_mseg-mjahr.
i_pedidos-zeile = i_mseg-zeile.
i_pedidos-cmov = i_mseg-menge.
move-corresponding i_pedidos to i_aux.
collect i_aux.
append i_pedidos.
endif.
endloop.
sort i_pedidos.
loop at i_pedidos.
clear i_listado.
move-corresponding i_pedidos to i_listado.
if i_pedidos-bwart = '101' or
i_pedidos-bwart = '102'.
i_listado-budat_e = i_pedidos-budat.
i_listado-menge_e = i_pedidos-menge.
else.
i_listado-budat_s = i_pedidos-budat.
i_listado-menge_s = i_pedidos-menge.
clear: i_listado-ebeln, i_listado-ebelp.
endif.
append i_listado.
endloop.
****************************** ALV ******************************
* Cambia colores de algunas celdas determinadas
data: color type slis_specialcol_alv.
loop at i_listado.
case i_listado-bwart.
when '101'.
clear color.
color-fieldname = 'BWART'.
color-color-col = 1.
append color to i_listado-color.
color-fieldname = 'BUDAT_E'.
color-color-col = 1.
append color to i_listado-color.
color-fieldname = 'MENGE_E'.
color-color-col = 1.
append color to i_listado-color.
when '102'.
clear color.
color-fieldname = 'BWART'.
color-color-col = 6.
append color to i_listado-color.
color-fieldname = 'BUDAT_E'.
color-color-col = 6.
append color to i_listado-color.
color-fieldname = 'MENGE_E'.
color-color-col = 6.
append color to i_listado-color.
when '411'.
clear color.
color-fieldname = 'BWART'.
color-color-col = 3.
append color to i_listado-color.
color-fieldname = 'BUDAT_S'.
color-color-col = 3.
append color to i_listado-color.
color-fieldname = 'MENGE_S'.
color-color-col = 3.
append color to i_listado-color.
when '412'.
clear color.
color-fieldname = 'BWART'.
color-color-col = 7.
append color to i_listado-color.
color-fieldname = 'BUDAT_S'.
color-color-col = 7.
append color to i_listado-color.
color-fieldname = 'MENGE_S'.
color-color-col = 7.
append color to i_listado-color.
endcase.
modify i_listado.
endloop.
*****************************************************************
endform. " SELECCIONAR_DATOS
***************************** ALV *************************************
*---------------------------------------------------------------------*
* FORM initialize_fieldcat1 *
*---------------------------------------------------------------------*
* Cambia los atributos por defecto de algunos campos
*---------------------------------------------------------------------*
form initialize_fieldcat1 using p_fieldtab type slis_t_fieldcat_alv.
define fieldcat_no_out.
clear alv_fieldcat.
alv_fieldcat-tabname = 'I_LISTADO'.
alv_fieldcat-fieldname = &1.
alv_fieldcat-no_out = 'X'.
append alv_fieldcat to p_fieldtab.
end-of-definition.
free alv_fieldtab.
fieldcat_no_out: 'LIFNR', 'MATNR', 'MEINS'.
clear alv_fieldcat.
alv_fieldcat-tabname = 'I_LISTADO'.
alv_fieldcat-fieldname = 'MENGE_E'.
alv_fieldcat-outputlen = 14.
alv_fieldcat-no_zero = 'X'.
alv_fieldcat-do_sum = 'X'.
append alv_fieldcat to p_fieldtab.
clear alv_fieldcat.
alv_fieldcat-tabname = 'I_LISTADO'.
alv_fieldcat-fieldname = 'MENGE_S'.
alv_fieldcat-outputlen = 14.
alv_fieldcat-no_zero = 'X'.
alv_fieldcat-do_sum = 'X'.
append alv_fieldcat to p_fieldtab.
clear alv_fieldcat.
endform. " INITIALIZE_FIELDCAT
*&---------------------------------------------------------------------*
*& Form BUILD_COMMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_HEADING[] text *
*----------------------------------------------------------------------*
form build_comment using p_heading type slis_t_listheader.
data: hline type slis_listheader,
text(60) type c,
sep(20) type c.
clear: hline, text.
hline-typ = 'H'.
write: 'List of Pending Deliveries' to text+05.
hline-info = text.
append hline to p_heading.
clear text.
write: 'User: ' to text,
sy-uname to text+9,
'Date: ' to text+30,
sy-datum to text+37,
'Page: ' to text+50,
sy-pagno to text+56.
hline-info = text.
append hline to p_heading.
endform. " BUILD_COMMENT
*&---------------------------------------------------------------------*
*& Form BUILD_EVENTTAB
*&---------------------------------------------------------------------*
* Inicializa las rutinas de los eventos del listado ALV
*----------------------------------------------------------------------*
form alv_build_eventtab using p_events type slis_t_event
p_tabla.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = p_events.
read table p_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move slis_ev_top_of_page to ls_event-form.
modify p_events from ls_event index sy-tabix.
endif.
read table p_events with key name = 'TOP_OF_PAGE'
into ls_event.
if sy-subrc = 0.
move 'TOP_OF_PAGE' to ls_event-form.
modify p_events from ls_event index sy-tabix.
endif.
read table p_events with key name = slis_ev_before_line_output
into ls_event.
if sy-subrc = 0.
move 'ANTES_ESCRIBIR_LINEA' to ls_event-form.
modify p_events from ls_event index sy-tabix.
endif.
endform. " BUILD_EVENTTAB
*---------------------------------------------------------------------*
* FORM ANTES_ESCRIBIR_LINEA *
*---------------------------------------------------------------------*
* Rutina que se ejecuta antes de escribir una nueva línea
*---------------------------------------------------------------------*
form antes_escribir_linea using p_c type slis_lineinfo.
check p_c-subtot is initial.
if not l_listado_ant is initial.
if l_listado_ant-lifnr ne i_listado-lifnr or
l_listado_ant-matnr ne i_listado-matnr.
uline.
new-page.
endif.
endif.
l_listado_ant = i_listado.
endform.
*---------------------------------------------------------------------**
* FORM TOP_OF_PAGE
**---------------------------------------------------------------------*
form top_of_page.
data: lt_commentary type slis_t_listheader with header line.
** Header
* lt_commentary-typ = 'H'. "-- Creo que lo muestra en negrita
* lt_commentary-info = 'Stock valorado por almacén'.
* APPEND lt_commentary.
* CLEAR lt_commentary.
**
lt_commentary-typ = 'S'.
lt_commentary-key = 'Proveedor'.
clear makt.
select single * from lfa1
where lifnr = i_listado-lifnr.
concatenate i_listado-lifnr lfa1-name1 into lt_commentary-info
separated by space.
append lt_commentary.
clear lt_commentary.
**
lt_commentary-typ = 'S'.
lt_commentary-key = 'Material'.
clear makt.
select single * from makt
where matnr = i_listado-matnr
and spras = sy-langu.
concatenate i_listado-matnr makt-maktx into lt_commentary-info
separated by space.
append lt_commentary.
clear lt_commentary.
**
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = lt_commentary[]
* I_LOGO =
i_end_of_list_grid = 'X'.
write: /60 'ENTRADAS',
90 'SALIDAS'.
.
endform.
*---------------------------------------------------------------------*
* FORM alv_sortinfo *
*---------------------------------------------------------------------*
* Criterios de ordenación
*---------------------------------------------------------------------*
form alv_sortinfo tables p_alv_sort type slis_t_sortinfo_alv.
data sortinfo_alv type slis_sortinfo_alv.
* CLEAR sortinfo_alv.
* sortinfo_alv-spos = '1'.
* sortinfo_alv-fieldname = 'LIFNR'.
* sortinfo_alv-tabname = 'I_LISTADO'.
* sortinfo_alv-subtot = 'X'.
* sortinfo_alv-up = 'X'.
* APPEND sortinfo_alv TO p_alv_sort.
clear sortinfo_alv.
sortinfo_alv-spos = '1'.
sortinfo_alv-fieldname = 'MATNR'.
sortinfo_alv-tabname = 'I_LISTADO'.
sortinfo_alv-up = 'X'.
sortinfo_alv-subtot = 'X'.
append sortinfo_alv to p_alv_sort.
endform. " ALV_SORTINFO
*---------------------------------------------------------------------*
* FORM alv_set_pf_status *
*---------------------------------------------------------------------*
* Estatus
*---------------------------------------------------------------------*
form pf_status_set
using pu_tab_excl_okcode type slis_t_extab.
set pf-status 'STANDARD' excluding pu_tab_excl_okcode.
endform.
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LAYOUT text *
*----------------------------------------------------------------------*
form alv_build_layout using p_layout type slis_layout_alv.
p_layout-f2code = alv_f2code.
p_layout-zebra = 'X'.
p_layout-detail_popup = 'X'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form WRITE_OUTPUT
*&---------------------------------------------------------------------*
* Rutina de salida
*----------------------------------------------------------------------*
form alv_write_output tables pi_tabla
using pe_tabla.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = alv_repname
i_internal_tabname = pe_tabla
i_inclname = alv_repname
changing
ct_fieldcat = alv_fieldtab.
if sy-subrc <> 0.
write: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_FIELDCATALOG_MERGE'.
endif.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = alv_repname
i_structure_name = pe_tabla
is_layout = alv_layout
it_fieldcat = alv_fieldtab
i_default = 'A'
i_save = alv_g_save
is_variant = alv_g_variant
it_events = alv_events[]
it_sort = alv_sort
it_filter = alv_filter
tables
t_outtab = pi_tabla.
if sy-subrc <> 0.
write: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_LIST_DISPLAY'.
endif.
endform. " WRITE_OUTPUT
*----------------------------------------------------------------------*
form alv_initialize_variant.
alv_g_save = 'A'.
clear alv_g_variant.
alv_g_variant-report = alv_repname.
alv_gx_variant = alv_g_variant.
call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
exporting
i_save = alv_g_save
changing
cs_variant = alv_gx_variant
exceptions
not_found = 2.
if sy-subrc = 0.
p_vari = alv_gx_variant-variant.
endif.
endform. " INITIALIZE_VARIANT