**-------------------------------------------------
* call function 'REUSE_ALV_GRID_DISPLAY'
*
**-------------------------------------------------
report zalv .
type-pools: slis. "for 'REUSE_ALV...list&grids'
*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*
tables: kna1.
*----------------------------------------------------------------------*
* Internal data *
*----------------------------------------------------------------------*
data: begin of it_tab occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
name2 like kna1-name2,
stras like kna1-stras,
pstlz like kna1-pstlz,
ort01 like kna1-ort01,
umsa1 like kna1-umsa1,
ktokd like kna1-ktokd,
end of it_tab.
* data-statements that are necessary for the use of the ALV-grid
data: it_xevents type slis_t_event.
data: xs_event type slis_alv_event.
data: repid type sy-repid.
data: it_fieldcat type slis_t_fieldcat_alv with header line.
data: it_layout type slis_layout_alv.
data: lo_itabname type slis_tabname.
data: variant type disvariant.
*----------------------------------------------------------------------*
* Initialization *
*----------------------------------------------------------------------*
initialization.
*----------------------------------------------------------------------*
* Parameters and select-options *
*----------------------------------------------------------------------*
select-options so_kunnr for kna1-kunnr default '2000' to '2300'.
select-options so_name for kna1-name1.
parameters: pa_pstcd as checkbox default 'X'.
parameters: pa_var as checkbox default 'X'.
*----------------------------------------------------------------------*
* Start of main program *
*----------------------------------------------------------------------*
start-of-selection.
perform select_records.
perform print_alvlist.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form select_records
*&---------------------------------------------------------------------*
form select_records.
select * from kna1 into corresponding fields of it_tab.
* where kunnr in so_kunnr
* and name1 in so_name.
append it_tab.
endselect.
endform. " select_records
*&--------------------------------------------------------------------*
*& Form print_alvlist
*&--------------------------------------------------------------------*
form print_alvlist.
repid = sy-repid.
lo_itabname = 'LT_ALVTABLE'.
* Fill the variables of the ALV-grid.
perform set_layout using it_layout.
perform set_events using it_xevents.
perform append_field.
* Sort the table
sort it_tab by kunnr.
* Present the table using the ALV-grid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = repid
i_callback_top_of_page = 'ALV_HEADER'
is_layout = it_layout
is_variant = variant
it_fieldcat = it_fieldcat[]
i_save = 'A'
* it_events = it_xevents
tables
t_outtab = it_tab.
endform. " print_alvlist
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
form set_layout using pa_layout type slis_layout_alv.
* pa_layout-f2code = '&ETA'.
pa_layout-zebra = 'X'.
* pa_layout-detail_popup = 'X'.
pa_layout-colwidth_optimize = 'X'.
*
pa_layout-totals_text = 'Total:'.
pa_layout-subtotals_text = 'Subtotal:'.
** Set the variant, as requested via the checkbox
* if pa_var = 'X'.
* variant-variant = '/ZLAYOUT'.
* else.
* clear variant-variant.
* endif.
endform. " SET_LAYOUT
*&--------------------------------------------------------------------
*& Form Set_events
*&--------------------------------------------------------------------
* Appends the values of the events to the events-variable that is
* used by REUSE_ALV_LIST_DISPLAY
*&--------------------------------------------------------------------
form set_events using pa_events type slis_t_event.
xs_event-name = slis_ev_top_of_list.
xs_event-form = 'XTOP_OF_LIST'.
append xs_event to pa_events.
xs_event-name = slis_ev_end_of_list.
xs_event-form = 'XEND_OF_LIST'.
append xs_event to pa_events.
xs_event-name = slis_ev_top_of_page.
xs_event-form = 'XTOP_OF_PAGE'.
append xs_event to pa_events.
xs_event-name = slis_ev_end_of_page.
xs_event-form = 'XEND_OF_PAGE'.
append xs_event to pa_events.
endform.
*&--------------------------------------------------------------------*
*& Form XTOP_OF_LIST
*&--------------------------------------------------------------------*
form xtop_of_list.
data lo_date(8).
concatenate sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum+2(2)
into lo_date.
write: at 1 'Report:'(t01), 20 'Reportname'(t02).
write: at 50 'Date:'(t03), lo_date.
new-line.
write: at 1 'Abap-name report: '(t04), sy-repid.
write: at 50 'Page:'(t05), sy-cpage.
endform. "xtop_of_list
*&--------------------------------------------------------------------*
*& Form XEND_OF_LIST
*&--------------------------------------------------------------------*
form xend_of_list.
write: 'Footer of the list'(002).
endform. "xend_of_list
*&---------------------------------------------------------------------*
*& Form XTOP_OF_PAGE
*&---------------------------------------------------------------------*
form xtop_of_page.
write:/ 'Top of the page.'(003).
*()*Here your selection-criteria can be printed
endform. "xtop-of-page
*&---------------------------------------------------------------------*
*& Form XEND_OF_PAGE
*&---------------------------------------------------------------------*
form xend_of_page.
write:/ 'End of the page.'(004).
endform. "xtop-of-page
*&---------------------------------------------------------------------*
*& Form append_field
*&---------------------------------------------------------------------*
form append_field.
perform append_list_field using '1' 'kunnr' 'COLA'.
perform append_list_field using '2' 'NAME1' 'COLB'.
perform append_list_field using '3' 'NAME2' 'COLC'.
perform append_list_field using '4' 'STRAS' 'COLD'.
perform append_list_field using '5' 'PSTLZ' 'COLE'.
perform append_list_field using '6' 'ORT01' 'COLF'.
perform append_list_field using '7' 'UMSA1' 'COLG'.
perform append_list_field using '8' 'KTOKD' 'COLH'.
endform. " FILL_STRUCTURE
*&--------------------------------------------------------------------*
*& Form append_alv_field
*&--------------------------------------------------------------------*
form append_list_field using value(p_col_pos)
value(p_fieldname)
value(p_seltex).
data st_fieldcat type slis_fieldcat_alv.
clear st_fieldcat.
move: p_col_pos to st_fieldcat-col_pos,
p_fieldname to st_fieldcat-fieldname,
p_seltex to st_fieldcat-seltext_l.
append st_fieldcat to it_fieldcat.
endform. "append_alv_field
*&---------------------------------------------------------------------*
*& Form alv_header
*&---------------------------------------------------------------------*
* alv_grid_report header event
*----------------------------------------------------------------------*
FORM alv_header.
DATA:it_list TYPE slis_t_listheader,
st_list TYPE slis_listheader.
st_list-typ = 'S'.
st_list-key = 'COMPANY: '.
st_list-info = 'L600 Wistron Corporation ini '.
APPEND st_list TO it_list.
CLEAR st_list.
st_list-typ = 'S'.
st_list-key = 'Plant: '.
st_list-info = 'Plant_A'.
APPEND st_list TO it_list.
CLEAR st_list.
st_list-typ = 'S'.
st_list-key = 'Version: '.
st_list-info = 'V1'.
APPEND st_list TO it_list.
CLEAR st_list.
st_list-typ = 'S'.
st_list-key = 'Gain Lost Only: '.
st_list-info = 'Y'.
APPEND st_list TO it_list.
CLEAR st_list.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_list.
endform. "alv_header
*
**-------------------------------------------------
* call function 'REUSE_ALV_LIST_DISPLAY'
*
**-------------------------------------------------
REPORT ZLIST .
type-pools: slis. "for 'REUSE_ALV...list&grids'
*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*
tables: kna1.
*----------------------------------------------------------------------*
* Internal data *
*----------------------------------------------------------------------*
data: begin of it_tab occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
name2 like kna1-name2,
stras like kna1-stras,
pstlz like kna1-pstlz,
ort01 like kna1-ort01,
umsa1 like kna1-umsa1,
ktokd like kna1-ktokd,
end of it_tab.
* data-statements that are necessary for the use of the ALV-grid
data: it_xevents type slis_t_event.
data: xs_event type slis_alv_event.
data: repid type sy-repid.
data: it_fieldcat type slis_t_fieldcat_alv with header line.
data: it_layout type slis_layout_alv.
data: lo_itabname type slis_tabname.
data: variant type disvariant.
*----------------------------------------------------------------------*
* Initialization *
*----------------------------------------------------------------------*
initialization.
*----------------------------------------------------------------------*
* Parameters and select-options *
*----------------------------------------------------------------------*
select-options so_kunnr for kna1-kunnr default '2000' to '2300'.
select-options so_name for kna1-name1.
parameters: pa_pstcd as checkbox default 'X'.
parameters: pa_var as checkbox default 'X'.
*----------------------------------------------------------------------*
* Start of main program *
*----------------------------------------------------------------------*
start-of-selection.
perform select_records.
perform print_alvlist.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form select_records
*&---------------------------------------------------------------------*
form select_records.
select * from kna1 into corresponding fields of it_tab.
* where kunnr in so_kunnr
* and name1 in so_name.
append it_tab.
endselect.
endform. " select_records
*&--------------------------------------------------------------------*
*& Form print_alvlist
*&--------------------------------------------------------------------*
form print_alvlist.
repid = sy-repid.
lo_itabname = 'LT_ALVTABLE'.
* Fill the variables of the ALV-grid.
perform set_layout using it_layout.
perform set_events using it_xevents.
perform append_field.
* Sort the table
sort it_tab by kunnr.
* Present the table using the ALV-grid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = repid
is_layout = it_layout
is_variant = variant
it_fieldcat = it_fieldcat[]
i_save = 'A'
it_events = it_xevents
tables
t_outtab = it_tab.
endform. " print_alvlist
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
form set_layout using pa_layout type slis_layout_alv.
* pa_layout-f2code = '&ETA'.
pa_layout-zebra = 'X'.
* pa_layout-detail_popup = 'X'.
pa_layout-colwidth_optimize = 'X'.
*
pa_layout-totals_text = 'Total:'.
pa_layout-subtotals_text = 'Subtotal:'.
** Set the variant, as requested via the checkbox
* if pa_var = 'X'.
* variant-variant = '/ZLAYOUT'.
* else.
* clear variant-variant.
* endif.
endform. " SET_LAYOUT
*&--------------------------------------------------------------------
*& Form Set_events
*&--------------------------------------------------------------------
* Appends the values of the events to the events-variable that is
* used by REUSE_ALV_LIST_DISPLAY
*&--------------------------------------------------------------------
form set_events using pa_events type slis_t_event.
xs_event-name = slis_ev_top_of_list.
xs_event-form = 'XTOP_OF_LIST'.
append xs_event to pa_events.
xs_event-name = slis_ev_end_of_list.
xs_event-form = 'XEND_OF_LIST'.
append xs_event to pa_events.
xs_event-name = slis_ev_top_of_page.
xs_event-form = 'XTOP_OF_PAGE'.
append xs_event to pa_events.
xs_event-name = slis_ev_end_of_page.
xs_event-form = 'XEND_OF_PAGE'.
append xs_event to pa_events.
endform.
*&--------------------------------------------------------------------*
*& Form XTOP_OF_LIST
*&--------------------------------------------------------------------*
form xtop_of_list.
data lo_date(8).
concatenate sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum+2(2)
into lo_date.
write: at 1 'Report:'(t01), 20 'Reportname'(t02).
write: at 50 'Date:'(t03), lo_date.
new-line.
write: at 1 'Abap-name report: '(t04), sy-repid.
write: at 50 'Page:'(t05), sy-cpage.
endform. "xtop_of_list
*&--------------------------------------------------------------------*
*& Form XEND_OF_LIST
*&--------------------------------------------------------------------*
form xend_of_list.
write: 'Footer of the list'(002).
endform. "xend_of_list
*&---------------------------------------------------------------------*
*& Form XTOP_OF_PAGE
*&---------------------------------------------------------------------*
form xtop_of_page.
write:/ 'Top of the page.'(003).
*()*Here your selection-criteria can be printed
endform. "xtop-of-page
*&---------------------------------------------------------------------*
*& Form XEND_OF_PAGE
*&---------------------------------------------------------------------*
form xend_of_page.
write:/ 'End of the page.'(004).
endform. "xtop-of-page
*&---------------------------------------------------------------------*
*& Form append_field
*&---------------------------------------------------------------------*
form append_field.
perform append_list_field using '1' 'kunnr' 'COLA'.
perform append_list_field using '2' 'NAME1' 'COLB'.
perform append_list_field using '3' 'NAME2' 'COLC'.
perform append_list_field using '4' 'STRAS' 'COLD'.
perform append_list_field using '5' 'PSTLZ' 'COLE'.
perform append_list_field using '6' 'ORT01' 'COLF'.
perform append_list_field using '7' 'UMSA1' 'COLG'.
perform append_list_field using '8' 'KTOKD' 'COLH'.
endform. " FILL_STRUCTURE
*&--------------------------------------------------------------------*
*& Form append_alv_field
*&--------------------------------------------------------------------*
form append_list_field using value(p_col_pos)
value(p_fieldname)
value(p_seltex).
data st_fieldcat type slis_fieldcat_alv.
clear st_fieldcat.
move: p_col_pos to st_fieldcat-col_pos,
p_fieldname to st_fieldcat-fieldname,
p_seltex to st_fieldcat-seltext_l.
append st_fieldcat to it_fieldcat.
endform. "append_alv_field