You are on page 1of 4

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

*& Report ZALV_GRID_EXAMPLE


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

report zalv_grid_example.

tables:t001.
"Types
types:
begin of t_1001,
bukrs type t001-bukrs,
butxt type t001-butxt,
ort01 type t001-ort01,
land1 type t001-land1,
end of t_1001.
"Work area
data:
w_t001 type t_1001.
"Internal table
data:
i_t001 type standard table of t_1001.

*&---------------------------------------------------------------------*
* ALV Declarations
*----------------------------------------------------------------------*
* Types Pools
type-pools:
slis.
* Types
types:
t_fieldcat type slis_fieldcat_alv,
t_events type slis_alv_event,
t_layout type slis_layout_alv.
* Workareas
data:
w_fieldcat type t_fieldcat,
w_events type t_events,
w_layout type t_layout.
* Internal Tables
data:
i_fieldcat type standard table of t_fieldcat,
i_events type standard table of t_events.
*&---------------------------------------------------------------------*
*& start of selection
*&---------------------------------------------------------------------*
start-of-selection.
perform get_data.

*&---------------------------------------------------------------------*
*& end-of-selection.
*&---------------------------------------------------------------------*
end-of-selection.

perform build_fieldcatlog.
perform build_events.
perform build_layout.
perform list_display.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
form get_data .

select bukrs
butxt
ort01
land1
from t001
into table i_t001
up to 30 rows.

endform. " get_data


*&---------------------------------------------------------------------*
*& Form build_fieldcatlog
*&---------------------------------------------------------------------*
form build_fieldcatlog .
clear:w_fieldcat,i_fieldcat[].

perform build_fcatalog using:


'BUKRS' 'I_T001' 'BUKRS',
'BUTXT' 'I_T001' 'BUTXT',
'ORT01' 'I_T001' 'ORT01',
'LAND1' 'I_T001' 'LAND1'.

endform. "BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
*& Form BUILD_FCATALOG
*&---------------------------------------------------------------------*
form build_fcatalog using l_field l_tab l_text.

w_fieldcat-fieldname = l_field.
w_fieldcat-tabname = l_tab.
w_fieldcat-seltext_m = l_text.

append w_fieldcat to i_fieldcat.


clear w_fieldcat.

endform. " build_fieldcatlog


*&---------------------------------------------------------------------*
*& Form build_events
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_events.
clear :
w_events, i_events[].
w_events-name = 'TOP_OF_PAGE'."Event Name
w_events-form = 'TOP_OF_PAGE'."Callback event subroutine
append w_events to i_events.
clear w_events.

endform. "build_events
*&---------------------------------------------------------------------*
*& Form build_layout
*&---------------------------------------------------------------------*
form build_layout .

w_layout-colwidth_optimize = 'X'.
w_layout-zebra = 'X'.

endform. " build_layout


*&---------------------------------------------------------------------*
*& Form list_display
*&---------------------------------------------------------------------*
form list_display .
data:
l_program type sy-repid.
l_program = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'


exporting
i_callback_program = l_program
is_layout = w_layout
it_fieldcat = i_fieldcat
it_events = i_events
tables
t_outtab = i_t001
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " list_display
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
form top_of_page.
data :
li_header type slis_t_listheader,
w_header like line of li_header.
data:
l_date type char10.
write sy-datum to l_date.
w_header-typ = 'H'.
concatenate sy-repid ':' 'From Date' l_date into w_header-info separated by
space.
append w_header to li_header.
clear w_header.

w_header-typ = 'S'.
w_header-info = sy-title.
append w_header to li_header.
clear w_header.

w_header-typ = 'A'.
w_header-info = sy-uname.
append w_header to li_header.
clear w_header.

call function 'REUSE_ALV_COMMENTARY_WRITE'


exporting
it_list_commentary = li_header.
endform. "top_of_page

You might also like