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: 

How can we hotspot option in ALV using oops concepts

Former Member
0 Kudos

Hi guys,

Can anyone tell me how to use hotspot in alv using oops...pls help me if anyone have the code for that..

4 REPLIES 4

Former Member
0 Kudos

Hi Nagarjuna,

Please check the code below, it has <b>double click</b> as well as <b>hot spot</b> option using OOPS concept in ALV.

----


  • Report ZC1ALVPROG1 *

----


  • Description : Display data through an ALV Grid and to

  • perform EDIT, UPDATE, and DELETE funtion on

  • a selected data.

----


report zc1alvprog1 no standard page heading message-id zc1addmsg.

&----


*& Declaration Section for Tables used in the Report *

&----


tables : zc1address, zc1address_exp.

type-pools: icon.

&----


*& Declaration Section for the Internal Tables *

&----


data : t_intab1 like table of zc1address with header line,

w_intab1 like line of t_intab1,

t_intab2 like table of zc1address_exp with header line,

w_intab2 like line of t_intab2.

&----


*& Declaration Section for EVENT HANDLER CLASS *

&----


class lcl_event_receiver definition deferred.

&----


*& Declaration Section for the ALV Grid *

&----


data: ok_code like sy-ucomm,

i_container type scrfname value 'ADDRESS_BOOK',

addressbook_grid type ref to cl_gui_alv_grid,

addressbook_container type ref to cl_gui_custom_container,

i_event_receiver type ref to lcl_event_receiver,

i_fcat type lvc_t_fcat,

w_fcat like line of i_fcat,

i_fgroup type lvc_t_sgrp,

w_fgroup like line of i_fgroup,

i_layout type lvc_s_layo,

i_variant type disvariant,

x_save,

i_index_rows type lvc_t_row,

i_selected_row like lvc_s_row.

constants: c_check type c value 'X'.

&----


*& Classes definition for tool bar push button

&----


class lcl_event_receiver definition.

public section.

methods:

handle_toolbar for event toolbar of cl_gui_alv_grid

importing e_object e_interactive,

handle_user_command for event user_command of cl_gui_alv_grid

importing e_ucomm,

handle_double_click for event double_click of cl_gui_alv_grid

importing e_row e_column,

handle_hotspot_click for event hotspot_click of cl_gui_alv_grid

importing e_row_id e_column_id es_row_no.

endclass.

&----


*& Classes implementation section

&----


class lcl_event_receiver implementation.

method handle_toolbar.

constants:

c_button_normal type i value 0,

c_separator type i value 1.

data: ls_toolbar type stb_button.

clear ls_toolbar.

move 3 to ls_toolbar-butn_type.

append ls_toolbar to e_object->mt_toolbar.

clear ls_toolbar.

move 'EDIT' to ls_toolbar-function.

move icon_system_copy to ls_toolbar-icon.

move 'Sets Grid in Edit Mode' to ls_toolbar-quickinfo.

move 'Edit' to ls_toolbar-text.

move ' ' to ls_toolbar-disabled.

append ls_toolbar to e_object->mt_toolbar.

move 'UPDATE' to ls_toolbar-function.

move icon_system_save to ls_toolbar-icon.

move 'Updates all the changed data' to ls_toolbar-quickinfo.

move 'Update' to ls_toolbar-text.

move ' ' to ls_toolbar-disabled.

append ls_toolbar to e_object->mt_toolbar.

move 'DELETE' to ls_toolbar-function.

move icon_delete to ls_toolbar-icon.

move 'Deletes the current record' to ls_toolbar-quickinfo.

move 'Delete' to ls_toolbar-text.

move ' ' to ls_toolbar-disabled.

append ls_toolbar to e_object->mt_toolbar.

move 'REFRESH' to ls_toolbar-function.

move icon_refresh to ls_toolbar-icon.

move 'Refreshes the data in the grid' to ls_toolbar-quickinfo.

move 'Refresh' to ls_toolbar-text.

move ' ' to ls_toolbar-disabled.

append ls_toolbar to e_object->mt_toolbar.

endmethod.

  • Method that check the events in the created buttons. *

method handle_user_command.

case e_ucomm.

when 'EDIT'.

call method addressbook_grid->set_ready_for_input

exporting i_ready_for_input = 1.

when 'UPDATE'.

perform update_modified_information.

when 'DELETE'.

perform delete_selected_information.

when 'REFRESH'.

perform refresh_table_information.

endcase.

endmethod.

  • Method that check the event of double click in the grid *

method handle_double_click.

read table t_intab1 index e_row-index into w_intab1.

read table t_intab2 into w_intab2 with key addcode =

w_intab1-addcode.

if sy-subrc <> 0.

message i005.

else.

call screen 3001 starting at 10 5.

endif.

endmethod.

  • Method that processes the hotspot event *

method handle_hotspot_click.

perform handle_hotspot using e_row_id

e_column_id

es_row_no.

endmethod.

endclass.

&----


*& Selection ScreenSection for the ALV Grid

&----


selection-screen begin of block add1 with frame title text-001.

select-options : s_acode for zc1address-addcode.

selection-screen end of block add1.

&----


*& Start Of Selection Event Begins Here *

&----


start-of-selection.

  • Selects the data into internal tables *

select * from zc1address into table t_intab1

where addcode in s_acode.

select * from zc1address_exp into table t_intab2

where addcode in s_acode.

call screen 3000.

&----


*& Module STATUS_3000 OUTPUT

&----


  • text

----


module status_3000 output.

set pf-status 'ADDRESSBOOK'.

set titlebar 'ADDRESS'.

if addressbook_container is initial.

create object addressbook_container "Creating container object

exporting

container_name = i_container.

create object addressbook_grid "Creating AlV Grid Object

exporting

i_parent = addressbook_container.

create object i_event_receiver. "Creating event receiver object

set handler i_event_receiver->handle_user_command for

addressbook_grid.

set handler i_event_receiver->handle_toolbar for addressbook_grid.

set handler i_event_receiver->handle_double_click for

addressbook_grid.

set handler i_event_receiver->handle_hotspot_click for

addressbook_grid.

perform create_field_group. "Grouping of fields funtion

perform create_field_catalog. "Field Catalogue creation

data: begin of info_tab,

client type sy-mandt,

username type sy-uname,

progname type sy-repid,

tcode type sy-tcode,

programmer type sy-repid,

end of info_tab.

data: info_tab1 like table of info_tab with header line,

w_info_tab1 like line of info_tab1.

move sy-mandt to w_info_tab1-client.

move sy-uname to w_info_tab1-username.

move sy-repid to w_info_tab1-progname.

move sy-tcode to w_info_tab1-tcode.

move 'KATHIRVEL BALAKRISHNAN' to w_info_tab1-programmer.

append w_info_tab1 to info_tab1.

call method addressbook_grid->set_table_for_first_display

exporting

is_variant = i_variant

i_save = x_save

is_layout = i_layout

it_special_groups = i_fgroup

changing

it_outtab = t_intab1[]

it_fieldcatalog = i_fcat.

endif.

call method addressbook_grid->set_ready_for_input

exporting

i_ready_for_input = 0.

endmodule. " STATUS_3000 OUTPUT

&----


*& Module USER_COMMAND_3000 INPUT

&----


  • text

----


module user_command_3000 input.

call method cl_gui_cfw=>dispatch.

case ok_code.

when 'BACK'.

set screen 0.

leave screen.

when 'EXIT'.

leave program.

endcase.

endmodule. " USER_COMMAND_3000 INPUT

&----


*& Module STATUS_3001 OUTPUT

&----


  • text

----


module status_3001 output.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

endmodule. " STATUS_3001 OUTPUT

&----


*& Module USER_COMMAND_3001 INPUT

&----


  • text

----


module user_command_3001 input.

case ok_code.

when 'CLOS'.

set screen 0.

leave screen.

endcase.

endmodule. " USER_COMMAND_3001 INPUT

&----


*& Form create_field_catalog

&----


  • This Subroutine Creates the Field Catalogue.

----


form create_field_catalog.

  • Address Code

w_fcat-fieldname = 'ADDCODE'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDCODE'.

w_fcat-coltext = text-002.

w_fcat-seltext = 'Address Code'.

w_fcat-col_pos = 1.

w_fcat-sp_group = 'GEN'.

w_fcat-hotspot = c_check.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Name

w_fcat-fieldname = 'ADDNAME'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDNAME'.

w_fcat-coltext = text-003.

w_fcat-seltext = 'Address Name'.

w_fcat-col_pos = 2.

w_fcat-sp_group = 'GEN'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Designation

w_fcat-fieldname = 'ADDDESI'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDDESI'.

w_fcat-coltext = text-004.

w_fcat-seltext = 'Address Designation'.

w_fcat-col_pos = 3.

w_fcat-sp_group = 'GEN'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Company Name

w_fcat-fieldname = 'ADDCOMP'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDCOMP'.

w_fcat-coltext = text-005.

w_fcat-seltext = 'Address Company Name'.

w_fcat-col_pos = 4.

w_fcat-sp_group = 'GEN'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Company Address

w_fcat-fieldname = 'ADDADDR'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDADDR'.

w_fcat-coltext = text-006.

w_fcat-seltext = 'Address Company Address'.

w_fcat-col_pos = 5.

w_fcat-sp_group = 'GEN'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Home Phone

w_fcat-fieldname = 'ADDHPHO'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDHPHO'.

w_fcat-coltext = text-007.

w_fcat-seltext = 'Address Home phone'.

w_fcat-col_pos = 6.

w_fcat-sp_group = 'CON'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Office Phone

w_fcat-fieldname = 'ADDOPHO'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDOPHO'.

w_fcat-coltext = text-008.

w_fcat-seltext = 'Address Office phone'.

w_fcat-col_pos = 7.

w_fcat-sp_group = 'CON'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Mobile Number

w_fcat-fieldname = 'ADDMOBI'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDMOBI'.

w_fcat-coltext = text-009.

w_fcat-seltext = 'Address Mobile Number'.

w_fcat-col_pos = 8.

w_fcat-sp_group = 'CON'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

  • Address Email Id

w_fcat-fieldname = 'ADDMAIL'.

w_fcat-ref_table = 'ZC1ADDRESS'.

w_fcat-ref_field = 'ADDMAIL'.

w_fcat-coltext = text-010.

w_fcat-seltext = 'Address Email Id'.

w_fcat-col_pos = 9.

w_fcat-sp_group = 'CON'.

w_fcat-edit = 'X'.

append w_fcat to i_fcat.

clear w_fcat.

i_layout-grid_title = 'ALV GRID PROGRAMMING'.

i_layout-zebra = 'X'.

i_layout-sel_mode = 'A'.

i_variant-report = sy-repid.

x_save = 'A'.

endform. " create_field_catalog

&----


*& Form create_field_group

&----


  • Creates the Grouping for the Fields in the Grid

----


form create_field_group.

  • Employee Information Group

w_fgroup-sp_group = 'GEN'.

w_fgroup-text = 'General Details'.

append w_fgroup to i_fgroup.

  • Employee Project Information Group

w_fgroup-sp_group = 'CON'.

w_fgroup-text = 'Contact Details'.

append w_fgroup to i_fgroup.

endform. " create_field_group

&----


*& Form update_modified_information

&----


  • Updates all the changed entries into the database table

----


form update_modified_information.

call method addressbook_grid->refresh_table_display

exporting

i_soft_refresh = ''.

data : w_intab1 like table of zc1address with header line .

update zc1address from table t_intab1.

if sy-subrc = 0.

message i000.

else.

message i001.

endif.

call method addressbook_grid->set_ready_for_input

exporting

i_ready_for_input = 0.

endform. " update_modified_information

&----


*& Form delete_selected_information

&----


  • This Deletes the selected row of data form the ALV grid.

----


form delete_selected_information.

data : i_lines type i.

  • Reading the index of the selected row in the ALV grid.

call method addressbook_grid->get_selected_rows

importing

et_index_rows = i_index_rows.

  • Check whether a row is selected or not. If not it popups a

  • dialog box as warning to select a row.

describe table i_index_rows lines i_lines.

if i_lines = 0.

message i002.

exit.

endif.

  • Reads the selected rows into work area for display

loop at i_index_rows into i_selected_row.

if sy-tabix = 1.

read table t_intab1 index i_selected_row-index into w_intab1.

endif.

endloop.

delete t_intab1 where addcode = w_intab1-addcode .

delete from zc1address where addcode = w_intab1-addcode .

perform refresh_table_information.

if sy-subrc = 0.

message i003.

else.

message i004.

endif.

endform. " delete_selected_information

&----


*& Form refresh_table_information

&----


  • text

----


form refresh_table_information.

call method addressbook_grid->set_ready_for_input

exporting i_ready_for_input = 0.

call method addressbook_grid->refresh_table_display.

endform. " refresh_table_information

&----


*& Form handle_hotspot

&----


  • The Process that are done in a hotspot of ALV

----


form handle_hotspot using p_e_row_id type lvc_s_row

p_e_column_id type lvc_s_col

p_es_row_no type lvc_s_roid.

read table t_intab1 index p_e_row_id into w_intab1.

read table t_intab2 into w_intab2 with key addcode =

w_intab1-addcode.

if sy-subrc <> 0.

message i005.

else.

call screen 3001 starting at 10 5.

endif.

endform. " handle_hotspot

Hope this will be helpful for you!

Cheers

Kathir~

ssimsekler
Active Contributor
0 Kudos

Hi Nagarjuna

You can refer to the tutorial <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an%20easy%20reference%20for%20alv%20grid%20control.pdf">"An Easy Reference for ALV Grid Control"</a>.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

0 Kudos

Hi,

*----


  • CLASS lcl_event_receiver DEFINITION

*----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

  • Hot Spot Click

handle_hotspot

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING e_row_id

e_column_id

es_row_no,

ENDCLASS.

  • Implementation

*&----


*& Method handle_hotspot

*&----


  • This method is called when the user clicks on a hotspot to drill down.

  • The following types are exported from the ALV

  • LVC_S_ROW

  • LVC_S_COL

  • LVC_S_ROID

*&----


METHOD handle_hotspot.

  • The hotspot processing coded in the form below.

PERFORM f9802_handle_hotspot USING e_row_id

e_column_id

es_row_no.

ENDMETHOD.

&----


*& Form f9802_handle_hotspot

&----


  • This form is called when the user clicks on a hotspot on the ALV grid

  • The parameters are of type

----


  • -->P_E_ROW text

  • -->P_E_COL text

  • -->P_E_ROID text

----


FORM f9802_handle_hotspot USING p_row

p_col

p_roid.

DATA: lw_output LIKE LINE OF i_output.

READ TABLE i_output INDEX p_row INTO lw_output.

SET PARAMETER ID 'MAT' FIELD lw_output-matnr.

CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

ENDFORM. " f9802_handle_hotspot

FORM f9300_modify_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat.

Field-symbols: <lfs_fieldcat> TYPE lvc_s_fcat.

LOOP AT p_fieldcat ASSIGNING <lfs_fieldcat>.

CASE <lfs_fieldcat>-fieldname.

WHEN 'MATNR'.

<lfs_fieldcat>-hotspot = c_x.

<lfs_fieldcat>-key = c_x.

WHEN OTHERS.

ENDCASE.

ENDLOOP.

ENDFORM.

In PBO,

module STATUS_9001 output.

  • Set handlers for events

SET HANDLER o_eventreceiver->handle_hotspot FOR o_Alvgrid.

ENDMODULE.

Try this out.

Thanks & Regards,

Judith.

Former Member
0 Kudos

Hi Nagarjuna,

Hope you got a lot of useful information. If you problem is solved can you please close this call. If any more clarification is needed, please let us know.

Cheers

Kathir!~