Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

class

Former Member
0 Likes
994

hi

i want to know the coding of registering the double click row column event of class cl_gui_alv_grid.

thanks.

aditya

1 ACCEPTED SOLUTION
Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
947

Hi,

<b>First you need to create a separate class, it will be used for treatment of the events</b>

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column.

PRIVATE SECTION.

ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_double_click.

    • Insert here your code

ENDMETHOD. "handle_double_click

ENDCLASS.

<b>You must creates a object for this class and generates an Instance.</b>

CREATE OBJECT event_receiver.

CALL METHOD grid1->set_table_for_first_display

EXPORTING " i_structure_name = ' '

is_variant = gs_layout

i_save = c_a

is_layout = gs_lay

CHANGING it_outtab = gt_tabelas

it_fieldcatalog = catalog.

<b>Finally, activates the events.</b>

SET HANDLER event_receiver->handle_double_click FOR grid1.

<b>The method "handle_double_click" is executed automatically when you execute a double click on rows.</b>

Regards.

Marcelo Ramos

8 REPLIES 8
Read only

Former Member
0 Likes
947

Hi Aditya,

This is the implementation of the event

class lcl_event_receiver_dbox implementation.

method on_close.

call method sender->free.

endmethod.

endclass.

Reward points if helpful.

Cheers

Shafiq

Read only

0 Likes
947

Not sure if the previous post(er) has understood the question but here's the PROPER way to do it and without using a separate class for your event receivers.

Here's a sample class using several events.

Use the EVENT DOUBLE_CLICK as it's in the PUBLIC section of ckl_gui_alv_grid.

If you really need the protected sections then use my commented Ïnheriting statement and call the superclass as shown in the commented out code, however the double_click event returns you row / column and absolute row in any case.

*

CLASS zcl_dog DEFINITION " inheriting from cl_gui_alv_grid.

.

PUBLIC SECTION.

METHODS:

constructor

IMPORTING z_object type ref to zcl_dog,

  • i_parent type ref to cl_gui_custom_container,

display_grid

CHANGING it_fldcat type lvc_t_fcat,

build_dynamic_structures

CHANGING it_fldcat TYPE lvc_t_fcat.

PRIVATE SECTION.

METHODS:

on_user_command FOR EVENT before_user_command OF cl_gui_alv_grid

IMPORTING e_ucomm

sender,

on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object

e_interactive,

on_dubbelklik FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row

e_column

es_row_no,

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed,

handle_data_changed_finished

FOR EVENT data_changed_finished OF cl_gui_alv_grid

IMPORTING e_modified

et_good_cells,

verwerk

IMPORTING program type sy-repid,

return_structure,

create_dynamic_fcat

EXPORTING it_fldcat TYPE lvc_t_fcat,

create_dynamic_table

IMPORTING it_fldcat TYPE lvc_t_fcat

EXPORTING dy_table TYPE REF TO DATA.

DATA:

lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI

zog LIKE LINE OF lr_rtti_struc->components, "RTTI

wa_it_fldcat TYPE lvc_s_fcat,

it_fldcat TYPE lvc_t_fcat,

dy_table TYPE REF TO data,

dy_line TYPE REF TO data,

struct_grid_lset TYPE lvc_s_layo,

grid_container1 TYPE REF TO cl_gui_custom_container,

grid1 TYPE REF TO cl_gui_alv_grid.

TYPES:

struc LIKE zog.

DATA:

zogt TYPE TABLE OF struc.

ENDCLASS.

CLASS zcl_dog IMPLEMENTATION.

METHOD constructor.

  • CALL METHOD super->constructor

  • EXPORTING

  • i_appl_events = 'X'

  • i_parent = i_parent.

.

CREATE OBJECT grid_container1

EXPORTING

container_name = 'CCONTAINER1'.

CREATE OBJECT grid1

EXPORTING

i_parent = grid_container1.

SET HANDLER z_object->on_user_command for grid1.

SET HANDLER z_object->on_toolbar for grid1.

SET HANDLER Z_OBJECT->handle_data_changed_finished FOR grid1.

SET HANDLER Z_OBJECT->on_dubbelklik FOR grid1.

CALL METHOD grid1->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

ENDMETHOD.

METHOD on_dubbelklik.

break-point 1.

ENDMETHOD.

METHOD handle_data_changed.

  • Insert user code here if required

  • this method is entered if user ENTERS DATA.

ENDMETHOD.

METHOD handle_data_changed_finished.

  • Insert user code here if required

  • Method entered here after data entry has finished.

ENDMETHOD.

METHOD return_structure.

lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( mt_toolbar.

ENDMETHOD.

METHOD verwerk.

PERFORM verwerk IN PROGRAM (program).

LEAVE PROGRAM.

ENDMETHOD.

Cheers

Jimbo

Read only

Former Member
0 Likes
947

hi,

chk the demo programs BCALV_GRID_02 and BCALV_GRID_03.

regards,

priya.

Read only

0 Likes
947

I usually think a real practical piece of code with a simple example is better than trying to plough through a lot of the SAP provided examples --especially that Plane / Seat type of application.

The other problem with the SAP applications is that the event receivers are defined in a separate class so it makes saving a Generic global class with SE24 not very convenient.

The Class in my previous post contains everything it needs in the SAME class so you can then save this with SE24 and create very small ABAPS to manipulate often quite complex tables with minimal abap coding.

Using the class in my above post here's a simple demo. It creates a table of 200 entries from KNA1.

If you double click on any cell you'll get taken into the method where there's a break-point.

(Create a Blank screen SE51 with a custom container called CCONTAINER1. Add the foloowing logic in the ecreen

PBO ===> MODULE status_0100.

You dont need a PAI. The EVENTS all handle the input).

Program ZJIMBOTESTXX.

  • Jimbo 2007.

FIELD-SYMBOLS :

<fs1> TYPE ANY,

<fs2> TYPE STANDARD TABLE,

<dyn_table> TYPE STANDARD TABLE,

<orig_table> TYPE STANDARD TABLE,

<dyn_field>,

<dyn_wa>.

INCLUDE ZZJIMBOXX_INCL. "<===== This is the CLASS definition in my prev.

  • post in this thread.

INCLUDE <icon>.

TABLES : KNA1.

TYPES: BEGIN OF s_elements,

kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

stras TYPE kna1-stras,

telf1 TYPE kna1-telf1,

ort01 TYPE kna1-ort01,

pstlz TYPE kna1-pstlz,

END OF s_elements.

DATA: z_object type ref to zcl_dog, "Instantiate our class

grid_container1 type ref to cl_gui_custom_container,

t_elements TYPE TABLE OF s_elements, "refers to our ITAB

wa_elements TYPE s_elements,

wa_dyn_table_line TYPE REF TO DATA,

it_fldcat TYPE lvc_t_fcat,

new_table TYPE REF TO DATA,

dy_table TYPE REF TO data,

dy_line TYPE REF TO data.

START-OF-SELECTION.

CALL SCREEN 100.

END-OF-SELECTION.

MODULE status_0100 OUTPUT.

ASSIGN wa_elements TO <fs1>.

CREATE OBJECT z_object EXPORTING z_object = z_object.

  • i_parent = grid_container1.

CALL METHOD z_object->build_dynamic_structures

CHANGING it_fldcat = it_fldcat.

PERFORM populate_dynamic_itab.

CALL METHOD z_object->display_grid

CHANGING it_fldcat = it_fldcat.

ENDMODULE.

MODULE user_command_0100 INPUT.

  • PAI not needed as we are using EVENTS

ENDMODULE.

FORM populate_dynamic_itab.

SELECT kunnr name1 stras telf1 ort01 pstlz

UP TO 200 rows

FROM KNA1

INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.

  • Populate Dynamic table and save a copy

  • create 2nd Dyn table to hold original data

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fldcat

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <orig_table>.

CREATE DATA dy_line LIKE LINE OF <orig_table>.

ASSIGN dy_line->* TO <dyn_wa>.

<orig_table> = <dyn_table>.

ENDFORM.

FORM VERWERK.

break-point 1.

  • Orig table is in dynamic table <orig_table>

  • ALV GRID changed table is in <dyn_table>.

Loop at <orig_table> into <dyn_wa>.

  • Do what you want

  • end

endloop.

Cheers

Jimbo

Read only

Former Member
0 Likes
947

hi,

Chk these standard pgms.

BCALV_EDIT_01 This report illustrates the simplest case of using an editable/noneditable ALV Grid Control.

BCALV_EDIT_02 This report illustrates how to set chosen cells of an ALV Grid Control editable.

BCALV_EDIT_03 In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.

The report checks the input value(s) semantically and provides protocol messages in case of error

Regards

Reshma

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
948

Hi,

<b>First you need to create a separate class, it will be used for treatment of the events</b>

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column.

PRIVATE SECTION.

ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_double_click.

    • Insert here your code

ENDMETHOD. "handle_double_click

ENDCLASS.

<b>You must creates a object for this class and generates an Instance.</b>

CREATE OBJECT event_receiver.

CALL METHOD grid1->set_table_for_first_display

EXPORTING " i_structure_name = ' '

is_variant = gs_layout

i_save = c_a

is_layout = gs_lay

CHANGING it_outtab = gt_tabelas

it_fieldcatalog = catalog.

<b>Finally, activates the events.</b>

SET HANDLER event_receiver->handle_double_click FOR grid1.

<b>The method "handle_double_click" is executed automatically when you execute a double click on rows.</b>

Regards.

Marcelo Ramos

Read only

0 Likes
947

As I showed above you DON'T NEED to create a separate class for the events.
This can ALL be handled in THE SAME CLASS.

Thís makes creating a " Global Generalized Class" which can then be used by any application program very easy. Just save it with SE24.

All I have to do then in any application program where I need to manipulate a table is simply the following

define my data structures

  • Any ITAB structure includind DEEP structures

  • just use parts of KNA1 as an example although the elements don't have to be in * DDIC

TYPES: BEGIN OF s_elements,

kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

stras TYPE kna1-stras,

telf1 TYPE kna1-telf1,

ort01 TYPE kna1-ort01,

pstlz TYPE kna1-pstlz,

END OF s_elements.

DATA: z_object type ref to zcl_dog, "Instantiate our class

grid_container1 type ref to cl_gui_custom_container,

t_elements TYPE TABLE OF s_elements, "refers to our ITAB

wa_elements TYPE s_elements,

wa_dyn_table_line TYPE REF TO DATA,

it_fldcat TYPE lvc_t_fcat,

wa_it_fldcat TYPE lvc_s_fcat,

new_table TYPE REF TO DATA,

dy_table TYPE REF TO data,

dy_line TYPE REF TO data.

Instantiate the CLASS

CREATE OBJECT z_object EXPORTING z_object = z_object.

  • i_parent = grid_container1.

CALL METHOD z_object->build_dynamic_structures

CHANGING it_fldcat = it_fldcat.


poulate the ITAB

and then display the GRID

CALL METHOD z_object->display_grid
CHANGING it_fldcat = it_fldcat.

all the events are contained in the class so you can program whatever action you like .

When using classes / OO it's better to totally think OO rather than use classes and object as "super glorified function modules".

Once you've built up some decent Z_classes you can probably remove about 95% of the legacy Z_ABAPS most shops have and creating new one's becomes a very quick exercise.

Cheers

Jimbo

Read only

Former Member
0 Likes
947

thanks