*----------------------------------------------------------------------*
* DECLARATIONS *
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_out,
[...]
END OF ty_out.
DATA: gt_out TYPE TABLE OF ty_out,
gs_out TYPE ty_out.
DATA gr_alv TYPE REF TO CL_SALV_TABLE.
*----------------------------------------------------------------------*
* PROGRAM BODY *
*----------------------------------------------------------------------*
START-OF-SELECTION.
[...]
END-OF-SELECTION.
PERFORM output_alv.
*----------------------------------------------------------------------*
* FORM OUTPUT_ALV *
*----------------------------------------------------------------------*
FORM output_alv.
TRY.
CL_SALV_TABLE=>FACTORY(
IMPORTING
R_SALV_TABLE = gr_alv
CHANGING
T_TABLE = gt_out ).
PERFORM set_settings.
gr_alv->display( ).
CATCH cx_salv_msg.
" error handling
RETURN.
ENDTRY.
ENDFORM. "output_alv
*----------------------------------------------------------------------*
* FORM SET_SETTINGS *
*----------------------------------------------------------------------*
FORM set_settings.
DATA: ls_key TYPE SALV_S_LAYOUT_KEY,
lo_cols TYPE REF TO CL_SALV_COLUMNS_TABLE,
lo_col TYPE REF TO CL_SALV_COLUMN,
lo_events TYPE REF TO CL_SALV_EVENTS_TABLE,
lo_funcs TYPE REF TO CL_SALV_FUNCTIONS_LIST,
lo_layout TYPE REF TO CL_SALV_LAYOUT,
lo_display TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
lo_selections TYPE REF TO CL_SALV_SELECTIONS,
lv_text_s TYPE SCRTEXT_S,
lv_text_m TYPE SCRTEXT_M,
lv_text_l TYPE SCRTEXT_L.
DEFINE set_column.
lv_text_s = lv_text_m = lv_text_l = &2.
lo_col = lo_cols->get_column( &1 ).
lo_col->set_short_text( lv_text_s ).
lo_col->set_medium_text( lv_text_m ).
lo_col->set_long_text( lv_text_l ).
END-OF-DEFINITION.
*Columns
lo_cols = gr_alv->get_columns( ).
lo_cols->set_optimize( 'X' ).
set_column 'FIELD' 'Field description'.
[...]
*Layouts
ls_key-report = SY-REPID.
lo_layout = gr_alv->get_layout( ).
lo_layout->set_key( ls_key ).
lo_layout->set_default( 'X' ).
lo_layout->set_save_restriction( ).
*Functions
lo_funcs = gr_alv->get_functions( ).
lo_funcs->set_all( ).
*Display Settings
lo_display = gr_alv->get_display_settings( ).
lo_display->set_striped_pattern( 'X' ).
*Selections
lo_selections = gr_alv->get_selections( ).
lo_selections->set_selection_mode(
IF_SALV_C_SELECTION_MODE=>ROW_COLUMN ).
ENDFORM. "set_settings