ALV grid learning notes -- Double Click Event

Source: Internet
Author: User

At the end of October, we conducted training on bc412. After class, we did some experiments and recorded these experiments from today, so that we can query them when necessary! (Unfortunately, the company has organized a lot of training, but it is rarely delivered in actual work, so it can only be recorded, for fear of forgetting to use it later ). today, we mainly record how to implement double-click events in the ALV grid event. this requirement should be applied in many cases, so we should record it first.

First, let's talk about the implementation principle of the ALV grid double-click event: ALV grid inherits from the class interface cl_gui_alv_grid, and many methods and events have been defined in the class interface cl_gui_alv_grid. For example

The set_table_for_first_display method can be found in methods of cl_gui_alv_grid. Therefore, if we need to check which methods or events can be used in ALV grid, we only need to select class/interfase in repository browser and enter cl_gui_alv_grid, you can see the defined menthod and events. To put it bluntly, we need to implement a dobule Click Event of ALV grid in this experiment. We can find an event like "double_click" in the events of cl_gui_alv_grid. What parameters does this double_click receive? Double-click double_click and select the double_click time in the right column. There is a paremeters button in the upper-left corner. After clicking this button, we can see three parameters: e_row, e_column, and es_row_no. OK. Now the event has been found. The next task we need to do is to define a class to implement the event and register the event to our ALV grid. The following is an example:

1. Draw a custom control in screen and name it alv_grid. It is defined in process before output.

Module status_0100, defined in process after input

Module user_command_0100.

2. Define a program named

Grid_event_receiver class. The Code is as follows:

 

Class grid_event_receiver definition.
Public section.
Methods:
Handler_double_click
For event double_click of cl_gui_alv_grid
Importing e_row e_column,
Endclass. "grid_event_rece

3. Implement the class grid_event_receiver in the program. The Code is as follows:

 

Class grid_event_receiver implementation.
Method handler_double_click.
Data: ls_sflight like line of gt_sflight.
Read Table gt_sflight index e_row-index into ls_sflight.
Select * From sbook into Table gt_sbook
Where carrid = ls_sflight-carrid
And connid = ls_sflight-connid
And fldate = ls_sflight-fldate.
Perform detail_list.

Endmethod.  

"Handler_double_click
Endclass. "grid_event_receiver implementation

With the above code, we can see that in the handler_double_click event, the index of paremeter e_row (indicating the row of double-click event) in our dobule_click event reads data from the gt_sflight table, then, read data from the table sbook and execute the form detail_list.

4. Define some variables in the program. The Code is as follows:

 

Data: custom_container type ref to cl_gui_custom_container, "custom_container: The container of grid1
Grid1 type ref to cl_gui_alv_grid, "the main ALV grid to show the mail data
Grid2 type ref to cl_gui_alv_grid, "the detail ALV grid to show the detail data
Dialogbox_container type ref to cl_gui_dialogbox_container, "dialogbox_container: The container of grid2
Event_receiver type ref to grid_event_receiver, "event_receiver: Point to grid_event_recerive

5. read data from moudule of PbO and display the data in grid1 and register the double_click event to grid1. In  

In the status_0100 module, the variables defined in the fourth part should be used as instances, and then

The set_table_for_first_display method displays data. Finally, you need to register the previously defined double click event to the grid. The Code is as follows:

 

If custom_container is initial.
Perform get_data tables gt_output []. "Get data from table and fill the data into internal table gt_output
Create object custom_container "create the instance of custom_container
Exporting
Container_name = 'alv _ grie' "set the container_name to 'alv _ grid' (define in screen)
Exceptions
Cntl_error = 1
Cntl_system_error = 2
Create_error = 3
Lifetime_error = 4
Lifetime_dynpro_dynpro_link = 5.
Create object grid1 exporting I _parent = custom_container. "create the instance of grid1 and set custom_container as grid1's container
Gs_layout-grid_title = 'flight '(100 ).
Gs_layout-excp_fname = g_lights_name.
Gs_layout-sel_mode = 'A '.
Call method grid1-> set_table_for_first_display "Call the method to show data
Exporting
I _structure_name = 'sflight'
Changing
It_outtab = gt_output []
* Exceptions
* Invalid_parameter_combination = 1
* Program_error = 2
* Too_many_lines = 3
* Others = 4.
If SY-SUBRC <> 0.
* Message ID SY-MSGID type SY-MSGTY number SY-MSGNO
* With SY-MSGV1 SY-MSGV2 SY-MSGV3.
Endif.
Create object event_receiver. "create the instance of event_receiver
Set handler event_receiver-> handler_double_click for grid1. "register the double_click event to grid1
Endif.

6. process other code in the pai module.

Through the above steps, we can implement the double-click event of ALV grid. Note that the above Code does not provide instances for grid2 and dialogbox_container. The instantiation of the two and how to place detailed data in the implementation process of the dobule Click Event (corresponding to  

Perform detail_list ). The code in detail_list is as follows:

 

Form detail_list.
Create object dialogbox_container "create the instance of dialogbox_container
Exporting
Maximum = 100
Left = 1, 150
Width = 800
Height = 200
Lifetime = cntl_lifetime_dynpro
.
Create object grid2 "create the instance of grid2 and set dialogbox_container as its container
Exporting I _parent = dialogbox_container.
Call method grid2-> set_table_for_first_display "Call the method to show the data
Exporting
I _structure_name = 'sBook'
Changing
It_outtab = gt_sbook.
Endform. "detail_list

Now, how to implement double-click events in ALV grid is described here. In the next article, I will record how to display data in ALV grid in the form of traffic lights.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.