1, get the cursor ALV method
*&---------------------------------------------------------------------*
*& How to get the ALV of your cursor
*&---------------------------------------------------------------------*
**top**
DATA:
P_control TYPE REF to Cl_gui_control,
P_control1 TYPE REF to Cl_gui_control.
**i01**
* Get cursor location ALV
IF P_control is INITIAL.
CREATE OBJECT P_control.
ENDIF.
Call METHOD P_control->get_focus
Importing
CONTROL = P_control1
EXCEPTIONS
Cntl_error = 1
Cntl_system_error = 2.
Case P_control1.
* On the occasion of ALV
When G_grid1.
......
* Under the ALV of the occasion
When G_grid2.
......
When OTHERS.
Endcase.
2. Get and set selection method
*&---------------------------------------------------------------------*
*&, setting Select Row method
*&---------------------------------------------------------------------*
**top**
DATA:
G_rows TYPE Lvc_t_row,
g_id TYPE lvc_t_roid.
**i01**
* Get Selection Line
Call METHOD G_grid1->get_selected_rows
Importing
Et_index_rows = G_rows2
Et_row_no = G_id2.
**o01**
IF not G_rows is INITIAL and
Not g_id is INITIAL.
* Set Selection column location
Call METHOD G_grid1->set_selected_rows
Exporting
It_index_rows = G_rows
It_row_no = g_id.
ENDIF.
3, get, set the current ALV cursor position
*&---------------------------------------------------------------------*
*&, sets the current ALV cursor position
*&---------------------------------------------------------------------*
**top**
Data:wa_colum TYPE Lvc_s_col,
Wa_row TYPE lvc_s_roid.
**i01**
* Get current ALV cursor position
Call METHOD G_grid1->get_current_cell
Importing
es_col_id = Wa_colum
Es_row_no = Wa_row.
**o01**
* Set current ALV cursor position
Call METHOD g_grid1->set_current_cell_via_id
Exporting
is_column_id = Wa_colum
Is_row_no = Wa_row.
4, get, set the upper left corner of the row and column (fixed ALV rows and columns scroll bar)
*&---------------------------------------------------------------------*
*&, sets the row and column in the upper-left corner (fixed ALV rows and columns scroll bar)
*&---------------------------------------------------------------------*
**top**
Data:wa_info TYPE Lvc_s_col,
wa_row_id TYPE lvc_s_roid.
**i01**
* Get the rows and columns in the upper left corner (fixed ALV row and column scroll bars)
Call METHOD g_grid1->get_scroll_info_via_id
Importing
Es_col_info = Wa_info
Es_row_no = wa_row_id.
**o01**
* Set the rows and columns in the upper left corner (fixed ALV row and column scroll bars)
Call METHOD g_grid1->set_scroll_info_via_id
Exporting
Is_col_info = Wa_info
Is_row_no = wa_row_id.
5, Screen value preservation method
*&---------------------------------------------------------------------*
The method of saving *& drawing face value
*&---------------------------------------------------------------------*
**i01**
DATA:
L_valid (1) TYPE C VALUE ' X '.
* Save Screen value
Call METHOD G_grid1->check_changed_data
Importing
E_valid = L_valid.
6, cell input can control method
*&---------------------------------------------------------------------*
The method of *& the force of the cell into the system
*&---------------------------------------------------------------------*
**o01**
* Cell control can be in force, input set ' 1 '.
Call METHOD G_grid1->set_ready_for_input
Exporting
I_ready_for_input = 1.
* Cell control is not in force, input set ' 0 '.
Call METHOD G_grid1->set_ready_for_input
Exporting
I_ready_for_input = 0.
7. Double-click the Event Trigger method
*&---------------------------------------------------------------------*
*& Double-click event Firing method
*&---------------------------------------------------------------------*
*---TOP-----*
CLASS Lcl_event_handler DEFINITION.
public section.
METHODS Handle_double_click
For EVENT Double_click of Cl_gui_alv_grid
Importing E_row "Row ID
E_column "Column name
Es_row_no. The Value row ID
Endclass. "Lcl_event_receiver DEFINITION
DATA:
G_event_handler TYPE REF to Lcl_event_handler,
*---FO1-----*
CLASS Lcl_event_handler implementation.
* Method:double CLICK
METHOD:
Handle_double_click.
Clear:flg_changed.
* Double-click on event Handling
READ TABLE it_data INDEX e_row into Wa_data.
EndMethod. "Handle_double_click
Endclass. "Lcl_event_handler implementation
*---OO1-----*
* Add ALV Event
CREATE OBJECT G_event_handler.
* Add ALV Handle
SET HANDLER G_event_handler->handle_double_click for G_GRID1.
Call METHOD g_grid1->register_edit_event "Registering Update events
Exporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
8, ALV Cell value Change Event triggering method
*&---------------------------------------------------------------------*
*& ALV Value change trigger check
*&---------------------------------------------------------------------*
*---TOP-----*
CLASS lcl_alv_receiver DEFINITION.
Public section.
METHODS handle_data_changed
For EVENT data_changed of Cl_gui_alv_grid
Importing er_data_changed
E_onf4
E_onf4_before
E_onf4_after.
Endclass. "Lcl_alv_receiver DEFINITION
DATA:
G_event_handler TYPE REF to Lcl_alv_receiver,
*---FO1-----*
CLASS lcl_alv_receiver implementation.
* method:handle_data_changed
METHOD handle_data_changed.
Data:it_mod_data TYPE Lvc_t_modi,
Wa_mod_data TYPE Lvc_s_modi.
It_mod_data = Er_data_changed->mt_mod_cells.
READ TABLE it_mod_data INDEX 1 into Wa_mod_data.
*-----------such as stand---------------------*
* IF wa_mod_data-fieldname = ' zwgt ' and
* Wa_mod_data-value < ' 0 '.
* MESSAGE ID ' xx ' TYPE ' I ' number 001
* with Wa_mod_data-value ' weight cannot be negative! ‘.
* LEAVE screen.
* ENDIF.
*-----------such as END-----------------------*
EndMethod. "Handle_double_click
Endclass. "Lcl_alv_receiver implementation
*---OO1-----*
* Add ALV Event
CREATE OBJECT G_event_handler.
* Add ALV Handle
SET HANDLER g_event_handler->handle_data_changed for G_GRID1.
Call METHOD g_grid1->register_edit_event "Registering Update events
Exporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
9. Implementation of dropdown list in ALV
*&---------------------------------------------------------------------*
Implementation of drop-down list in *& ALV
*&---------------------------------------------------------------------*
*---TOP-----*
DATA:
It_dropdown TYPE Lvc_t_drop,
Wa_dropdown TYPE Lvc_s_drop,
*---FO1-----*
* ALV's drop-down list edit
PERFORM Frm_dropdown_edit.
*&---------------------------------------------------------------------*
*& Form Frm_dropdown_edit
*&---------------------------------------------------------------------*
* ALV's drop-down list edit
*----------------------------------------------------------------------*
FORM Frm_dropdown_edit.
Clear:wa_dropdown.
Refresh:it_dropdown.
* You can change the assignment of the written dead to the value of the loop loop data.
* Order Area drop-down list content editing (for example)
Wa_dropdown-handle = ' 1 '. "1 in the corresponding Lvc_s_fcat" column
Wa_dropdown-value = ' D '. The values that are displayed
APPEND Wa_dropdown to It_dropdown.
Clear:wa_dropdown.
Wa_dropdown-handle = ' 1 '.
Wa_dropdown-value = ' A '.
APPEND Wa_dropdown to It_dropdown.
Clear:wa_dropdown.
Wa_dropdown-handle = ' 1 '.
Wa_dropdown-value = ' U '.
APPEND Wa_dropdown to It_dropdown.
Clear:wa_dropdown.
EndForm. "Frm_dropdown_edit
*---OO1-----*
Call METHOD g_grid1->set_drop_down_table "First_display before calling
Exporting
It_drop_down = It_dropdown.
* Settings for ALV items indicated by the table
MOVE ' C ' to wa_cat-just.
MOVE ' X ' to Wa_cat-edit.
MOVE ' 1 ' to Wa_cat-drdn_hndl. "ALV Control: Natural number, set drop-down list when pay ' 1 ', ' 2 ' ...
MOVE ' Zpo_area ' to wa_cat-fieldname.
MOVE ' order area ' to Wa_cat-coltext.
APPEND Wa_cat to It_cat.
CLEAR Wa_cat.
OO ALV Setting Save layout
http://wenku.baidu.com/link?url=- i04uqu4tgr13xme1tkzvrxl6xns8tqiqj919c6pjkh9uyzcaumfnji5phrlije7wlohph5z5l0whqwu0ahokjhzjzdkt2tvjxnl9cxmu0m
ALV OO Finishing