Step1.
-------------------------------------------------------------------------------------------------------
CLASS lcl_salv_tab DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : main IMPORTING
i_list TYPE xfeld
i_grid TYPE xfeld
i_alv_tb TYPE c
i_hide_fld TYPE c,
fetch_records,
get_alv_instance IMPORTING
i_list TYPE xfeld
i_grid TYPE xfeld
i_alv_tb TYPE c
i_hide_fld TYPE c,
display_alv.
PRIVATE SECTION.
CLASS-DATA : lt TYPE TABLE OF sflight,
lo_salv_tab TYPE REF TO cl_salv_table,
lo_func TYPE REF TO cl_salv_functions_list,
lo_cols TYPE REF TO cl_salv_columns_table,
lo_col TYPE REF TO cl_salv_column .
ENDCLASS.
CLASS lcl_salv_tab IMPLEMENTATION.
METHOD main.
fetch_records( ).
get_alv_instance( EXPORTING i_list = i_list
i_grid = i_grid
i_alv_tb = i_alv_tb
i_hide_fld = i_hide_fld ).
display_alv( ).
ENDMETHOD.
METHOD fetch_records.
SELECT * FROM sflight INTO TABLE lt UP TO 20 ROWS.
ENDMETHOD.
METHOD get_alv_instance.
DATA : flag.
IF i_list = 'X' OR i_grid = 'X'.
IF i_list = 'X'.
flag = 'X'.
ELSE.
flag = ' '.
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = flag
IMPORTING
r_salv_table = lo_salv_tab
CHANGING
t_table = lt.
IF i_alv_tb = abap_true.
**Begin- Displaying toolbar on alv **
CALL METHOD lo_salv_tab->get_functions " Get the instance of "alv toolbal button
RECEIVING
value = lo_func.
CALL METHOD lo_func->set_default " pass 'TRUE' to display toobar on alv
EXPORTING
value = if_salv_c_bool_sap=>true."TRUE displays toolbar on "alv/FALSE hides toolbar
**End- Displaying toolbar on alv**
ENDIF.
IF i_hide_fld = abap_true.
** Begin - Hides paritular column of the table in the list or grid**
CALL METHOD lo_salv_tab->get_columns " get all columns of the "table
RECEIVING
value = lo_cols.
TRY.
CALL METHOD lo_cols->get_column " get reference to particular "column
EXPORTING
columnname = 'MANDT'
RECEIVING
value = lo_col.
CALL METHOD lo_col->set_technical " set technical - true hides "the column on UI
EXPORTING
value = if_salv_c_bool_sap=>true.
CATCH cx_salv_not_found .
ENDTRY.
** End - Hides paritular column of the table in the list or grid**
ENDIF.
CATCH cx_salv_msg .
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD display_alv.
CALL METHOD lo_salv_tab->display.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS : list RADIOBUTTON GROUP g1,
grid RADIOBUTTON GROUP g1,
alv_tool AS CHECKBOX,
hide_fld AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.
CALL METHOD lcl_salv_tab=>main EXPORTING
i_list = list
i_grid = grid
i_alv_tb = alv_tool
i_hide_fld = hide_fld.
-------------------------------------------------------------------------------------------------------------
Step2. Select the below I/P.
Step3. Te=he column MANDT appears on the O/P.
Step4. Select Hide Field.
Step5. The column MANDT is hidden on the UI.
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
CLASS lcl_salv_tab DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : main IMPORTING
i_list TYPE xfeld
i_grid TYPE xfeld
i_alv_tb TYPE c
i_hide_fld TYPE c,
fetch_records,
get_alv_instance IMPORTING
i_list TYPE xfeld
i_grid TYPE xfeld
i_alv_tb TYPE c
i_hide_fld TYPE c,
display_alv.
PRIVATE SECTION.
CLASS-DATA : lt TYPE TABLE OF sflight,
lo_salv_tab TYPE REF TO cl_salv_table,
lo_func TYPE REF TO cl_salv_functions_list,
lo_cols TYPE REF TO cl_salv_columns_table,
lo_col TYPE REF TO cl_salv_column .
ENDCLASS.
CLASS lcl_salv_tab IMPLEMENTATION.
METHOD main.
fetch_records( ).
get_alv_instance( EXPORTING i_list = i_list
i_grid = i_grid
i_alv_tb = i_alv_tb
i_hide_fld = i_hide_fld ).
display_alv( ).
ENDMETHOD.
METHOD fetch_records.
SELECT * FROM sflight INTO TABLE lt UP TO 20 ROWS.
ENDMETHOD.
METHOD get_alv_instance.
DATA : flag.
IF i_list = 'X' OR i_grid = 'X'.
IF i_list = 'X'.
flag = 'X'.
ELSE.
flag = ' '.
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = flag
IMPORTING
r_salv_table = lo_salv_tab
CHANGING
t_table = lt.
IF i_alv_tb = abap_true.
**Begin- Displaying toolbar on alv **
CALL METHOD lo_salv_tab->get_functions " Get the instance of "alv toolbal button
RECEIVING
value = lo_func.
CALL METHOD lo_func->set_default " pass 'TRUE' to display toobar on alv
EXPORTING
value = if_salv_c_bool_sap=>true."TRUE displays toolbar on "alv/FALSE hides toolbar
**End- Displaying toolbar on alv**
ENDIF.
IF i_hide_fld = abap_true.
** Begin - Hides paritular column of the table in the list or grid**
CALL METHOD lo_salv_tab->get_columns " get all columns of the "table
RECEIVING
value = lo_cols.
TRY.
CALL METHOD lo_cols->get_column " get reference to particular "column
EXPORTING
columnname = 'MANDT'
RECEIVING
value = lo_col.
CALL METHOD lo_col->set_technical " set technical - true hides "the column on UI
EXPORTING
value = if_salv_c_bool_sap=>true.
CATCH cx_salv_not_found .
ENDTRY.
** End - Hides paritular column of the table in the list or grid**
ENDIF.
CATCH cx_salv_msg .
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD display_alv.
CALL METHOD lo_salv_tab->display.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS : list RADIOBUTTON GROUP g1,
grid RADIOBUTTON GROUP g1,
alv_tool AS CHECKBOX,
hide_fld AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.
CALL METHOD lcl_salv_tab=>main EXPORTING
i_list = list
i_grid = grid
i_alv_tb = alv_tool
i_hide_fld = hide_fld.
-------------------------------------------------------------------------------------------------------------
Step2. Select the below I/P.
Step3. Te=he column MANDT appears on the O/P.
Step4. Select Hide Field.
Step5. The column MANDT is hidden on the UI.
-------------------------------------------------------------------------------------------------------
No comments:
Post a Comment