ABAP OO ALV Sample Program To Display Table Structure
ABAP OO ALV Sample Program To Display Table Structure
selection-screen skip.
parameters:
p_lay04 as checkbox. "DEFAULT Layouts
selection-screen skip.
parameters:
p_lay05 as checkbox default 'X', "Start with Layout
p_lay06 like disvariant-variant. "LAYOUT
selection-screen end of block lay.
begin of gc_s_display,
list type i value 1,
fullscreen type i value 2,
grid type i value 3,
end of gc_s_display.
include <color>.
include <icon>.
include <symbol>.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST *
*----------------------------------------------------------------------*
at selection-screen on value-request for p_lay06.
perform f4_layouts using gs_test-restrict changing p_lay06.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
start-of-selection.
**--------------------------------------------------------------------**
** B E G I N
** this section of code deals with the handling of the layouts
**--------------------------------------------------------------------**
* gs_test-amount = p_amount.
gs_test-repid = sy-repid.
case 'X'.
when p_lay01. "SAVE All
*... §4.3 set Layout save restriction (3) no restriction
gs_test-restrict = if_salv_c_layout=>restrict_none.
when p_lay02. "SAVE USER-SPECIFIC
*... §4.3 set Layout save restriction (1) restrict to user dependant
gs_test-restrict = if_salv_c_layout=>restrict_user_dependant.
when p_lay03. "SAVE ACROSS USERS
*... §4.3 set Layout save restriction (2) restrict to user independant
gs_test-restrict = if_salv_c_layout=>restrict_user_independant.
endcase.
**--------------------------------------------------------------------**
** E N D
** this section of code deals with the handling of the layouts
**--------------------------------------------------------------------**
** ?= means cast
** r_descr ?= cl_abap_typedescr=>describe_by_data( wa_spfli ).
r_descr ?= cl_abap_typedescr=>describe_by_name( P_TABNAM ).
Loop at r_descr->components into wa_comp.
EndLoop.
<ls_alvtab>-t_color = lt_color.
endif.
endloop.
CATCH CX_SALV_MSG .
ENDTRY.
*... §3 Functions
*... §3.1 activate ALV generic Functions
data: lr_functions type ref to cl_salv_functions_list.
lr_functions = r_grid->get_functions( ).
lr_functions->set_default( abap_true ).
lr_columns = r_grid->get_columns( ).
lr_columns->set_optimize( abap_true ).
**--------------------------------------------------------------------**
** B E G I N
** this code deals with the handling of column headings
** it will overwrite the data element specified in the data dictionary
**--------------------------------------------------------------------**
data: l_column TYPE REF TO CL_SALV_COLUMN.
**--------------------------------------------------------------------**
** E N D
** this code deals with the handling of column headings
** it will overwrite the data element specified in the data dictionary
**--------------------------------------------------------------------**
**
perform create_header_and_footer .
lr_layout = r_grid->get_layout( ).
*&---------------------------------------------------------------------*
** E N D
*& this code deals with Layout processing
*&---------------------------------------------------------------------*
**
**
**--------------------------------------------------------------------**
** B E G I N
** this code deals with the handling of display of lines
**--------------------------------------------------------------------**
* ref to the class
data: lr_display_settings type ref to cl_salv_display_settings,
l_title type lvc_title,
STRIPED_PATTERN type SAP_BOOL value 'X',"space = false x = true
VERTICAL_LINES type SAP_BOOL value 'X',
HORIZONTAL_LINES type SAP_BOOL value 'X'.
l_title = 'Display of Table Structure'.
r_grid->display( ).
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
initialization.
perform get_default_layout using gs_test-restrict changing p_lay06.
*&---------------------------------------------------------------------*
*& Form set_columns_technical
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form set_columns_technical using ir_columns type ref to cl_salv_columns.
try.
lr_column = ir_columns->get_column( 'MANDT' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'FLOAT_FI' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'STRING_F' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'XSTRING' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'INT_FIEL' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'HEX_FIEL' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'DROPDOWN' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
try.
lr_column = ir_columns->get_column( 'TAB_INDEX' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
*&---------------------------------------------------------------------*
*& Form set_columns_color
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form set_columns_color using ir_columns type ref to cl_salv_columns.
try.
lr_column ?= ir_columns->get_column( 'NAME' ).
ls_color-col = col_heading.
ls_color-int = 0.
ls_color-inv = 0.
lr_column->set_color( ls_color ).
catch cx_salv_not_found.
endtry.
*
*
**... §5.2 set the color of a complete row
** (1) register the column in which the color information
** for the row is held
***
data: lr_columns type ref to cl_salv_columns_table.
types: t_color type lvc_t_scol.
**
lr_columns = r_grid->get_columns( ).
**
try.
lr_columns->set_color_column( 'T_COLOR' ).
catch cx_salv_data_error. "#EC NO_HANDLER
endtry.
Data: wk_hdg_line_1(50).
Data: wk_hdg_line_2(50).
lr_header = lr_top_element->create_header_information(
row = 1
column = 1
text = wk_hdg_line_1
tooltip = 'space for tooltip' ).
lr_action = lr_top_element->create_action_information(
row = 2
column = 1
text = wk_hdg_line_2
tooltip = 'tooltip description - if any' ).
lr_action = lr_top_element->create_action_information(
row = 2
column = 5
text = IT_DAY_ATTR-DAY_STRING ).
Data: wk_text_1(30),
wk_text_2(30),
wk_text_3(30),
wk_text_4(30),
wk_text_5(30),
wk_output_date(10),
wk_output_time(10).
** ROW 1
write sy-datlo to wk_output_date.
CONCATENATE 'Date:' wk_output_date into wk_text_1 SEPARATED BY space.
lr_textview1 = lr_grid->create_text(
row = 1
column = 1
text = wk_text_1
tooltip = 'Tooltip' ).
** ROW 2
WRITE sy-timlo to wk_output_time.
CONCATENATE 'Time:' wk_output_time into wk_text_1 SEPARATED BY space.
lr_textview2 = lr_grid->create_text(
row = 2
column = 1
text = wk_text_1
tooltip = 'Tooltip' ).
wk_text_2 = 'lr_layout_grid3'.
lr_textview3 = lr_grid->create_text(
row = 2
column = 2
text = wk_text_2
tooltip = 'Tooltip' ).
lr_layout_grid1 ?= lr_textview1->get_layout_data( ).
lr_layout_grid2 ?= lr_textview2->get_layout_data( ).
lr_layout_grid3 ?= lr_textview3->get_layout_data( ).
lr_layout_grid4 ?= lr_textview4->get_layout_data( ).
lr_layout_grid5 ?= lr_textview5->get_layout_data( ).
lr_layout_grid1->set_h_align( if_salv_form_c_h_align=>left ).
lr_layout_grid2->set_h_align( if_salv_form_c_h_align=>left ).
lr_layout_grid3->set_h_align( if_salv_form_c_h_align=>left ).
* lr_layout_grid4->set_h_align( if_salv_form_c_h_align=>center ).
**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**
**&&&& check class CL_SALV_FORM_UIE_IMAGE &&&&&**
**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**
r_grid->set_end_of_list( lr_eol ).
*&---------------------------------------------------------------------*
*& Form f4_layouts
*&---------------------------------------------------------------------*
* §4.5 F4 Layouts
* cl_salv_layout provides a method for handling the f4 help of the
* layouts for the specified layout key. It is also possible to use
* the static class cl_salv_layout_service.
*----------------------------------------------------------------------*
form f4_layouts using i_restrict type salv_de_layout_restriction
changing c_layout type disvariant-variant.
ls_key-report = sy-repid.
ls_layout = cl_salv_layout_service=>f4_layouts(
s_key = ls_key
restrict = i_restrict ).
c_layout = ls_layout-layout.
*&---------------------------------------------------------------------*
*& Form get_default_layout
*&---------------------------------------------------------------------*
* §4.4 Get Default Layout
* cl_salv_layout provides a method for retieving the valid default
* layout. It is also possible to use the static class
* cl_salv_layout_service. The rules for determinig the valid
* default Layout is as follows:
* (1) check if user-dependant default layout exists if yes then
* this layout is loaded
* (2) check if user-independant standard layout exists if yes then
* this layout is loaded
* (3) check if user-independant SAP standard layout exists if yes
* then this layout is loaded
*----------------------------------------------------------------------*
form get_default_layout using i_restrict type salv_de_layout_restriction
changing c_layout type disvariant-variant.
ls_key-report = sy-repid.
ls_layout = cl_salv_layout_service=>get_default_layout(
s_key = ls_key
restrict = i_restrict ).
c_layout = ls_layout-layout.