Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

*&---------------------------------------------------------------------*

*& Report ZTEST_ALV


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_ALV.
type-pools: slis.
types: stat_offset(2) type n.
tables:mara,afko,MSEG.

types : begin of ty_makt,


matnr type makt-matnr,
maktx type makt-maktx,
end of ty_makt.
types : begin of ty_mseg,
sel TYPE c,
chk TYPE c,
mblnr TYPE mseg-mblnr,
mjahr type mseg-mjahr,
bwart TYPE mseg-bwart,
werks TYPE mseg-werks,
matnr type mseg-matnr,
end of ty_mseg.

data:it_mseg TYPE TABLE OF ty_mseg WITH HEADER LINE,


wa_mseg TYPE ty_mseg.
*---------------------------------------------------------------------*
*
Constants
Begin with C_
*---------------------------------------------------------------------*
constants:
c_formname_top_of_page type slis_formname value 'TOP_OF_PAGE',
c_wbrk(4) type c value 'WBRK',
c_x(1) type c value 'X',
c_timeb_lo type tims value '170000',
c_timeb_up type tims value '235959',
c_timea_lo type tims value '000001',
c_timea_up type tims value '080000'.

data

: w_variant like disvariant,


w_user_command
type slis_formname value 'USER_COMMAND',
w_status
type slis_formname value 'SET_PF_STATUS',
gd_layout
type slis_layout_alv,
w_repid like sy-repid,
w_pos type i,
w_offset type stat_offset,
w_prdat(12) type c,
w_rpdate(12) type c,

w_std_before type c,
w_std_after type c,
w_act_before type c,
w_act_after type c,
w_time type tims,
w_rptime(8) type c,
w_error type c,
w_ls_line type slis_listheader,
it_fieldcat type table of slis_fieldcat_alv,
it_events type table of slis_alv_event,
it_list_top_of_page type table of slis_listheader.

SELECT-OPTIONS:so_prdat for afko-GLTRP,


so_matnr for mara-matnr,
so_bwart for mseg-bwart.
PARAMETERS :plant TYPE mseg-werks.
parameters: variant like disvariant-variant.
parameters : p_grid radiobutton group grp1,
p_list radiobutton group grp1 default 'X'.

at selection-screen on variant.
perform alv_pre_selection.
at selection-screen on value-request for variant.
perform alv_f4_variant.

start-of-selection.
PERFORM get_data.
perform fieldcat_init using it_fieldcat.
perform build_layout.
perform eventtab_build using it_events.
perform comment_build using it_list_top_of_page.
perform call_alv.
TOP-OF-PAGE.
perform top_OF_page.
*&---------------------------------------------------------------------*
*&
Form alv_pre_selection
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form alv_pre_selection .
w_variant-report = sy-repid.

if not variant is initial.


w_variant-variant = variant.
call function 'REUSE_ALV_VARIANT_EXISTENCE'
exporting
i_save
= 'A'
changing
cs_variant = w_variant.
endif.
endform.
" alv_pre_selection
*&---------------------------------------------------------------------*
*&
Form alv_f4_variant
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form alv_f4_variant .
w_variant-report = sy-repid.
data :
w_save(1)
type c value 'A',
w_exit(1)
type c.
call function 'REUSE_ALV_VARIANT_F4'
exporting
is_variant = w_variant
i_save
= w_save
importing
e_exit
= w_exit
es_variant = w_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S'
number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
if w_exit = space.
variant = w_variant-variant.
endif.
endif.
variant = w_variant-variant.
endform.
" alv_f4_variant
*&---------------------------------------------------------------------*
*&
Form top_page
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form top_OF_page .
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = it_list_top_of_page.
endform.
" top_page

*&---------------------------------------------------------------------*
*&
Form fieldcat_init
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_IT_FIELDCAT text
*----------------------------------------------------------------------*
form fieldcat_init using
rt_fieldcat type slis_t_fieldcat_alv.
perform fill_field using : 'WERKS' 'Plant' '' '',
'MBLNR' 'Mat.Doc.' '' '',
'MJAHR' 'Mat.Year' '' '',
'BWART' 'Movement Type' '' '',
'MATNR' 'MATERIAL' 'X' '',
'MENGE' 'QTY' '' '',
'CHK' 'Select' 'X' 'X'.

endform.
" fieldcat_init
*&---------------------------------------------------------------------*
*&
Form eventtab_build
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_IT_EVENTS text
*----------------------------------------------------------------------*
form eventtab_build using lt_events type slis_t_event.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events
= lt_events.
read table lt_events with key name =
into ls_event.

slis_ev_top_of_page

if sy-subrc = 0.
move c_formname_top_of_page to ls_event-form.
append ls_event to lt_events.
endif.
endform.
" eventtab_build
*&---------------------------------------------------------------------*
*&
Form comment_build
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_IT_LIST_TOP_OF_PAGE text
*----------------------------------------------------------------------*
form comment_build using
lt_top_of_page type slis_t_listheader.
data: ls_line type slis_listheader,

str(50) type c,
date1(15) type c,
date2(15) type c.
write sy-datum dd/mm/yy to w_rpdate.
write so_prdat-low dd/mm/yyyy to date1.
write sy-uzeit to w_rptime using edit mask '__:__:__'.
ls_line-typ = 'H'.
ls_line-info+1(40) = 'Daily Production MIS Report'(004).
append ls_line to lt_top_of_page.
clear ls_line.
ls_line-typ = 'S'.
ls_line-info(20) = text-009.
if so_prdat-high is initial.
ls_line-info+20(10) = date1.
else.
write so_prdat-high dd/mm/yyyy to date2.
concatenate date1 ' To ' date2 into str separated by space.
ls_line-info+20(40) = str.
endif.
append ls_line to it_list_top_of_page.
clear ls_line.

ls_line-typ = 'S'.
ls_line-info(20) = text-007.
ls_line-info+20(10) = w_rpdate.
ls_line-info+35(15) = text-008.
ls_line-info+50(10) = w_rptime.
append ls_line to it_list_top_of_page.
clear ls_line.
endform.
" comment_build
*&---------------------------------------------------------------------*
*&
Form call_alv
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form call_alv .
BREAK SAPDEV3.
w_repid = sy-repid.
if ( p_grid = 'X' ).
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program
= w_repid
it_fieldcat
= it_fieldcat
is_layout
= gd_layout
it_events
= it_events
i_save
= 'A'
is_variant
= w_variant

i_callback_user_command = 'VALIDATE_COMMAND'
tables
t_outtab
= it_mseg.
else.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program
= w_repid
it_fieldcat
= it_fieldcat
it_events
= it_events
i_callback_user_command = w_user_command
i_save
= 'A'
is_variant
= w_variant
tables
t_outtab
= it_mseg.
endif.
endform.
" call_alv
*&---------------------------------------------------------------------*
*&
Form fill_field
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_0266
text
*
-->P_0267
text
*----------------------------------------------------------------------*
form fill_field using
p_tab_field_name p_ref_field_name EDIT chk.
data: ls_fieldcat type slis_fieldcat_alv.
clear ls_fieldcat.
w_pos = w_pos + 1.
ls_fieldcat-col_pos
= w_pos.
ls_fieldcat-fieldname
= p_tab_field_name.
ls_fieldcat-ref_fieldname = p_ref_field_name.
ls_fieldcat-EDIT
= EDIT.
ls_fieldcat-checkbox
= chk.
* ls_fieldcat-ref_tabname
= p_ref_field_table.
* ls_fieldcat-seltext_s
= p_short_text.
* ls_fieldcat-seltext_m
= p_short_text.
* ls_fieldcat-seltext_l
= p_qfieldname.
* ls_fieldcat-reptext_ddic = p_short_text.
* ls_fieldcat-key
= p_key_field_flag.
* ls_fieldcat-cfieldname
= p_cfieldname.
* ls_fieldcat-qfieldname
= p_qfieldname.
* ls_fieldcat-outputlen
= p_outputlen.
* ls_fieldcat-datatype
= p_datatype.
* ls_fieldcat-inttype
= p_inttype .
append ls_fieldcat to it_fieldcat.
endform.
" fill_field
*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
*
text

*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form get_data .
select * from mseg
INTO CORRESPONDING FIELDS OF TABLE it_msEg
where matnr in so_matnr
AND werks = plant
AND BWART IN SO_BWART.
endform.
" get_data
*&--------------------------------------------------------------------*
*&
Form VALIDATE_COMMAND
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
*
-->R_UCOMM
text
*
-->SEL_FIELD text
*---------------------------------------------------------------------*
FORM validate_command USING r_ucomm TYPE sy-ucomm
sel_field TYPE slis_selfield.
BREAK SAPDEV3.
DATA :it_grid TYPE REF TO cl_gui_alv_grid.
DATA : is_valid.
* CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
*
IMPORTING
*
*
e_grid
= it_grid.
**
*
* CALL METHOD it_grid->check_changed_data
*
IMPORTING
*
e_valid
= is_valid .
CASE r_ucomm.
WHEN '&DATA_SAVE'.
ENDCASE.
ENDFORM.
"validate_command
*&---------------------------------------------------------------------*
*&
Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
*
Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
BREAK SAPDEV3.
gd_layout-box_fieldname
= 'SEL'.
"set field name to store row selection
* gd_layout-edit
= 'X'. "makes whole ALV table editable
gd_layout-zebra
= 'X'.
endform.
" BUILD_LAYOUT

You might also like