Handling Alv Grid
Hi All,
I'm using ALV grid for my report output. I'm building the fieldcatalog where i'm passing hotspot for a field. Which has output either yes/no.
Now i need the hand button to be displayed only for records with Yes,so that it can be drilled down.
For No hand symbol should nt come. Is there any way to control hotspot at record level.
Please help.
Thanks,
Bharathi
Hi,<BR>
<BR>
The following code is a template for your requirement:<BR>
<BR>
types: begin of t_data,<BR>
flg(3) type c,<BR>
sty type lvc_t_styl,<BR>
end of t_data,<BR>
t_tdata type table of t_data.<BR>
<BR>
DATA: i_fcat type LVC_T_FCAT,<BR>
s_fcat type lvc_s_fcat,<BR>
s_lay type lvc_s_layo,<BR>
s_sty type lvc_s_styl,<BR>
i_data type t_tdata,<BR>
s_data type t_data.<BR>
<BR>
s_lay-stylefname = 'STY'.<BR>
<BR>
s_fcat-FIELDNAME = 'FLG'.<BR>
APPEND s_fcat to i_fcat.<BR>
<BR>
CLEAR: s_data.<BR>
s_data-flg = 'Yes'.<BR>
s_sty-FIELDNAME = 'FLG'.<BR>
s_sty-style = CL_GUI_ALV_GRID=>MC_STYLE_HOTSPOT.<BR>
insert s_sty into TABLE s_data-sty.<BR>
APPEND s_data to i_data.<BR>
<BR>
CLEAR: s_data.<BR>
s_data-flg = 'No'.<BR>
s_sty-FIELDNAME = 'FLG'.<BR>
s_sty-style = CL_GUI_ALV_GRID=>MC_STYLE_HOTSPOT_NO.<BR>
insert s_sty into TABLE s_data-sty.<BR>
APPEND s_data to i_data.<BR>
<BR>
CLEAR: s_data.<BR>
s_data-flg = 'No'.<BR>
s_sty-FIELDNAME = 'FLG'.<BR>
s_sty-style = CL_GUI_ALV_GRID=>MC_STYLE_HOTSPOT_NO.<BR>
insert s_sty into TABLE s_data-sty.<BR>
APPEND s_data to i_data.<BR>
<BR>
CLEAR: s_data.<BR>
s_data-flg = 'Yes'.<BR>
s_sty-FIELDNAME = 'FLG'.<BR>
s_sty-style = CL_GUI_ALV_GRID=>MC_STYLE_HOTSPOT.<BR>
insert s_sty into TABLE s_data-sty.<BR>
APPEND s_data to i_data.<BR>
<BR>
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'<BR>
EXPORTING<BR>
I_INTERFACE_CHECK = ' '<BR>
I_BYPASSING_BUFFER =<BR>
I_BUFFER_ACTIVE =<BR>
I_CALLBACK_PROGRAM = ' '<BR>
I_CALLBACK_PF_STATUS_SET = ' '<BR>
I_CALLBACK_USER_COMMAND = ' '<BR>
I_CALLBACK_TOP_OF_PAGE = ' '<BR>
I_CALLBACK_HTML_TOP_OF_PAGE = ' '<BR>
I_CALLBACK_HTML_END_OF_LIST = ' '<BR>
I_STRUCTURE_NAME =<BR>
I_BACKGROUND_ID = ' '<BR>
I_GRID_TITLE =<BR>
I_GRID_SETTINGS =<BR>
IS_LAYOUT_LVC = s_lay<BR>
IT_FIELDCAT_LVC = i_fcat<BR>
IT_EXCLUDING =<BR>
IT_SPECIAL_GROUPS_LVC =<BR>
IT_SORT_LVC =<BR>
IT_FILTER_LVC =<BR>
IT_HYPERLINK =<BR>
IS_SEL_HIDE =<BR>
I_DEFAULT = 'X'<BR>
I_SAVE = ' '<BR>
IS_VARIANT =<BR>
IT_EVENTS =<BR>
IT_EVENT_EXIT =<BR>
IS_PRINT_LVC =<BR>
IS_REPREP_ID_LVC =<BR>
I_SCREEN_START_COLUMN = 0<BR>
I_SCREEN_START_LINE = 0<BR>
I_SCREEN_END_COLUMN = 0<BR>
I_SCREEN_END_LINE = 0<BR>
I_HTML_HEIGHT_TOP =<BR>
I_HTML_HEIGHT_END =<BR>
IT_EXCEPT_QINFO_LVC =<BR>
IR_SALV_FULLSCREEN_ADAPTER =<BR>
IMPORTING<BR>
E_EXIT_CAUSED_BY_CALLER =<BR>
ES_EXIT_CAUSED_BY_USER =<BR>
TABLES<BR>
T_OUTTAB = i_data<BR>
EXCEPTIONS<BR>
PROGRAM_ERROR = 1<BR>
OTHERS = 2<BR>
.<BR>
IF SY-SUBRC <> 0.<BR>
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO<BR>
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.<BR>
ENDIF.<BR>
<BR>
Thanks,<BR>
Kiruba.<BR>
Similar Messages
-
Deactivate buttons in ALV GRID being called in subscreen
Hi,
In a screen, when a specific tab is selected (tab strip), the subscreen area is filled with ALV GRID. I need to deactivate few buttons on the ALV GRID. How can that be done??
Advance ThanksHi Aadarsh,
Check out the following program.
Global data definitions for ALV
To allow the declaration of gr_event_handler before the
lcl_event_receiver class is defined, decale it as deferred in the
start of the program
CLASS lcl_event_handler DEFINITION DEFERRED.
Object reference
ALV Grid instance reference
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,
Custom container instance reference
gr_ccontainer TYPE REF TO cl_gui_custom_container,
Event class reference
gr_event_handler TYPE REF TO lcl_event_handler. "IC210507+
Internal Table
Field catalog table
DATA: gt_fieldcat TYPE lvc_t_fcat,
Internal table holding list data
gt_list TYPE STANDARD TABLE OF sflight,
Table to be filled up for excluding some of the standard function
buttons
gt_exclude TYPE ui_functions. "IC210507+
Work area
Layout structure
DATA: gs_layout TYPE lvc_s_layo,
Field catalog structure
gs_fcat TYPE lvc_s_fcat,
Exclude button structure
gs_exclude TYPE ui_func, "IC210507+
Structure to add button in the ALV toolbar
gs_toolbar TYPE stb_button. "IC210507+
Variables
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm,
Name of the custom control added on the screen
gv_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
Begin of IC210507
Local classes
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION.
METHODS:
To add new functional buttons to the ALV toolbar
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
To implement user commands
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
End of IC210507
Calling the screen where ALV output is displayed
CALL SCREEN 100.
*& Module STATUS_0100 OUTPUT
PBO
MODULE status_0100 OUTPUT.
ALV display
PERFORM display_alv.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
PAI
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
IF save_ok EQ 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form display_alv
ALV display
FORM display_alv.
PERFORM get_data.
PERFORM create_alv.
ENDFORM. " display_alv
*& Form get_data
Fetch data to be displayed in the list
FORM get_data.
SELECT * FROM sflight
INTO TABLE gt_list.
ENDFORM. " get_data
*& Form create_alv
Create and set or Refresh ALV
FORM create_alv.
Checking whether an instance of the container (or ALV Grid) exists.
IF gr_alvgrid IS INITIAL.
If not, creating and setting ALV for the first display.
Creating custom container instance
CREATE OBJECT gr_ccontainer
EXPORTING
container_name = gv_custom_control_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
Creating ALV Grid instance
CREATE OBJECT gr_alvgrid
EXPORTING
i_parent = gr_ccontainer
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5.
Begin of IC210507
Creating an instance for the event handler
CREATE OBJECT gr_event_handler.
Registering handler methods to handle ALV Grid events
SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid.
SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid.
End of IC210507
Preparing field catalog.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
Preparing layout structure
PERFORM prepare_layout CHANGING gs_layout.
Excluding Unwanted Standard Function Buttons
PERFORM exclude_tb_functions CHANGING gt_exclude. "IC210507+
Method to display ALV grid
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
To exclude buttons the exclusion table must be passed to the following
field
it_toolbar_excluding = gt_exclude "IC210507+
CHANGING
it_outtab = gt_list
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
To make ALV show our additional buttons, we must call the method
set_toolbar_interactive for the ALV Grid instance after the instance
is created.
CALL METHOD gr_alvgrid->set_toolbar_interactive. "IC210507+
ELSE.
If an instance of the container (or ALV Grid) exists, refreshing it.
CALL METHOD gr_alvgrid->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.
ENDIF.
ENDFORM. " create_alv
*& Form prepare_field_catalog
Subroutine to populate field catalog
<--P_GT_FIELDCAT Table to describe the field catalog
FORM prepare_field_catalog CHANGING p_gt_fieldcat TYPE lvc_t_fcat.
Generating the field catalog semi automatically
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = p_gt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
LOOP AT p_gt_fieldcat INTO gs_fcat.
CASE gs_fcat-fieldname.
WHEN 'CARRID'.
gs_fcat-outputlen = '10'.
gs_fcat-coltext = 'Airline Carrier ID'.
MODIFY p_gt_fieldcat FROM gs_fcat.
WHEN 'FLDATE'.
gs_fcat-just = 'C'.
gs_fcat-hotspot = 'X'.
MODIFY p_gt_fieldcat FROM gs_fcat.
ENDCASE.
ENDLOOP.
ENDFORM. " prepare_field_catalog
*& Form prepare_layout
Preparing layout structure
<--P_GS_LAYOUT Layout structure
FORM prepare_layout CHANGING p_gs_layout TYPE lvc_s_layo.
p_gs_layout-zebra = 'X' .
p_gs_layout-grid_title = 'Flight Info System'.
p_gs_layout-smalltitle = 'X'.
ENDFORM. " prepare_layout
Begin of IC210507
*& Form exclude_tb_functions
Excluding Unwanted Standard Function Buttons
<--P_GT_EXCLUDE Table to be filled up to exclude buttons
FORM exclude_tb_functions CHANGING p_gt_exclude TYPE ui_functions.
MC_FC_ are names for functions directly and the names beginning with
MC_MB_ are for the function menus including some subfunctions as menu
entries.
In this case 'Maximum' and 'Minimum' options under 'Sum' button & 'Print'
button are excluded
gs_exclude = cl_gui_alv_grid=>mc_fc_maximum.
APPEND gs_exclude TO p_gt_exclude.
gs_exclude = cl_gui_alv_grid=>mc_fc_minimum.
APPEND gs_exclude TO p_gt_exclude.
gs_exclude = cl_gui_alv_grid=>mc_fc_print.
APPEND gs_exclude TO p_gt_exclude.
ENDFORM. " exclude_tb_functions
*& Class (Implementation) lcl_event_handler
Event handler for the ALV Grid instance.
CLASS lcl_event_handler IMPLEMENTATION.
Handle Toolbar
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object e_interactive .
ENDMETHOD . "handle_toolbar
Handle User Command
METHOD handle_user_command .
PERFORM handle_user_command USING e_ucomm .
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler
*& Form handle_toolbar
Subroutine called from event handler method for event toolbar.
This is to add a new button in the ALV application toolbar
-->P_E_OBJECT
-->P_E_INTERACTIVE
FORM handle_toolbar USING p_e_object TYPE REF TO cl_alv_event_toolbar_set
p_e_interactive.
Begin of 'Adding a new Button'
CLEAR gs_toolbar.
Function code
MOVE 'EXIT' TO gs_toolbar-function.
Button type that will be added to the toolbar
gs_toolbar-butn_type = 0.
Icon for the button
From the type group ICON in SE11, we can get the value to be passed
for icon
gs_toolbar-icon = '@2N@'.
Quick info for the button
MOVE 'Exit' TO gs_toolbar-quickinfo.
Text for the button
MOVE 'Exit' TO gs_toolbar-text.
Adds the button as disabled if set to X
MOVE ' ' TO gs_toolbar-disabled.
Appending the structure to the table attribute mt_toolbar of the object
APPEND gs_toolbar TO p_e_object->mt_toolbar.
End of 'Adding a new Button'
Begin of 'Disabling an existing standard Button'
LOOP AT p_e_object->mt_toolbar
INTO gs_toolbar
Identify which button to disable from the function code
In this case disabling the 'Filter' button
WHERE function = '&MB_FILTER'.
Set the 'DISABLED' field to disable a button
gs_toolbar-disabled = 'X'.
MODIFY p_e_object->mt_toolbar FROM gs_toolbar.
ENDLOOP.
End of 'Disabling an existing standard Button'
ENDFORM. " handle_toolbar
*& Form handle_user_command
Implement any new function
-->P_E_UCOMM text
FORM handle_user_command USING p_e_ucomm TYPE syucomm.
IF p_e_ucomm EQ 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDFORM. " handle_user_command
End of IC210507
Award points if found useful.
Regards
Indrajit. -
ALV GRID - Handling selected rows? Sorting in OUTTAB is different from ALV
Dear Experts ,
I have a transaction with ALV grid. I have defined several application specific functions to the ALV grid tool bar. My requirement is to handle the ALV tool bar functions only for the selected rows.
Code snippet:
DATA:
LS_GRID_DS TYPE TYS_DS.
TYPES: BEGIN OF TYS_DS.
INCLUDE TYPE TYS_ALVGRID.
TYPES: STRUCNAME LIKE DD02L-TABNAME.
TYPES: PRETAB TYPE ZTAB_T,
OUTTAB TYPE ZTAB_T,
OUTTAB_HIDDEN TYPE ZTAB_T,
OUTTAB_SUM TYPE ZTAB_T,
OUTTAB_ROLLBACK TYPE ZTAB_T,
END OF TYS_DS.
LOOP AT ls_grid_ds-marked_rows INTO ss_index_split
WHERE rowtype IS INITIAL.
( Marked rows is correctly giving the row numbers of the highlighted rows)
READ TABLE ls_grid_ds-outtab INTO ss_sel_rows_ds_split
INDEX ss_index_split-index.
ISSUE : Sorting in ls_grid_ds-outtab internal table is different from ALV Grid display.
Hence, though ls_grid_ds-marked_rows giving correct rows, I am not able to handle the my requirement correctly.
Why sorting in gs_grid_ds-outtab is different from ALV display? How can they made in sync?
Thank you in Advance.
Sravan.
Edited by: Raja Sravan on Jan 16, 2009 1:13 AMHello Raja
The OUTTAB is usually in sync with the display on the frontend grid control because it is a CHANGING parameter (of method SET_TABLE_FOR_FIRST_DISPLAY).
Question: Do you "feed" ls_grid_ds-outtab to the parameter IT_OUTTAB of method SET_TABLE_FOR_FIRST_DISPLAY?
If not then it is obvious why you get discrepancies.
Regards
Uwe -
How to handle check box click in ALV grid
Hi Experts,
I use ALV grid using FM.
I have list of delivery note items with one custom field as check-box. When I check the checkbox, all other lines related to the same delivery note should be automaticaly checked.
Is there any event or function code, where I can handle single click to checkbox?
Thanks®ards,
JirkaHI
you can use following code in user command function .
DATA :BEGIN OF IT_MAINDATA OCCURS 0,
MAINDATA(1),
IT_RD1(1),
END OF IT_MAINDATA.
data: V_INDEX TYPE I.
DESCRIBE TABLE itab LINES LINE.
DO. " line times.
READ LINE SY-INDEX FIELD VALUE Iitab-RD1.
IF SY-SUBRC NE 0. EXIT. ENDIF.
CHECK V_INDEX > 0.
CHECK itab-RD1 = 'X'.
MODIFY itab INDEX V_INDEX.
IT_MAINDATA-IT_RD1 = Iitab-RD1.
ENDDO.
i think is work.
regards,
Abhi -
hi,
Hi,
I am displaying some fields from VBAP in ALV gid and have give drop down check box to storage location making it editable so if the user changes Storage location of
some entries and clicks SAVE button, when we click save button i need to capture all the rows that were been changed and update VA02 using these records through bapi.
but iam not able to capture this SAVE event but iam able to capture Enter and cursor event.
i have written following code for this
LOCAL CLASSES: Definition
class lcl_event_receiver: local class to handle event CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
LOCAL CLASSES: Implementation
class lcl_event_receiver (Implementation)
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_data_changed.
DATA: l_error_in_data TYPE c.
PERFORM handle_data_changed USING er_data_changed l_error_in_data.
*§7.Display application log if an error has occured.
IF l_error_in_data EQ 'X'.
CALL METHOD er_data_changed->display_protocol.
ENDIF.
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*& Form handle_data_changed
Identify columns which were changed and check input
-->P_ER_DATA_CHANGED text
FORM handle_data_changed USING p_er_data_changed
TYPE REF TO cl_alv_changed_data_protocol
p_error_in_data TYPE c.
DATA : lw_mod_cell TYPE lvc_s_modi ,
l_value TYPE lvc_value ,
l_lgort TYPE lgort_d.
SORT p_er_data_changed->mt_mod_cells BY row_id .
LOOP AT p_er_data_changed->mt_mod_cells INTO lw_mod_cell
WHERE fieldname = 'LGORT'.
CALL METHOD p_er_data_changed->get_cell_value
EXPORTING
i_row_id = lw_mod_cell-row_id
i_fieldname = 'LGORT'
IMPORTING
e_value = l_value.
SELECT SINGLE lgort FROM t001l INTO l_lgort WHERE werks = p_werks
AND lgort = l_value.
IF sy-subrc NE 0.
In case of error, create a protocol entry in the *application log.
CALL METHOD p_er_data_changed->add_protocol_entry
EXPORTING
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = text-003
i_msgv2 = l_value
i_msgv3 = text-004
i_fieldname = lw_mod_cell-fieldname
i_row_id = lw_mod_cell-row_id.
p_error_in_data = 'X'.
EXIT.
ELSE.
*§5b.If the value is valid change values of
cells.
CALL METHOD p_er_data_changed->modify_cell
EXPORTING
i_row_id = lw_mod_cell-row_id
i_fieldname = lw_mod_cell-fieldname
i_value = l_value.
READ TABLE t_list1 INTO w_list1 INDEX lw_mod_cell-row_id.
IF sy-subrc EQ 0.
*comparing old value with the changed value
IF w_list1-lgort <> l_value.
MOVE: w_list1-werks TO w_list3-werks,
w_list1-matnr TO w_list3-matnr,
w_list1-arktx TO w_list3-arktx,
w_list1-vbeln TO w_list3-vbeln,
w_list1-posnr TO w_list3-posnr,
w_list1-pstyv TO w_list3-pstyv,
w_list1-vstel TO w_list3-vstel,
w_list1-auart TO w_list3-auart,
w_list1-kwmeng TO w_list3-kwmeng,
w_list1-vrkme TO w_list3-vrkme,
w_list1-mbdat TO w_list3-mbdat,
l_value TO w_list3-lgort.
APPEND w_list3 TO t_list3.
*t_list3 will contain all the records that are changed
CLEAR w_list3.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF go_custom_container IS INITIAL.
create a custom container control for our ALV Control
CREATE OBJECT go_custom_container
EXPORTING
container_name = g_cont_on_main
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
Display error message.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = sy-repid
txt2 = sy-subrc
txt1 = 'The control could not be created'.
ENDIF.
create an instance of alv control
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
*If display or change radio button is cheked
IF ( p_chng = 'X' OR p_disp = 'X' ) .
Set a titlebar for the grid control
g_layout-grid_title = 'Sales Orders'.
g_layout-excp_fname = 'TRAFFIC_LIGHT'.
Define a drop down table.
PERFORM set_drdn_table.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_layout = g_layout
CHANGING
it_outtab = t_list1
it_fieldcatalog = t_fieldcat1
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.
ENDIF.
register ENTER and CURSOR to raise event DATA_CHANGED.
(Per default the user may check data by using the check icon).
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->handle_double_click FOR go_grid.
SET HANDLER g_event_receiver->handle_hotspot_click FOR go_grid .
SET HANDLER g_event_receiver->handle_data_changed FOR go_grid .
ENDIF.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = go_grid.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE user_command_0100 INPUT.
ok_code = sy-ucomm.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'SAVE'.
PERFORM update_sales_order using t_list3[].
endcase.
Thanks in Advance,
SiriHi Sirisha,
You can get the event code for Enter because you have regitered in the event reciever .
But for the SAVE you will have to set in the PF-status of the screen and not the ALV-grid save .
Please award if helpful. -
Urgent checkboxes handling in alv grid
helo all .i need to handle checkboxes in alv grid.
i did like
case u_comm.
when 'save'.
perform save.
endcase.
in the form.
form save.
loop at it_mara into it_mara1 where chk = 'X'
and moving the contents to it_mara1.
but after doing it is not looping when i have seen in debug .
plz help me
i need to have those selected values and move a head.Hi rakhee,
First add a single charecter field into the internal table you want to display in the ALV.Then set the field cataloge and set the value for Checkbox as 'X'.it wil display the field as a check box.when you check the check box it will update the internal table also.
please check the below code.
TYPE-POOLS : slis.
TYPES : BEGIN OF st_mara.
TYPES : matnr TYPE mara-matnr.
TYPES : a,
END OF st_mara.
DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat.
DATA : it_mara TYPE TABLE OF st_mara.
SELECT * FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_mara UP TO 1 ROWS.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'A'.
wa_fieldcat-checkbox = 'X'.
wa_fieldcat-edit = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'MATNR'.
APPEND wa_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_mara.
BREAK-POINT.
if you are using controls just call the method
CALL METHOD grid1->check_changed_data.
grid1 is the instance of the ALV grid.
when the method is called you will get the internal table with the field marked as 'X'.
Regards
Sandeep -
Handling checkboxes in ALV Grid.
Hi guys.
I have displayed an ALV grid with checkboxes. I want to opearate on the selected checkboxes by the user by clicking on a added button.
I am using oops and using function set_table_for_first_display.
if no box is selected the function works properly. If i select a checkbox, i get a dump.
ThanksHi arun
here is the required code.
<b>Form to register events</b>
FORM register_events .
CREATE OBJECT gr_event_handler .
SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid .
SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid.
SET HANDLER gr_event_handler->handle_hotspot_click FOR gr_alvgrid.
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid.
ENDFORM.
<b>Class Defination and implementation</b>
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION .
METHODS:
*To add new functional buttons to the ALV toolbar
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
*To implement user commands.
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
To handle hotspot click.
handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id es_row_no,
To handle Double Click
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column .
ENDCLASS. "LCL_EVENT_HANDLER DEFINITION
*& Class (Implementation) lcl_event_handler
Text
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object.
ENDMETHOD . "handle_toolbar
METHOD handle_user_command.
perform handler_user_command using e_ucomm .
ENDMETHOD. "handle_user_command
METHOD handle_hotspot_click .
PERFORM handle_hotspot_click USING e_row_id e_column_id es_row_no .
ENDMETHOD . "handle_hotspot_click
METHOD handle_double_click .
PERFORM handle_double_click USING e_row e_column .
ENDMETHOD . "handle_hotspot_click
ENDCLASS. "lcl_event_handler
<b>
PBO of screen that is called after the pushbutton is pressed.</b>
MODULE STATUS_9400 OUTPUT.
SET PF-STATUS 'SCREEN9400'.
perform diaply_checkbox.
<b>and the method display_checkbox.</b>
FORM diaply_checkbox .
data: count type i.
count = 0.
loop at za004_t_t into wa_a004_t_t.
if wa_a004_t_t-checkboc = 'X'.
count = count + 1.
endif.
count = count + 1.
endloop.
ENDFORM. " diaply_checkbox
thanks
Abhinav Dhasmana -
Handling Right & Left Click Events in ALV Grid
Hi Friends,
Please give me the idea how to handle Right & Left mouse Click Events in ALV Grid.
My requirement is that when i click on the grid i need to pop up a message.
Eagerly waiting for your replies
Thanks
Satishyou have to Define a class and implement event handler methods for this purpose.
and the following events can help.
LEFT_CLICK_DESIGN
LEFT_CLICK_RUN
Regards
Raja -
ALV GRID - how to handle scrollbar click
Hello,
Is it possible to handle scrollbar movment/click
in alv grid control?
Thanks in advance for your help.
HarryHello vijay,
I'am implementing a calendar with the alv grid control.
Since I do not want to process all the data at one time
I need to know when the scrollbar reach the upper or lower extremity so that I can populate + other processes the alv grid.
Something very similar to the actual behaviour of "F4_DATE" function module displaying the Calendar control.
Hope you can help me
Thanks -
Problem in handling double click in the second alv grid control
Hi all,
I have a screen. In the screen , I have 2 custom container and each custom container has 1 alv grid control.
I need to handle double click event for both of alv grid controls in my screen.
I defined 2 local event handler class for each alv grid and defined 2 handle_double_click event.
In the first Alv grid double click works fine , everything is ok, world is peaceful.
But in the second alvgrid, the row parameters (E_ROW, E_COLUMN, ES_ROW_NO) comes initial so i cannot handle it.
All i need is to call a different transaction (displaying the equipment-IE03) when user double-click on a field in the second alv grid control. I tried to use hotspot_click event too but it does'nt give the row id either.
I read some posts in the forms ([Double click event of alv grid control|Double click event of alv grid control]).
I tried everything but nothing works.
Please help. Your answers will be appreciated.Hello Eagle
I am not sure where the problem lies in your case but sample report ZUS_SDN_THREE_ALV_GRIDS_01 shows that you can always find out the current cell after the double-click event (in any case you have the current cell already as IMPORTING parameters of the event):
*& Report ZUS_SDN_THREE_ALV_GRIDS_01
*& Flow logic of screen '0100' (no screen elements, ok-code => GD_OKCODE):
** PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
** PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
*& Thread: problem in handling double click in the second alv grid control
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1172052"></a>
REPORT zus_sdn_three_alv_grids_01.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_splitter_2 TYPE REF TO cl_gui_splitter_container,
go_cell_top TYPE REF TO cl_gui_container,
go_cell_bottom TYPE REF TO cl_gui_container,
go_cell_left TYPE REF TO cl_gui_container,
go_cell_right TYPE REF TO cl_gui_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
go_grid3 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_outtab TYPE STANDARD TABLE OF vbak,
gt_outtab_2 TYPE STANDARD TABLE OF vbap,
gt_outtab_3 TYPE STANDARD TABLE OF vbep.
**PARAMETERS:
** p_bukrs TYPE bukrs DEFAULT '1000'.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
ms_row TYPE lvc_s_row,
ms_col TYPE lvc_s_col.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_outtab TYPE vbak,
ls_outtab_2 TYPE vbap,
ls_outtab_3 TYPE vbep.
" Initialize class data
CLEAR: ms_row,
ms_col.
CASE sender.
WHEN go_grid1.
ms_row = e_row.
ms_col = e_column.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'GET_ITEMS'
* IMPORTING
* rc =
WHEN go_grid2.
ms_row = e_row.
ms_col = e_column.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'GET_SCHEDULE_LINES'
* IMPORTING
* rc =
WHEN go_grid3.
** READ TABLE gt_vbap INTO ls_vbap INDEX e_row-index.
** CHECK ( ls_vbap-matnr IS NOT INITIAL ).
** SET PARAMETER ID 'MAT' FIELD ls_vbap-matnr.
** CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
WHEN OTHERS.
RETURN.
ENDCASE.
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM vbak INTO TABLE gt_outtab UP TO 100 ROWS.
PERFORM init_controls.
* Display data
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAK'
CHANGING
it_outtab = gt_outtab
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH: gt_outtab_2.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
CHANGING
it_outtab = gt_outtab_2 " empty !!!
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH: gt_outtab_3.
CALL METHOD go_grid3->set_table_for_first_display
EXPORTING
i_structure_name = 'VBEP'
CHANGING
it_outtab = gt_outtab_3 " empty !!!
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro:
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "ORDERS"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid2->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Refresh display of detail ALV list
CALL METHOD go_grid3->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
" Double-click on first or second ALV grid
WHEN 'GET_ITEMS' OR
'GET_SCHEDULE_LINES'.
PERFORM get_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 1
columns = 2
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_left.
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = go_cell_right.
* Create 2nd splitter container
CREATE OBJECT go_splitter_2
EXPORTING
parent = go_cell_left
rows = 2
columns = 1
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Get cell container
CALL METHOD go_splitter_2->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_top.
CALL METHOD go_splitter_2->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = go_cell_bottom.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_top
EXCEPTIONS
OTHERS = 5.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_cell_bottom
EXCEPTIONS
OTHERS = 5.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT go_grid3
EXPORTING
i_parent = go_cell_right
EXCEPTIONS
OTHERS = 5.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1.
SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid2.
SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid3.
ENDFORM. " INIT_CONTROLS
*& Form GET_DETAILS
* text
* --> p1 text
* <-- p2 text
FORM get_details .
* define local data
DATA: ls_row TYPE lvc_s_row,
ls_col TYPE lvc_s_col.
data: ls_outtab type vbak,
ls_outtab_2 type vbap,
ls_outtab_3 type vbep.
BREAK-POINT.
CASE gd_okcode.
WHEN 'GET_ITEMS'.
CALL METHOD go_grid1->get_current_cell
IMPORTING
* e_row =
* e_value =
* e_col =
es_row_id = ls_row
es_col_id = ls_col
* es_row_no =
read TABLE gt_outtab into ls_outtab index ls_row-index.
refresh: gt_outtab_2,
gt_outtab_3.
SELECT * FROM vbap into TABLE gt_outtab_2
WHERE vbeln = ls_outtab-vbeln.
WHEN 'GET_SCHEDULE_LINES'.
CALL METHOD go_grid2->get_current_cell
IMPORTING
* e_row =
* e_value =
* e_col =
es_row_id = ls_row
es_col_id = ls_col
* es_row_no =
READ TABLE gt_outtab_2 into ls_outtab_2 index ls_row-index.
refresh: gt_outtab_3.
SELECT * FROM vbep into TABLE gt_outtab_3
WHERE vbeln = ls_outtab_2-vbeln
AND posnr = ls_outtab_2-posnr.
WHEN OTHERS.
RETURN.
ENDCASE.
IF ( lcl_eventhandler=>ms_row = ls_row AND
lcl_eventhandler=>ms_col = ls_col ).
MESSAGE 'Current cell identical' TYPE 'I'.
ELSE.
MESSAGE 'Current cell NOT identical' TYPE 'I'.
ENDIF.
ENDFORM. " GET_DETAILS
Regards
Uwe -
Hi all,
Please let me know how to hanldle event handling , making a cell in editable mode ,double click and hotspot creation,colorign a single cell,calling a transatcion when clicked on hotspot in a alv grid display program (not using OO concepts).
Looikng forward for a positive response.
Reagrds,
Mohinder.Hi,
You can create your own custom status and asign it to your
ALV GRID. Here is a sample code to add custom status and handling events.
http://www.geocities.com/mpioud/Z_DEMO_ALV_REFRESH_BUTTON.html
Reward Points if found helpfull..
Cheers,
Chandra Sekhar. -
Handling Enter Key in Editable ALV Grid using REUSE_ALV_GRID_DISPLAY
Hello All,
I have seen a number of threads on captioned issue and everyone of them say to create FCODE for Enter in the Screen's PF Status and then handle the event.
But the catch is when you hit Enter key in ALV Grid, it will not trigger any FCODE at all because the FCODE Enter you have created is for the screen and not for the GRID. Can anyone please let me know if SAP has given any standard utility in REUSE_ALV_GRID_DISPLAY FM for handling the Enter key event.
Thanks and regards,
MaheshHi,
Set the PF-status for OK key and use the FCODE or u can usethe dynamic ok_code generated .
Also try 'ENTE' .
Hope thishelps. -
Handling Double click on a Pop-up screen with ALV Grid
Hello Experts,
I have an issue handling double click on ALV Pop-up screen. I tried to achive this using following steps.
1. I defined a local class in Top-include to handle double click and implemented it in the following way.
CLASS lcl_alv_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
on_double_click FOR EVENT double_click
OF cl_gui_alv_grid
IMPORTING e_row
e_column
es_row_no.
ENDCLASS. "lcl_alv_event_handler DEFINITION
*~~~ Implementation code
CLASS lcl_alv_event_handler IMPLEMENTATION.
To handle Selection of Issue data on Screen 100
METHOD on_double_click.
DATA: lt_row_no TYPE lvc_t_roid,
ls_req TYPE zcst_zirt_seltab.
READ TABLE gt_req
INTO ls_req
INDEX e_row-index.
g_req_id = ls_req-zzrequest_id.
gv_selected = true.
CALL METHOD go_alv->dispatch
EXPORTING
cargo = 'OK'
eventid = 3
is_shellevent = ' '
is_systemdispatch = 'X'
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMETHOD. "on_double_click
ENDCLASS. "lcl_alv_event_handler IMPLEMENTATION
2. Registered the event in the PBO module of the screen
ls_events-eventid = 3.
ls_events-appl_event = gc_true.
APPEND ls_events TO lt_events.
CALL METHOD co_alv->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 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.
CREATE OBJECT co_alv_event_handler.
SET HANDLER: co_alv_event_handler->on_double_click FOR co_alv.
CALL METHOD co_alv->set_toolbar_interactive.
3. In the PAI module of Screen, tried to handle the event 'OK' that waqs registred in PBO.
CASE save_ok.
WHEN 'OK'.
Get selected line
CALL METHOD io_alv->get_selected_rows
IMPORTING
et_index_rows = lt_rows
et_row_no = lt_rows_no.
IF NOT lt_rows IS INITIAL.
READ TABLE lt_rows INTO ls_rows INDEX 1.
IF sy-subrc EQ 0.
gv_selected = 'X'.
READ TABLE it_req
INTO ls_req
INDEX ls_rows-index.
e_req_id = ls_req-zzrequest_id.
SET SCREEN 0.
ENDIF.
ELSE.
SET SCREEN 0.
ENDIF.
With this code what is happening is, when user double clicks a line on Pop-up screen with ALV grid data, the program is able to successfully get into the class implementation but the control is not going to PAI module to execute the OK_code handling part.
Am I doing this in the right way? Appreciate quick suggestions. Proper posts will be thoroughly awarded with points.
Thx.
MinniPut your code into the Event handler Implementation of Double Click which is there in the PAI Module.
Regards,
Naimesh Patel -
Haw can i handle the single-click mouse event in a ALV Grid class implementation...???
The LEFT_CLICK_RUN and RIGHT_CLICK don't help's me....
Someone can update me...???
Thank's...hi,
you can just set all the field as hotspot , and implement the event hotspot_click.
check the code below:
pay attention the words in red
REPORT ZDAVID_ALV1.
CLASS ZCL_EVENT_RECEIVER DEFINITION DEFERRED." Declear a custom class
tables zemployee.
data: ls_fcat type lvc_s_fcat,
li_fcat type lvc_t_fcat,
ls_layo type lvc_s_layo,
ls_color type lvc_s_scol,
LO_EVENT TYPE REF TO ZCL_EVENT_RECEIVER.
data: container type ref to cl_gui_custom_container,
grid type ref to cl_gui_alv_grid.
types: begin of ty_emp,
emp_x type c,
zemp_id type zemp_id,
zemp_name type zemp_name,
zemp_salary type zemp_salary,
zemp_dpart type zemp_dpart,
rowcolor(4) type c,
cellcolor type lvc_t_scol,
end of ty_emp.
data: emp type table of ty_emp,
wa_emp type ty_emp,
wcellcolor type lvc_s_scol.
call screen 9000.
CLASS ZCL_EVENT_RECEIVER DEFINITION." class definition
PUBLIC SECTION.
methods:
handle_single_click
for event hotspot_click of cl_gui_alv_grid
importing
e_row_id es_row_no e_column_id.
PRIVATE SECTION.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
* LCL_EVENT_RECEIVER (DEFINITION)
* ===============================================================
* LOCAL CLASSES: IMPLEMENTATION
* ===============================================================
* CLASS LCL_EVENT_RECEIVER (IMPLEMENTATION)
* IN THIS EXAMPLE, ONLY EVENT DOUBLE_CLICK IS CAUGHT
CLASS ZCL_EVENT_RECEIVER IMPLEMENTATION." implementation
method handle_single_click.
message e_column_id-fieldname type 'I'.
endmethod.
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
form sub_get_data.
select * from zemployee into corresponding fields of wa_emp.
wa_emp-emp_x = 'X'.
if wa_emp-zemp_id = '171184'.
" wa_emp-rowcolor = 'C610'.
wcellcolor-fname = 'ZEMP_ID'.
wcellcolor-color-col = '7'.
wcellcolor-color-int = '1'.
append wcellcolor to wa_emp-cellcolor.
ENDIF.
append wa_emp to emp.
CLEAR WA_EMP. clear wcellcolor.
endselect.
endform.
form sub_create_obj.
if container is initial.
create object container
exporting
container_name = 'MYCONT'.
endif.
if grid is initial.
create object grid
exporting
i_parent = container.
endif.
endform.
form sub_call_alv.
call method grid->set_table_for_first_display
exporting
is_layout = ls_layo
changing
it_outtab = emp
it_fieldcatalog = li_fcat
"it_sort = i_sort2
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
if sy-subrc <> 0.
endif.
create object lo_event.
set handler lo_event->handle_single_click for grid." set handler
endform.
form sub_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'EMP_X'.
ls_fcat-coltext = 'Check'.
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
ls_fcat-hotspot = 'X'." hotspot
append ls_fcat to li_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ZEMP_ID'.
ls_fcat-coltext = 'ID'.
append ls_fcat to li_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ZEMP_NAME'.
ls_fcat-coltext = 'Name'.
append ls_fcat to li_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ZEMP_SALARY'.
ls_fcat-coltext = 'Salary'.
ls_fcat-do_sum = 'X'.
append ls_fcat to li_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ZEMP_DPART'.
ls_fcat-coltext = 'Department'.
ls_fcat-drdn_hndl = '1'.
ls_fcat-edit = 'X'.
append ls_fcat to li_fcat.
clear ls_fcat.
endform.
form sub_layout.
ls_layo-zebra = 'X'.
ls_layo-INFO_FNAME = 'ROWCOLOR'.
endform.
module pbo output.
perform sub_get_data.
perform sub_fcat.
perform sub_layout.
perform sub_create_obj.
perform sub_drop.
perform sub_call_alv.
endmodule.
module pai input.
data: ok_code type sy-ucomm.
case ok_code.
when 'SHOW'.
MESSAGE 'D' TYPE 'I'.
WHEN 'EXIT'.
leave program.
WHEN OTHERS.
ENDCASE.
clear ok_code.
endmodule.
form sub_drop.
data: wa_drop type lvc_s_drop,
drop type lvc_t_drop.
wa_drop-handle = '1'.
wa_drop-value = 'Dev'.
append wa_drop to drop.
clear wa_drop.
wa_drop-handle = '1'.
wa_drop-value = 'Testing'.
append wa_drop to drop.
clear wa_drop.
wa_drop-handle = '1'.
wa_drop-value = 'Admin'.
append wa_drop to drop.
clear wa_drop.
wa_drop-handle = '1'.
wa_drop-value = 'NSS'.
append wa_drop to drop.
clear wa_drop.
wa_drop-handle = '1'.
wa_drop-value = 'Finance'.
append wa_drop to drop.
clear wa_drop.
call method grid->set_drop_down_table
EXPORTING
it_drop_down = drop.
endform.
*& Module set_gui OUTPUT
* text
MODULE set_gui OUTPUT.
set pf-status 'PF_GUI'.
ENDMODULE. " set_gui OUTPUT -
Moderator message: do not post the same question in more than one forum. Duplicate has been rejected
Hi,
I have 3 ALV Grids in my reports done by using containers with CL_GUI_ALV_GRID....
Each ALV Grid display a table....
Each toolbar of the grid has a print button.....
Here i have 2 questions...
i) when a print button of a grid is pressed..how can i know the grid of which the print button is pressed...i.e. if grid one print button is pressed..then how can i know it is triggered from Grid one and likewise for grid 2 and grid 3.
Im using same method for the event user_command for the three grids.......
ii) WHen layout is changed for a particular ALV grid...i.e. if some columns are made hidden...then when print button is pressed..Then i need to print only the columns of changed layout.............
How can i know the columns of the changed layout..........
<<Forbidden phrase removed>>
Thanks in Advanceeee
Sai Santosh
Edited by: Matt on Dec 15, 2008 3:45 PM1 - In local class definition, use the [SENDER|http://help.sap.com/saphelp_nw04s/helpdata/en/71/a8a77955bc11d194aa0000e8353423/frameset.htm] parameter of the event you manage.
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 sender.
PRIVATE SECTION.
ENDCLASS.
Then in the implemented method check the value, or use the object sender like any alv grid object.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_double_click.
CASE sender.
WHEN grid1.
(Doc: [Event Handling|http://help.sap.com/saphelp_sm32/helpdata/EN/9b/d080b49fc111d2bd68080009b4534c/frameset.htm])
2-use the method [GET_FRONTEND_FIELDCATALOG|https://www.sdn.sap.com/irj/scn/advancedsearch?query=get_frontend_fieldcatalog&cat=sdn_all] of CL_GUI_ALV_GRID to get the curent layout.
Regards
Maybe you are looking for
-
I started with an iPod, then moved to another state and also purchased an iPhone. I updated my new email address in my account settings, but when receiving updates, my old email address is displayed and cannot be edited. What can I do to make my en
-
Deployment aborted while deploying a webdynpro application
Hi SDNers, While deploying a webdynpro application deployment aborted and shown the following error. Aug 8, 2006 4:51:38 PM /userOut/deploy (com.sap.ide.eclipse.sdm.threading.DeployThreadManager) [Thread[Deploy Thread,5,main]] ERROR: [010]Deployment
-
Need to install OS X 10.3 on OS 9
I currently have OS 9 running on my MAC G4. I want to place OS X 10.3 on the computer without wiping away OS 9. I don't need to run it in Classic mode as I prefer to just go to the StartUp Disk Control Panel and switch back and forth from there. I ha
-
Can anyone assist.
-
Hi, How to resolve the issue given below dim1 --------<- fact ->------dim2 | | | | ▲ ▲ | | | | |________dim3_______| I want dim3 to be dimensional instead of fact ( which turns out to be fact after mapping shown above ). Is there any other alternativ