-----------------------------------------------------------------------------------------------
CLASS lcl_salv_tab DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : main IMPORTING
i_list TYPE xfeld
i_grid TYPE xfeld
i_alv_tb TYPE C,
fetch_records,
get_alv_instance IMPORTING
i_list TYPE xfeld
i_grid TYPE xfeld
i_alv_tb TYPE c,
display_alv.
PRIVATE SECTION.
TYPES : BEGIN OF ty_flight,
status TYPE c LENGTH 1.
INCLUDE TYPE sflight.
TYPES : END OF ty_flight.
CLASS-DATA : lt TYPE TABLE OF ty_flight,
ls TYPE ty_flight,
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,
rem_seat TYPE i.
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 ).
display_alv( ).
ENDMETHOD.
METHOD fetch_records.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE lt UP TO 30 ROWS.
LOOP AT lt INTO ls.
rem_seat = ls-seatsmax_b - ls-seatsocc_b.
if rem_seat = 0.
ls-status = 1 . " RED LIGHT VALUE
elseif rem_seat le 10.
ls-status = 2. " YELLOW LIGHTVALUE
else.
ls-status = 3. " GREEN LIGHT VALUE
endif.
MODIFY LT FROM ls INDEX sy-tabix TRANSPORTING status.
clear ls.
ENDLOOP.
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
EXPORTING
value = if_salv_c_bool_sap=>true."TRUE displays toolbar on " alv
**End- Displaying toolbar on alv**
ENDIF.
** Begin - Hides partiular column of the table in the list or grid**
CALL METHOD lo_salv_tab->get_columns " get all columns
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 partiular column of the table in the list or grid**
** Begin-Set status field as traffic light 1- red /2-yellow /3-green**
TRY.
CALL METHOD lo_cols->set_exception_column
EXPORTING
value = 'STATUS'. " pass the field name of internal table for "showing traffic light status
CATCH cx_salv_data_error .
ENDTRY.
**End - Set status field as traffic light **
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.
SELECTION-SCREEN END OF BLOCK b1.
CALL METHOD lcl_salv_tab=>main EXPORTING
i_list = list
i_grid = grid
i_alv_tb = alv_tool.
---------------------------------------------------------------------------------------------
Step2.
Step3.
------------------------------------------------------------------------------------------------------
No comments:
Post a Comment