Application Development 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: 

Event response of double click event of cl_gui_alv_grid class

YayatiEkbote
Contributor
0 Kudos

Hello guys,

For a custom requirement i have created an application using custom container and ALV grid display. As number of columns and rows are to be formed runtime, i have used dynamically created internal table using field symbols. My requirement is to display the row position and column position of the cell which is double clicked in input field on screen painter.

OR if row position and column position are filled in the input fields then the corresponding cell should be highlighted.

For the first condition i used custom event handler class for double click event.

I gave the screen fields name as

DATA: v_rowpos TYPE n LENGTH 2, "input field on screen for input and output

           v_colpos  TYPE c LENGTH 5. "input field on screen for input and output

CLASS zcl_events IMPLEMENTATION.

METHOD handle_double_click.

v_rowpos = e_row-index.

v_colpos = e_column-fieldname.

ENDMETHOD.

ENDCLASS.

When i double click the cell it fills the screen variables with values. But the values are not getting displayed in the input field on screen.

When i debugged, i found that after the execution of method in the class, PBO of the screen is not getting called, hence the values in the fields are not getting reflected on screen.

Please guide me how can i fill the screen fields with row position and column position of the cell selected.

Also how to highlight the cell if the row position and column position are filled in screen fields by user.

Regards,

Yayati Ekbote

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

So you want to update fields which are not part of the ALV grid, so you should trigger the PAI/PBO cycle. Did you try some tools like method cl_gui_cfw=>set_new_ok_code or FM SAPGUI_SET_FUNCTIONCODE.

Regards,

Raymond

13 REPLIES 13

YayatiEkbote
Contributor
0 Kudos

Hello friends,

I found the way how to highlight the cell if the row position and column position is entered in the input fields of screen.

I used the method set_current_cell_via_id of class cl_gui_alv_grid after the method set_table_for_first_display is executed.

But i am unable to get the row position and column position of cell which is double clicked, in the input fields of screen.

Regards,

Yayati Ekbote

Former Member
0 Kudos

Hi,

Are you calling the ALV in the PBO if screen or is it getting displayed when some action is performed on the screen? If it is not in the PBO,Have you called the screen again in method implementation?

Regards,

Sonal

former_member212002
Active Contributor
0 Kudos

To display the values in screen, Have you tried method REFRESH_TABLE_DISPLAY of CL_GUI_ALV_GRID?

DATA  :        gs_stbl type lvc_s_stbl .

** Row,Col Stable

  gs_stbl-row = 'X'.

  gs_stbl-col = 'X'.

    call method go_alv->refresh_table_display

      exporting

        is_stable = gs_stbl.

Cheers!

Abhinab.

0 Kudos

Hello Abhinab,

Thanks for reply, but refresh table display will refresh the internal table which i have passed to method set_table_for_first_display.

My problem is the values are not getting displayed in the INPUT FIELD of screen. And the reason is PBO is not getting called after event handler class method which i have declared.

Regards,

Yayati Ekbote

0 Kudos

Hi,

There are many standard programs available in SAP for these. Check SE38 with this bcalv*   and go through the flow how events and methods are called in.

Regards,

Swarna

0 Kudos

Yayati,

I guess REFRESH_ TABLE_DISPLAY refreshes the grid passed on to the method SET_TABLE_FOR_FIRST_DISPLAY.

Have a look in the documentation below?

refresh_table_display (SAP Library - ALV Grid Control (BC-SRV-ALV))

Cheers!

Abhinab

raymond_giuseppi
Active Contributor
0 Kudos

So you want to update fields which are not part of the ALV grid, so you should trigger the PAI/PBO cycle. Did you try some tools like method cl_gui_cfw=>set_new_ok_code or FM SAPGUI_SET_FUNCTIONCODE.

Regards,

Raymond

0 Kudos

Hello Raymond,

  Yes i had to write this statement 'LEAVE TO SCREEN 100' to go to PBO at the end of the method. Then only the values are getting displayed in the input field on the screen. And yes the input field is not part of the ALV_GRID. They are seperately drawn in screen painter.

But even if that works in case of hotspot click or double click on the cell, while the drag and drop events only ondrag event is triggered. ondrop event is not triggered which should follow ondrop event.

Regards,

Yayati Ekbote

0 Kudos

Hello Yayati,

Why don't you set the "the next screen" to 100 for your screen attributes? It would be much more easy for you and your system.

for the drap and drop...

1. Define the layout structure of type LVC_S_LAYO.

2.          Define your Drag & Drop behavior and get the associated handle using method get_handle

of class cl_dragdrop.

3.          Assign the handle to field s_dragdrop-row_ddid or s_dragdrop-col_ddid of the

layout structure.

4.          Pass the layout structure with method set_table_for_first_display

0 Kudos

Hello Hai,

I have done all the things as you have described. Drag and drop action is happening but method for event 'ondrop' is not getting triggered after method execution of method on event  'ondrag'.

I have set the handlers for both the events.

SET HANDLER o_events->handle_hotspot_click FOR o_grid.

SET HANDLER o_events->handle_on_drag FOR o_grid.

SET HANDLER o_events->handle_on_drop FOR o_grid.

Where o_events is object of the class lcl_events which i have declared for event handling.

And o_grid is the object of class cl_gui_alv_grid.

My problem is when i click the cell (single click / hotspot click ) the method handle_hotspot_click is called. But after the execution of the method,the control does not return to PBO.

In drag drop action the method for 'ondrag' event i.e. handle_on_drag is executed, but method for event 'ondrop' i.e. handle_on_drop is not getting triggered subsequently.

Regards,

Yayati Ekbote

0 Kudos

Hi Yayati,

In order to make it clear for what you needs, I give you a sample program that will work (I have tested), please look carefully in "Bold"

REPORT  zalv_dragdrop.

*Structure declaration for T016T

TYPES : BEGIN OF ty_t016t,

         brsch TYPE brsch,

         brtxt TYPE text1_016t,

         spras TYPE spras,

         END OF ty_t016t.

*Work area and internal table for  T016T

DATA : it_t016t TYPE STANDARD TABLE OF ty_t016t,

       wa_t016t TYPE ty_t016t.

*class declaration

CLASS lcl_dragdrop DEFINITION.

  PUBLIC SECTION.

    DATA: wa TYPE ty_t016t,

          index TYPE i.   "Index of Line to be moved

ENDCLASS.                    "LCL_DRAGDROP DEFINITION

*Application class definition

CLASS lcl_objdragdropapp DEFINITION.

  PUBLIC SECTION.

    METHODS:

*Handling Event Drag

      handle_alv_drag

        FOR EVENT ondrag

        OF cl_gui_alv_grid

        IMPORTING e_row e_column e_dragdropobj,

*Handling event DROP

      handle_alv_drop

        FOR EVENT ondrop

        OF cl_gui_alv_grid

        IMPORTING e_row e_column e_dragdropobj.

ENDCLASS.                    "LCL_objdragdropapp DEFINITION

*Application class implementation

CLASS lcl_objdragdropapp IMPLEMENTATION.

*  OnDrag event is used to 'fetch' information from the drag source.

  METHOD handle_alv_drag.

    DATA: dataobj TYPE REF TO lcl_dragdrop,

          line TYPE ty_t016t.

* Read dragged row

    READ TABLE it_t016t INDEX e_row-index INTO line.

* create and fill dataobject for events ONDROP

    CREATE OBJECT dataobj.

* Remembering row index to move a line

    MOVE e_row-index TO dataobj->index.

* store the dragged line.

    READ TABLE it_t016t INTO dataobj->wa INDEX e_row-index.

* Assigning data object to the refering event parameter

    e_dragdropobj->object = dataobj.

  ENDMETHOD.                    "HANDLE_ALV_DRAG

*Event handler for event 'OnDrop'. This event is used

*to use your dragged information in combination with your drop source.

  METHOD handle_alv_drop.

    DATA: dataobj TYPE REF TO lcl_dragdrop,

          drop_index TYPE i,

          stable TYPE lvc_s_stbl.

* Refresh Alv Grid Control without scrolling

    stable-row = 'X'.

    stable-col = 'X'.

* Catch-Statement to ensure the drag&drop-Operation is aborted properly.

    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.

      dataobj ?= e_dragdropobj->object.

      DELETE it_t016t INDEX dataobj->index.

      INSERT dataobj->wa INTO it_t016t INDEX e_row-index.

*Refreshing the ALV

      CALL METHOD c_alv->refresh_table_display

        EXPORTING

          i_soft_refresh = 'X'

          is_stable      = stable.

    ENDCATCH.

    IF sy-subrc <> 0.

* If anything went wrong aborting the drag and drop operation:

      CALL METHOD e_dragdropobj->abort.

    ENDIF.

  ENDMETHOD.                    "HANDLE_ALV_DROP

ENDCLASS.                    "LCL_objdragdropapp IMPLEMENTATION

*data declarations for alv

DATA:   c_dragdropapp TYPE REF TO lcl_objdragdropapp,

        c_dockingcont TYPE REF TO cl_gui_docking_container,

        c_alv TYPE REF TO cl_gui_alv_grid,

* reference variable to CL_DRAGDROP:

        c_dragdropalv TYPE REF TO cl_dragdrop,

        it_layout TYPE lvc_s_layo,

        it_fcat  TYPE lvc_t_fcat.            "Field catalogue

*declarations for handle event

DATA:   effect TYPE i,

        handle_alv TYPE i.

*initialization event

INITIALIZATION.

*start of selection event

START-OF-SELECTION.

*select data

  PERFORM fetch_data.

*ALV output

  PERFORM alv_output.

* Class definitions and method implementation for drag and drop

*&---------------------------------------------------------------------*

*&      Form  alv_CONTROLS

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM alv_controls.

* create docking container for alv control

  CREATE OBJECT c_dockingcont

    EXPORTING

        dynnr = '600'

        extension = 300

        side = cl_gui_docking_container=>dock_at_top.

* create alv control

  CREATE OBJECT c_alv

     EXPORTING i_parent = c_dockingcont.

* create the application object to handle the ABAP Objects Events

  CREATE OBJECT c_dragdropapp.

* Events alv control

*For Dragging

  SET HANDLER c_dragdropapp->handle_alv_drag FOR c_alv.

*For Dropping

  SET HANDLER c_dragdropapp->handle_alv_drop FOR c_alv.

* build tree nodes for drag&drop

PERFORM build_handle.

* Fieldcatalogue for ALV

  PERFORM alv_build_fieldcat.

* ALV attributes FOR LAYOUT

  PERFORM alv_report_layout.

* Call ALV GRID

  CALL METHOD c_alv->set_table_for_first_display

    EXPORTING

      is_layout                     = it_layout

    CHANGING

      it_outtab                     = it_t016t

      it_fieldcatalog               = it_fcat

    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 sy-msgv4.

  ENDIF.

ENDFORM.                               "ALV_CONTROLS

*&---------------------------------------------------------------------*

*&      Form  build_handle

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM build_handle.

* define a drag & Drop behaviour for the whole grid

  CREATE OBJECT c_dragdropalv.

  effect = cl_dragdrop=>move + cl_dragdrop=>copy.

  CALL METHOD c_dragdropalv->add

    EXPORTING

      flavor     = 'Line'

      dragsrc    = 'X'

      droptarget = 'X'

      effect     = effect.

*getting the handle for drag and drop

  CALL METHOD c_dragdropalv->get_handle

    IMPORTING

      handle = handle_alv.

ENDFORM.                               " build_handle

*&---------------------------------------------------------------------*

*&      Form  fetch_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fetch_data .

* select and display data from t016

  SELECT brtxt brsch spras FROM t016t INTO CORRESPONDING FIELDS OF TABLE it_t016t

  WHERE spras = 'EN'.

ENDFORM.                    " fetch_data

*&---------------------------------------------------------------------*

*&      Form  alv_report_layout

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM alv_report_layout .

  it_layout-grid_title = 'ALV Drag Drop'.

* provide handle to alv control to all rows for same drag & drop behaviour

  it_layout-s_dragdrop-row_ddid = handle_alv.

ENDFORM.                    " alv_report_layout

*&---------------------------------------------------------------------*

*&      Form  alv_build_fieldcat

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM alv_build_fieldcat .

  DATA lv_fldcat TYPE lvc_s_fcat.

  CLEAR lv_fldcat.

  lv_fldcat-row_pos   = '1'.

  lv_fldcat-col_pos   = '1'.

  lv_fldcat-fieldname = 'BRSCH'.

  lv_fldcat-tabname   = 'IT_T016T'.

  lv_fldcat-outputlen = 8.

  lv_fldcat-scrtext_m = 'Industry'.

  APPEND lv_fldcat TO it_fcat.

  CLEAR lv_fldcat.

  lv_fldcat-row_pos   = '1'.

  lv_fldcat-col_pos   = '2'.

  lv_fldcat-fieldname = 'BRTXT'.

  lv_fldcat-tabname   = 'IT_T016T'.

  lv_fldcat-outputlen = 15.

  lv_fldcat-scrtext_m = 'Description'.

  APPEND lv_fldcat TO it_fcat.

  CLEAR lv_fldcat.

ENDFORM.                    " alv_build_fieldcat

0 Kudos

Have you set your screen attribute to '100' for your 'next screen' ?

0 Kudos

Hello Hai,

The problem of drag and drop is solved. In my case i wasn't passing the E_DRAGDROPOBJ from handle_on_drag method. It was remaining initial. So handle_on_drop method was not getting initiated. Now drag drop is working fine.

But after the method on 'ondrop' event i.e. handle_on_drop, i have to write LEAVE TO SCREEN 100. without which the changes to the ALV Grid are not getting updated.

Regards,

Yayati Ekbote