Professional Documents
Culture Documents
______ _______
* | _ | _ | _ | | | _ | || _ | _ |
_ | | _ |
* | |_| | |_| | |_| | _ | | |_| | _ | |_| | |_| |
| || | |_| |
* | | | | |_| | | | | | | | |
|_||_| |
* | | _ || | ___| _| | |_| | | _ ||
__ | |
* | _ | |_| | _ | | | |_| _ | | _ | |_| |
| | | _ |
* |__| |__|_______|__| |__|___| |_______|__| |__|______||__| |__|_______|
___| |_|__| |__|
*
www.abapcadabra.com
*---------------------------------------------------------------------
* include : ZABAPCADABRA_EASY_ALV
* holding : Local LCL_EASY_ALV class definition & implementation
* title : Easy ALV through lcl_easy_alv
* functional area : Cross modules
* environment : 4.7
* program Function : This local class can be included in any ABAP report
* and supports easy access to the standard SAP ALV
* suite of functionality. It's a wrapper class that
* sweetens the implementation of ALV reports.
* Documentation : Search for "Easy ALV" on AbapcadabrA.com
* There are simple "to-go" examples on ALV matters such
* as Field colors, Icons, Respond to field clicks and
* much more - using this local class.
* Previous version : This is the initial version
* Developer name : Wim Maasdam
* Development date : 18/11/2015
* Version : 0.1
*---------------------------------------------------------------------
*---------------------------------------------------------------------
* C L A S S D E F I N I T I O N
*---------------------------------------------------------------------
CLASS lcl_easy_alv DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
gw_colored_field type lvc_s_scol ##NEEDED.
DATA:
RF_SELECTIONS type ref to CL_SALV_SELECTIONS,
RF_DISPLAY_SETTINGS type ref to CL_SALV_DISPLAY_SETTINGS,
RF_COLUMNS_TABLE type ref to CL_SALV_COLUMNS_TABLE,
RF_COLUMN_TABLE type ref to CL_SALV_COLUMN_TABLE,
RF_FUNCTIONS_LIST type ref to CL_SALV_FUNCTIONS_LIST,
RF_FUNCTIONAL_SETTINGS type ref to CL_SALV_FUNCTIONAL_SETTINGS,
RF_SORTS type ref to CL_SALV_SORTS,
RF_LAYOUT type ref to CL_SALV_LAYOUT,
* Freely usable custom container: if your ALV lives in part of a screen
RF_custom_container type ref to cl_gui_custom_container.
METHODS:
SET_FIELD
IMPORTING
FIELDNAME type string
IS_KEY type boolean OPTIONAL
IS_HIDDEN type boolean OPTIONAL
IS_UNAVAILABLE type boolean OPTIONAL
IS_ICON type boolean OPTIONAL
IS_HOTSPOT type boolean OPTIONAL
IS_CHECKBOX type boolean OPTIONAL
IS_BUTTON type boolean OPTIONAL
IS_EXCEPTION type boolean OPTIONAL
TOOLTIP type any OPTIONAL
DESCRIPTION_OVERALL type any OPTIONAL
DESCRIPTION_SHORT type any OPTIONAL
DESCRIPTION_MEDIUM type any OPTIONAL
DESCRIPTION_LONG type any OPTIONAL
LEADING_ZERO type boolean OPTIONAL
ZERO_VALUES type boolean OPTIONAL
DDIC_REFERENCE type string OPTIONAL
OUTPUT_LENGTH type LVC_OUTLEN OPTIONAL
POSITION type I OPTIONAL
ALIGNMENT type I OPTIONAL
QUANTITY_COLUMN type LVC_QFNAME OPTIONAL
CURRENCY_COLUMN type LVC_QFNAME OPTIONAL
DECIMAL_PLACES type LVC_DECMLS OPTIONAL,
SET_ALV_FROM_TEMPLATE
IMPORTING
CONTAINER type ref to CL_GUI_CUSTOM_CONTAINER OPTIONAL
TITLE type LVC_TITLE OPTIONAL
MENU_REPORT type SYREPID OPTIONAL
MENU_PFSTATUS type SYPFKEY OPTIONAL
SKIP_VARIANT_SUPPORT type BOOLEAN DEFAULT abap_false
CHANGING
CONTENT type TABLE
SALV_TABLE type ref to CL_SALV_TABLE OPTIONAL,
DISPLAY
IMPORTING
TITLE type ANY OPTIONAL
REFRESH type BOOLEAN DEFAULT abap_false,
SET_SORT
IMPORTING
FIELDNAME type string
DESCENDING type boolean DEFAULT abap_false
SUBTOTAL type boolean DEFAULT abap_false,
SET_LAYOUT_PROTECTION
IMPORTING
VALUE type BOOLEAN DEFAULT abap_true,
SET_NO_BUTTONS,
SET_HEADER_LINE
IMPORTING
COL1 type any OPTIONAL
COL2 type any OPTIONAL
COL3 type any OPTIONAL
COL4 type any OPTIONAL
COL5 type any OPTIONAL
COL6 type any OPTIONAL
RESET_HEADER type boolean DEFAULT ABAP_FALSE
PREFERRED PARAMETER COL1
RETURNING VALUE(HEADER) TYPE REF TO CL_SALV_FORM_LAYOUT_GRID,
SET_FOOTER_LINE
IMPORTING
COL1 type any OPTIONAL
COL2 type any OPTIONAL
COL3 type any OPTIONAL
COL4 type any OPTIONAL
COL5 type any OPTIONAL
COL6 type any OPTIONAL
RESET_FOOTER type boolean DEFAULT ABAP_FALSE
WITH_GRID_LINES type boolean DEFAULT ABAP_FALSE
PREFERRED PARAMETER COL1
RETURNING VALUE(FOOTER) TYPE REF TO CL_SALV_FORM_LAYOUT_GRID,
ADD_GENERAL_TOOLTIP
IMPORTING
TYPE type SALV_DE_CONSTANT DEFAULT CL_SALV_TOOLTIP=>C_TYPE_ICON
VALUE type ANY
TOOLTIP type ANY OPTIONAL,
SET_SELECTION_MODE
IMPORTING
VALUE type I DEFAULT 0.
PROTECTED SECTION.
DATA: RF_ALV_TABLE type ref to CL_SALV_TABLE.
PRIVATE SECTION.
DATA:
RF_ALV_HEADER type ref to CL_SALV_FORM_LAYOUT_GRID,
VA_ALV_HEADER_LINE type SYINDEX,
RF_ALV_FOOTER type ref to CL_SALV_FORM_LAYOUT_GRID,
VA_ALV_FOOTER_LINE type SYINDEX,
RF_TABLE_CONTENT type ref to DATA ##NEEDED.
ENDCLASS.
*---------------------------------------------------------------------
* C L A S S I M P L E M E N T A T I O N
*---------------------------------------------------------------------
CLASS lcl_easy_alv IMPLEMENTATION.
METHOD SET_FIELD .
* This method allows changes to the columns on the ALV report. An overview:
* IS_KEY - determines whether the field is a key field (placed up front)
* IS_HIDDEN - the field is not on the initial display, but the end user can
* add it to the report
* IS_UNAVAILABLE - the field is a technical field, not on display and can
* also not be added to the report
* TOOLTIP - bit of information that shows up when the mouse is hovering
over
* the column header name
* DESCRIPTION_OVERALL - the description that will be used for the short,
* medium as well as the long description. Please note: these descriptions
* are defaulted from the data dictionary, thus the description should
only
* be changed if it does not show correctly on the ALV report.
* DESCRIPTION_SHORT / _MEDIUM / _LONG - individual descriptions
* LEADING_ZERO - to make the report show leading zero's for the column
* ZERO_VALUES - for numeric columns: indicate that 0 should not be
displayed
* DDIC_REFERENCE - change the description and other properties of a field
* by setting the DDIC_REFERENCE to e.g. 'MARA-MATNR' (tablename hyphen
* fieldname).
* IS_ICON - the field holds an ICON code such as @AB@ which is recognized
* by the ALV. This setting allows usage of tooltip functionality on
* the level of reported lines.
* IS_HOTSPOT - the field (whole column) value is underlined and the report
* will respond to a a single click
* IS_EXCEPTION - the field holds a code for the exception or status setup
* which is defaulted to group 1 (traffic light icons, value 0 to 3).
Tooltip
* texts can also be made available for this.
* POSITION - when a column is not in the right location it can be
* relocated by setting the column position.
DATA: lva_scrtext_s TYPE scrtext_s,
lva_scrtext_m TYPE scrtext_m,
lva_scrtext_l TYPE scrtext_l,
lva_fieldname TYPE lvc_fname,
lva_tooltip TYPE lvc_tip,
lwa_ddic_reference TYPE salv_s_ddic_reference,
lva_hidden_flag TYPE sap_bool.
TRY.
lva_fieldname = fieldname.
SET LOCALE LANGUAGE sy-langu.
TRANSLATE lva_fieldname TO UPPER CASE.
IF position IS SUPPLIED.
rf_columns_table->set_column_position( columnname = lva_fieldname
position = position ).
ENDIF.
rf_column_table ?= rf_columns_table->get_column( lva_fieldname ).
IF is_hidden IS SUPPLIED.
IF ( is_hidden = abap_true ).
lva_hidden_flag = abap_false.
ELSE.
lva_hidden_flag = abap_true.
ENDIF.
rf_column_table->set_visible( lva_hidden_flag ).
ENDIF.
IF is_key IS SUPPLIED.
rf_column_table->set_key( is_key ).
ENDIF.
IF is_icon IS SUPPLIED.
rf_column_table->set_icon( is_icon ).
ENDIF.
IF is_hotspot IS SUPPLIED.
IF is_hotspot = abap_true.
rf_column_table->set_cell_type( if_salv_c_cell_type=>hotspot ).
ELSE.
rf_column_table->set_cell_type( if_salv_c_cell_type=>text ).
ENDIF.
ENDIF.
IF is_checkbox IS SUPPLIED.
IF is_checkbox = abap_true.
rf_column_table->set_cell_type( if_salv_c_cell_type=>checkbox ).
ELSE.
rf_column_table->set_cell_type( if_salv_c_cell_type=>text ).
ENDIF.
ENDIF.
IF is_button IS SUPPLIED.
IF is_button = abap_true.
rf_column_table->set_cell_type( if_salv_c_cell_type=>button ).
ENDIF.
ENDIF.
IF is_exception IS SUPPLIED.
rf_columns_table->set_exception_column( value = lva_fieldname group
= '1' ).
ENDIF.
ENDIF.
IF currency_column IS SUPPLIED.
rf_column_table->set_currency_column( currency_column ).
ENDIF.
IF is_unavailable IS SUPPLIED.
rf_column_table->set_technical( is_unavailable ).
ELSE.
* Default setting: the field should be marked as non technical
rf_column_table->set_technical( abap_false ).
ENDIF.
IF alignment IS SUPPLIED.
rf_column_table->set_alignment( alignment ).
ENDIF.
IF output_length IS SUPPLIED.
rf_column_table->set_output_length( output_length ).
ENDIF.
if decimal_places IS SUPPLIED.
rf_column_table->set_decimals( decimal_places ).
endif.
CATCH cx_salv_not_found
cx_salv_data_error.
ENDTRY.
ENDMETHOD.
method SET_ALV_FROM_TEMPLATE .
* The ALV report is linked to a (single) internal table with data
* which is linked to the ALV class via this method. When the data
* table is altered after linking it to the class, the changes are
* picked up automatically (the display( ) method has a refresh
* option).
data: lrf_exception type ref to cx_salv_msg ##NEEDED,
lva_container_name type string,
lva_layout_key type salv_s_layout_key.
salv_table = rf_alv_table.
endmethod.
method DISPLAY .
data: lv_title type LVC_TITLE.
* When the ALV report is ready to be displayed, this method will
* compose the ALV and display it full screen.
check me->rf_alv_table is bound.
if rf_alv_header is bound.
rf_alv_table->set_top_of_list( rf_alv_header ).
rf_alv_table->set_top_of_list_print( rf_alv_header ).
endif.
if rf_alv_footer is bound.
rf_alv_table->set_end_of_list( rf_alv_footer ).
rf_alv_table->set_end_of_list_print( rf_alv_footer ).
endif.
if refresh = abap_true.
rf_alv_table->refresh( ).
else.
rf_alv_table->display( ).
endif.
endmethod.
method SET_SORT .
* Set a sort field, also allows subtotalling to be switched on. The
* latter will only have effect when set_aggregate( ) is also used.
* Add several sort fields by calling this method several times.
data: lva_fieldname type lvc_fname,
lva_sort_sequence TYPE SALV_DE_SORT_SEQUENCE.
rf_sorts->add_sort(
columnname = lva_fieldname
subtotal = subtotal
sequence = lva_sort_sequence ).
set_field( fieldname ).
catch cx_salv_not_found
cx_salv_existing
cx_salv_data_error.
endtry.
endmethod.
method SET_LAYOUT_PROTECTION .
* In some reports the sequence in which the records are displayed should
* not be changed. This method can be used to remove the sort and filter
* buttons from available ALV functions.
data: lva_not_value type sap_bool.
endmethod.
method SET_NO_BUTTONS .
endmethod.
method SET_HEADER_LINE .
* The ALV report supports headers, a block of text that is presented on
* every ALV screen. The block consists of several lines and each line
* has up to 6 columns. This method add's a line to the header.
* NOTE: headers and footers do not work in custom controls (dynpro)
data: lrf_flow type ref to cl_salv_form_layout_flow.
header = rf_alv_header.
endmethod.
method SET_FOOTER_LINE .
* As with the header - this method adds a line to the footer of the ALV
* Please note: if the value is numeric, it will be displayed right-aligned.
data: lrf_text type ref to cl_salv_form_text,
lrf_layout_data type ref to cl_salv_form_layout_data_grid,
lrf_str type string.
endmethod.
method ADD_GENERAL_TOOLTIP .
data: lrf_tooltips type ref to cl_salv_tooltips,
lva_value type lvc_value,
lva_tooltip type lvc_tip.
endmethod.
method SET_SELECTION_MODE .
* Protected method: call from local class to use. This method
* can be used to control how line/column selections should work.
* Check interface IF_SALV_C_SELECTION_MODE for possible values:
* 0=No selection, 1=Individual selection, 2=Mult.selection
* 3= Cell selection and 4=Line and Column Selection
check me->rf_alv_table is bound.
if rf_selections is not bound.
rf_selections = rf_alv_table->get_selections( ).
endif.
rf_selections->set_selection_mode( value ).
endmethod.
ENDCLASS.