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

Classes and Methods - handle_double_click

Former Member
0 Likes
2,037

Hi All,

I am working on classes and methods now. I have a doubt.

I have declared as:

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.

ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.

  • Method to handle the double click.

METHOD handle_double_click.

IF e_row-rowtype IS INITIAL.

READ TABLE tb_output INDEX e_row-index INTO wa_out.

PERFORM get_secondary_list.

PERFORM display_secondary_list.

ENDIF.

ENDMETHOD. "handle_double_click

ENDCLASS.

Now, can't i define the same method 'handle_double_click' with some other functionality in IMPLEMETATION?

From the first screen when it is double clicked it should take me to screen 200. Inside 200, if i double click on somthing..it should take me to screen 3. But it is taking me to screen 200 again. Please help me put. It's urgent.

Thanks a lot.

Regards,

Seenu

2 REPLIES 2
Read only

Former Member
0 Likes
820

Hi,

Plz look into below code it will help you.


class lcl_event_receiver definition deferred.
*
*********


data: ok_code like sy-ucomm,
      save_ok like sy-ucomm,
      g_max type i value 100,
      gt_sflight type table of sflight,
      gt_sbook type table of sbook,
      g_repid like sy-repid,
      gs_layout   type lvc_s_layo,
      cont_for_flights   type scrfname value 'BCALV_GRID_02_100',
      grid1  type ref to cl_gui_alv_grid,
      custom_container type ref to cl_gui_custom_container,
      grid2  type ref to cl_gui_alv_grid,
* reference to dialogbox container.
      dialogbox_container type ref to cl_gui_dialogbox_container,
* reference to local class that handles events of GRID1 and
* DIALOGBOX_CONTAINER
      event_receiver type ref to lcl_event_receiver.

* Set initial dynpro
set screen 100.

****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_event_receiver: local class to handle event DOUBLE_CLICK
*                           and CLOSE.
*
* Definition:
* ~~~~~~~~~~~
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,
    handle_close
        for event close of cl_gui_dialogbox_container
            importing sender.

  private section.
   data: dialogbox_status type c.  "'X': does exist, SPACE: does not ex.

endclass.
*
* lcl_event_receiver (Definition)
*===============================================================

****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class c_event_receiver (Implementation)
*
* In this example, only event DOUBLE_CLICK is caught
*
class lcl_event_receiver implementation.

* §3.At doubleclick(1): The event DOUBLE_CLICK provides
*    parameters of the clicked row and column.
*    Use row parameter to select a line of the
*    corresponding internal table.
  method handle_double_click.
    data: ls_sflight like line of gt_sflight.

* read selected row from internal table gt_sflight
    read table gt_sflight index e_row-index into ls_sflight.

* §4.At Doubleclick(2): Select booking data
    perform select_table_sbook using ls_sflight
                               changing gt_sbook.

* §5.At doubleclick(3): Create dialogbox to show detail list
*   (if not already existent)
    if dialogbox_status is initial.
      dialogbox_status = 'X'.
      perform create_detail_list.
    else.
      call method dialogbox_container->set_visible
                       exporting visible = 'X'.
      call method grid2->refresh_table_display.
    endif.
  endmethod.
*--------------------------------------------------------*
  method handle_close.
* §6.Handle the CLOSE-button of the dialogbox

* set dialogbox invisible
* (the dialogbox is destroyed outomatically when the user
* switches to another dynpro).
    call method sender->set_visible
          exporting visible = space.
* In this example closing the dialogbox leads
* to make it invisible. It is also conceivable to destroy it
* and recreate it if the user doubleclicks a line again.
* Displaying a great amount of data has a greater impact on performance.
  endmethod.

endclass.
*
* lcl_event_receiver (Implementation)
*===================================================================

*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
form exit_program.
  call method custom_container->free.
  call method cl_gui_cfw=>flush.
  if sy-subrc ne 0.
* add your handling, for example
    call function 'POPUP_TO_INFORM'
         exporting
              titel = g_repid
              txt2  = sy-subrc
              txt1  = 'Error in FLush'(500).
  endif.
  leave program.
endform.
*&---------------------------------------------------------------------*
*&      Module  PBO_100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module pbo_100 output.

  set pf-status 'MAIN100'.
  set titlebar 'MAIN100'.
  g_repid = sy-repid.
* §1.Create one ALV Control that shows the first table.
  if custom_container is initial.
* select data from table SFLIGHT
    perform select_table_sflight changing gt_sflight.

* create a custom container control for our ALV Control
    create object custom_container
        exporting
            container_name = cont_for_flights
        exceptions
            cntl_error = 1
            cntl_system_error = 2
            create_error = 3
            lifetime_error = 4
            lifetime_dynpro_dynpro_link = 5.
    if sy-subrc ne 0.
* add your handling, for example
      call function 'POPUP_TO_INFORM'
           exporting
                titel = g_repid
                txt2  = sy-subrc
                txt1  = 'The control could not be created'(510).
    endif.
* create an instance of alv control
    create object grid1
         exporting i_parent = custom_container.
*
* Set a titlebar for the grid control
*
    gs_layout-grid_title = 'Flights'(100).

    call method grid1->set_table_for_first_display
         exporting i_structure_name = 'SFLIGHT'
                   is_layout        = gs_layout
         changing  it_outtab        = gt_sflight.

********
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
    create object event_receiver.
    set handler event_receiver->handle_double_click for grid1.
*
********

  endif.                               "IF custom_container IS INITIAL
  call method cl_gui_control=>set_focus exporting control = grid1.

* Control Framework flushes at the end of PBO automatically!

endmodule.                             " PBO_100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  PAI_100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module pai_100 input.
  save_ok = ok_code.
  case save_ok.
    when 'BACK'.
      perform exit_program.
    when 'EXIT'.
      perform exit_program.
  endcase.
  clear save_ok.
endmodule.                             " PAI_100  INPUT
*&---------------------------------------------------------------------*
*&      Form  SELECT_TABLE_SFLIGHT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_SFLIGHT  text
*----------------------------------------------------------------------*
form select_table_sflight changing p_gt_sflight like gt_sflight[].
  select * from sflight into table p_gt_sflight up to g_max rows.
endform.                               " SELECT_TABLE_SFLIGHT

*&---------------------------------------------------------------------*
*&      Form  SELECT_TABLE_SBOOK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LS_SFLIGHT  text
*      <--P_GT_SBOOK  text
*----------------------------------------------------------------------*
form select_table_sbook using    p_ls_sflight like line of gt_sflight
                        changing p_gt_sbook like gt_sbook[].

  select * from  sbook into table p_gt_sbook
         where  carrid  = p_ls_sflight-carrid
         and    connid  = p_ls_sflight-connid
         and    fldate  = p_ls_sflight-fldate.

endform.                               " SELECT_TABLE_SBOOK
*&---------------------------------------------------------------------*
*&      Form  create_detail_list
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_detail_list.
* create dialogbox container as dynpro-instance
* When the user switches to another screen, it is
* destroyed by lifetime mangagement of CFW
      create object dialogbox_container
          exporting
            top = 150
            left = 150
            lifetime = cntl_lifetime_dynpro
            caption = 'Bookings'(200)
            width = 800
            height = 200.
      create object grid2
          exporting i_parent = dialogbox_container.
* Register ABAP OO event 'CLOSE'. It is not necessary to register this
* event at the frontend (this is done during creation).
      set handler event_receiver->handle_close for dialogbox_container.

* display data
      gs_layout-grid_title = space.
      call method grid2->set_table_for_first_display
           exporting i_structure_name = 'SBOOK'
                     is_layout        = gs_layout
           changing  it_outtab        = gt_sbook.

      call method cl_gui_control=>set_focus exporting control = grid2.

endform.                    " create_detail_list

This will surely work.

Plz reward if useful.

Thanks,

Dhanashri.

Read only

Former Member
0 Likes
820

Closed