Вы находитесь на странице: 1из 5

1

Important Field Catalog Parameters:-


1. DO_SUM :- If this field is set to X, the system will calculate total of specified column n at the
bottom.
2. EMPHASIZE:- If this field is set, the ALV will use predefined color for highlighting the column.
The basic use is to color the entire column.
3. KEY:- If this field is set, the system will fix the column during horizontal scrolling.
4. STYLE:- To display field differently i. e. as button. There are many constant attributes of
class cl_gui_alv_grid is available. i.e. MC_STYLE_BUTTON.
5. NO_ZERO:- if this field set, no zeros will be displayed if the field is initial.

Important Layout Parameters:-


1. GRID_TITLE:- To display title between grid control and ALV toolbar.
2. NO_HEADERS :- To display columns without heading.
3. NO_TOOLBAR :- To hide the ALV toolbar.
4. SEL_MODE :- To enable the use to select lines ( multiple line in grid).
5. CTAB_FNAME :- Field name in output table for coloring Columns.
6. INFO_NAME :- Field name in output table for coloring Rows.

Checkbox Functionality :- The checkbox functionality has been replaced by selection buttons in front of
each row (field SEL_MODE of the layout structure set to A or D; when using the editable ALV Grid
Control, these selection buttons are always visible). Class methods like
GET_SELECTED_ROWS work only for this new functionality and not for checkboxex. Thus,
checkboxes should not be used for line selection but for a column as an additional or for an already
existing attribute.

Q How to exclude standard function button from ALV toolbar?


Ans:- To exclude those buttons, you fill a table of type UI_FUNCTIONS and pass it to the parameter
IT_TOOLBAR_EXCLUDING of the method set_table_for_first_display. The function codes for the
buttons may be acquired by inspecting the constant attributes of the class cl_gui_alv_grid. All function
for standard ALV toolbar button codes are starting with mc_fc_*** and MC_MB_ are for the function
menus. To hide the entire toolbar, you can set the field NO_TOOLBAR of the layout structure
to X. i.e.

DATA ls_exclude TYPE ui_func.


ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
APPEND ls_exclude TO pt_exclude.

NOTE:- we can get the function code from the attribute list of CL_GUI_GRID_DISPLAY class. All the
constants in attributes list with associated type UI_FUNC can be used.

Q How to allowed user to save and change layout of report? Or Purpose of is_variant
parameter in set_table_for_first_display method.
Ans:- Following steps:-
1. Define a structure of type disvariant i.e. W_VARIANT TYPE DISVARIANT.
2. Pass the program name to report parameter of it i.e. W_VARIANT-REPORT = SY-REPID.
3. Pass this structure to method set_table_for_first_display i.e.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
is_variant = w_variant
I_save = 'A'
2

4. If we want to allow the use to save his layout variant, the value for i_save parameter should be A.
Otherwise, he can only choose and change layout temporarily.

Q How to add button on ALV grid control in OOPS.


Ans: We use two of ALV Grid events . First is toolbar and second is user_command Steps to add
button ALV grid control:-
1. Define a custom class with two event handler methods for events toolbar and user_command of
cl_gui_alv_grid.
2. Toolbar event has two importing parameters :- e_object, e_interactive.
3. E_object is an object reference variable of type CL_ALV_EVENT_TOOLBAR_SET class. And this class
has attribute mt_toobar which is table type of ttb_button. Pass the values as follow:-
CONSTANTS:
* CONSTANTS FOR BUTTON TYPE
c_button_normal TYPE i VALUE 0,
c_menu_and_default_button TYPE i VALUE 1,
c_menu TYPE i VALUE 2,
c_separator TYPE i VALUE 3,
c_radio_button TYPE i VALUE 4,
c_checkbox TYPE i VALUE 5,
c_menu_entry TYPE i VALUE 6.

DATA: ls_toolbar TYPE stb_button.


* APPEND SEPARATOR TO THE NORMAL TOOLBAR
CLEAR ls_toolbar.
MOVE c_separator TO ls_toolbar-butn_type..
APPEND ls_toolbar TO e_object->mt_toolbar.
* APPEND A NEW BUTTON TO THE TOOLBAR . USE E_OBJECT OF EVENT TOOLBAR .
* E_OBJECT IS OF TYPE CL_ALV_EVENT_TOOLBAR_SET.
* THIS CLASS HAS ONE ATTRIBUTE MT_TOOLBAR WHICH IS OF TABLE TYPE
* TTB_BUTTON. THE STRUCTURE IS STB_BUTTON

CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
*This code is for giving space in between two icons
* CLEAR ls_toolbar.
* MOVE c_separator TO ls_toolbar-butn_type..
* APPEND ls_toolbar TO e_object->mt_toolbar.
* CLEAR ls_toolbar.
* MOVE 'SAVE' TO ls_toolbar-function.
* MOVE icon_display_text TO ls_toolbar-icon.
* MOVE 'Display flight' TO ls_toolbar-quickinfo.
* MOVE 'Display' TO ls_toolbar-text.
* MOVE ' ' TO ls_toolbar-disabled.
* APPEND ls_toolbar TO e_object->mt_toolbar.

4. To handle the click of above defined button, we need to handle function code (CHANGE as in
above case) in event handler method for user_command event of cl_gui_alv_grid. User_command
has importing parameter e_ucomm which returns the function code of button pressed. Using this we
can code as follow:
3

METHOD handle_user_command.
* HANDLE OWN FUNCTIONS IN THE TOOLBAR
CASE e_ucomm.
WHEN 'CHANGE'.
PERFORM change_flight.
ENDCASE.
ENDMETHOD. "handle_user_command

Q How to color a ROW in ALV OOPs?


Ans:- Steps to color a row:-
1. Create a structure for internal table and also include a structure element of type c length 4 i.e.
TYPES : BEGIN OF ty_tab.
INCLUDE STRUCTURE ytest_emp.
TYPES : ROW_COLOR(4) TYPE c.
TYPES : END OF ty_tab.
2. Prepare a layout as below
gs_layout-info_fname = 'ROW_COLOR'. it is element from internal table
structure.
Append the element with color code to internal table as below.
LOOP AT tab INTO wa_tab WHERE salary LT 50000. condition based
wa_tab-row_color = 'C600'.
MODIFY tab FROM wa_tab TRANSPORTING row_color.
ENDLOOP.
CLEAR wa_tab

* Char 4 and the characters is set as follows:


* Char 1 = C = This is a color property
* Char 2 = 6 = Color code (1 - 7)
* Char 3 = Intensified on/of = 1 = on
* Char 4 = Inverse display = 0 = of
Q How to color a COLUMN in ALV OOPs?
Ans:- If only column has to be colored, we only need to modify a EMPHASIS element of field catalog as
below:-

LOOP AT gt_fcat INTO gs_fcat WHERE fieldname = 'SALARY'.


MOVE 'C510' TO gs_fcat-emphasize.
MODIFY gt_fcat FROM gs_fcat TRANSPORTING emphasize.
ENDLOOP.

Q How to color a ROW and COLUMN together conditionally in ALV OOPs?


Ans:-
1. Create a structure for internal table and also include two more elements and internal table and
work area in this as follow:-
TYPES : BEGIN OF ty_tab.
INCLUDE STRUCTURE ytest_emp.
TYPES : row_color(4) TYPE c, " for Row Color
col_color TYPE lvc_t_scol. " for Column Color
TYPES : END OF ty_tab.

DATA : it_color TYPE TABLE OF lvc_s_scol,


wa_col_color TYPE lvc_s_scol.
4

2. To color a column, we need to make following changes to layout structure.


* for coloring column
p_gs_layout-ctab_fname = 'COL_COLOR'. for column ctab_fname element
CLEAR wa_tab. should be used
MOVE 'SALARY' TO wa_col_color-fname.
MOVE '6' TO wa_col_color-color-col.
MOVE '1' TO wa_col_color-color-int.
MOVE '1' TO wa_col_color-color-inv.

APPEND wa_col_color TO it_color.

LOOP AT tab INTO wa_tab WHERE salary EQ '60000'.


wa_tab-col_color[] = it_color[].
MODIFY tab FROM wa_tab TRANSPORTING col_color.
ENDLOOP.
CLEAR wa_tab.

* for coloring Row


p_gs_layout-info_fname = 'ROW_COLOR'. for column info_fname element of layout
CLEAR wa_tab. should be used
LOOP AT tab INTO wa_tab WHERE salary LT 50000.
wa_tab-row_color = 'C600'.
MODIFY tab FROM wa_tab TRANSPORTING row_color.
ENDLOOP.
CLEAR wa_tab.

Q Where the data captured data is stored in ALV Interactive Reports using user command?
Ans: We need pass a value to user command parameter i.e.

I_callback_user command = 'USER_COMMAND'.

Then we need to explicitly create Form ( subroutine ) with name USER_COMMAND.

FORM USER_COMMAND USING OK_CODE LIKE SY-UCOMM


SELFIELD TYPE SLIS_SELFIELD.

SELFIELD will store the contents of selected line. This is in case of simple ALV. In oops ALV, we use event
DOUBLE_CLICK. It return a E_ROW, E_COLUMN , ES_ROW_NO.

QHow can we display multiple alv's without using containers?


Ans:- Using Blocked ALV.

Q How to change Fieldcatalog dynamically?


Ans:- To change the field catalog during runtime, we can use the method 'get_frontend_fieldcatalog',
of class 'cl_gui_alv_grid'.

Step 1:- Create an internal table of type LVC_T_FCAT.

Step 2:- Call method 'get_frontend_fieldcatalog' of class cl_gui_alv_grid and populate the field catalog
using the parameter 'et_fieldcatalog' . This parameter will give you the field catalog of the current
displayed screen.

Step 3:- Now loop at the field catalog and make the required changes.

Step 4:- Call the method 'set_table_for_first_display' and pass the field catalog.
5

Q How to display cell of ALV as button?


Ans:- To make a cell to be displayed as a pushbutton, we have two steps. Firstly, insert a new inner table
of type LVC_T_STYL into your list data table.
Inserting an inner table to store cell display styles Fill this inner table for each field to be displayed as
pushbutton.
TYPES : BEGIN OF ty_tab.
INCLUDE STRUCTURE ytest_emp.
TYPES : row_color(4) TYPE c, " for Row Color
col_color TYPE lvc_t_scol, " for Column Color
cell_style TYPE lvc_t_styl. " to display cell as button
TYPES : END OF ty_tab.

DATA : wa_style TYPE lvc_s_styl,


gs_layout TYPE lvc_s_layo,

wa_style-fieldname = 'SALARY'.
wa_style-style = cl_gui_alv_grid=>mc_style_button.
gs_layout-STYLEFNAME = 'CELL_STYLE'.

Then, above structure need to up appended in cell_style table.

LOOP AT tab INTO wa_tab.


APPEND wa_style to wa_tab-cell_style.
MODIFY tab FROM wa_tab TRANSPORTING cell_style.
ENDLOOP.

Q Can we display output using alv gird object without created custom container class object?
Ans:- Yes we can display alv without custom container object as follow.

CREATE OBJECT alv


EXPORTING
i_parent = cl_gui_custom_container=>screen0.

CALL METHOD alv->set_table_for_first_display


EXPORTING
i_structure_name = tabname
CHANGING
it_outtab = <itab>.

CALL SCREEN 100.

Or we can use following code.


DATA : o_alv TYPE REF TO cl_salv_table.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = lt_msg.

* CATCH cx_salv_msg INTO lv_msg. "#EC NO_HANDLER


CALL METHOD o_alv->display( ).

ENDTRY.

Вам также может понравиться