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: 

Handle Refresh button on ALV

Former Member
0 Kudos

I am displaying an Editable ALV (using OO ABAP)

Befor I display I handled soe validations.

Issue:

When the user changes any data on the editable alv, and press refresh button the toolbar, these validations should trigger again.

How can I change this standard functionality.

Thanks

Kiran

6 REPLIES 6

Former Member
0 Kudos

Hi Kiran

Check this code

REPORT zwsalvgrid.

TYPE-POOLS: icon.

TABLES: zc6_employee.

CLASS lcl_event_receiver DEFINITION DEFERRED.

----


DATA: BEGIN OF i_employee OCCURS 0.

INCLUDE STRUCTURE zc6_employee.

DATA: traffic_light TYPE c.

DATA: line_color(4) TYPE c.

DATA: END OF i_employee.

----


DATA: ok_code LIKE sy-ucomm,

wa_employee LIKE LINE OF i_employee,

gs_layout TYPE lvc_s_layo.

DATA: grid1 TYPE REF TO cl_gui_alv_grid,

i_custom_container TYPE REF TO cl_gui_custom_container,

o_event_receiver TYPE REF TO lcl_event_receiver.

DATA: wa_change LIKE zc6_employee.

DATA:

  • Data for storing information about selected rows in the grid

gi_index_rows TYPE lvc_t_row, " Internal table

g_selected_row LIKE lvc_s_row. " Information about 1 row

----


  • C L A S S E S

----


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.

ENDCLASS.

----


  • CLASS lcl_event_receiver IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_toolbar. " Event handler method for event toolbar.

CONSTANTS: " Constants for button type.

c_button_normal TYPE i VALUE 0,

c_separator TYPE i VALUE 3.

DATA:

ls_toolbar TYPE stb_button.

MOVE c_separator TO ls_toolbar-butn_type.

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Append a new button that to the toolbar. Use E_OBJECT of

  • event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.

  • This class has one attribute MT_TOOLBAR which is of table type

  • TTB_BUTTON. The structure is STB_BUTTON

CLEAR ls_toolbar.

MOVE 'CHANGE' TO ls_toolbar-function.

MOVE icon_change TO ls_toolbar-icon.

MOVE 'Change Details' TO ls_toolbar-quickinfo.

MOVE 'Change' TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDMETHOD.

METHOD handle_user_command." Handleown functions defined in thetoolbar

CASE e_ucomm.

WHEN 'CHANGE'.

PERFORM change_details.

ENDCASE.

ENDMETHOD.

ENDCLASS.

----


  • S T A R T - O F - S E L E C T I O N.

----


START-OF-SELECTION.

SELECT-OPTIONS: s_empid FOR zc6_employee-s1empid.

SELECT * FROM zc6_employee INTO CORRESPONDING FIELDS OF TABLE

i_employee WHERE s1empid IN s_empid.

CALL SCREEN '100'.

&----


*& Module USER_COMMAND_0100 INPUT

&----


MODULE user_command_0100 INPUT.

CASE ok_code.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Module STATUS_0100 OUTPUT

&----


MODULE status_0100 OUTPUT.

DATA:

v_layout TYPE disvariant.

IF i_custom_container IS INITIAL.

  • Create objects for container and ALV grid

CREATE OBJECT i_custom_container

EXPORTING container_name ='ALV_CONTAINER'.

CREATE OBJECT grid1

EXPORTING

i_parent = i_custom_container.

  • Create object for event_receiver class

  • and set handlers

CREATE OBJECT o_event_receiver.

SET HANDLER o_event_receiver->handle_user_command FOR grid1.

SET HANDLER o_event_receiver->handle_toolbar FOR grid1.

  • Layout (Variant) for ALV grid

v_layout-report = sy-repid. "Layout fo report

----


  • Setup the grid layout using a variable of structure lvc_s_layo

----


  • Set grid title

gs_layout-grid_title = 'ALV Grid Display-Employee Details'.

  • Selection mode B- Single row without buttons.

  • This is the default mode

gs_layout-sel_mode = 'B'.

gs_layout-excp_fname = 'TRAFFIC_LIGHT'.

gs_layout-info_fname = 'LINE_COLOR'.

LOOP AT i_employee INTO wa_employee.

wa_employee-traffic_light = '3'.

  • Value of color field:

  • C = Color, 6=Color 1=Intesified on, 0: Inverse display off

MODIFY i_employee FROM wa_employee.

ENDLOOP.

  • Grid setup for first display

CALL METHOD grid1->set_table_for_first_display

EXPORTING i_structure_name = 'ZC6_EMPLOYEE'

is_variant = v_layout

i_save = 'A'

is_layout = gs_layout

CHANGING it_outtab = i_employee[].

  • End of grid setup

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0200 INPUT

&----


MODULE user_command_0200 INPUT.

CASE ok_code.

WHEN'SAVE'.

PERFORM save_changes.

ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

&----


*& Form change_details

&----


  • Reads the contents of the selected row in the grid, and transfers

  • the data to screen 200, where it can be changed and saved.

----


FORM change_details.

REFRESH gi_index_rows.

CLEAR g_selected_row.

DATA:

l_lines TYPE i.

DESCRIBE TABLE gi_index_rows LINES l_lines.

IF l_lines > 0.

CALL METHOD grid1->set_selected_rows

EXPORTING

it_index_rows = gi_index_rows.

ENDIF.

  • Read index of selected rows

CALL METHOD grid1->get_selected_rows

IMPORTING

et_index_rows = gi_index_rows.

  • Check if any row are selected at all. If not

  • table gi_index_rows will be empty

DESCRIBE TABLE gi_index_rows LINES l_lines.

IF l_lines = 0.

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

textline1 = 'You must choose a line'.

EXIT.

ENDIF.

  • Read indexes of selected rows. In this example only one

  • row can be selected as we are using gs_layout-sel_mode = 'B',

  • so it is only ncessary to read the first entry in

  • table gi_index_rows

LOOP AT gi_index_rows INTO g_selected_row.

IF sy-tabix = 1.

READ TABLE i_employee INDEX g_selected_row-index INTO wa_employee.

ENDIF.

ENDLOOP.

  • Transfer data from the selected row to screen 200 and show

  • screen 200

CLEAR wa_change.

MOVE wa_employee TO wa_change.

CALL SCREEN 200 STARTING AT 5 5.

ENDFORM.

&----


*& Form save_changes

----


FORM save_changes.

MOVE wa_change TO wa_employee.

  • Update database table

MODIFY zc6_employee FROM wa_change.

MOVE wa_change TO wa_employee.

  • Update grid table , traffic light field and color field.

wa_employee-traffic_light = '1'.

  • C = Color, 6=Color 1=Intesified on, 0=Inverse display off

wa_employee-line_color = 'C610'.

MODIFY i_employee INDEX g_selected_row-index FROM wa_employee.

  • Refresh grid

CALL METHOD grid1->refresh_table_display.

CALL METHOD cl_gui_cfw=>flush.

LEAVE TO SCREEN 0.

ENDFORM. " save_changes

hope this helps u...

Regards

Sreenivas

0 Kudos

Hi Sreenivas

I am not creating any extra button on tool bar.

I want to handle the existing refresh button on standard alv tool bar.

Is this possible.

Thanks

Kiran

Former Member
0 Kudos

Ok first you need to copy the gui status STANDARD from the function group SALV into your program. This is the standard gui status used for the toolbar in your program, next modify it and add a button to the toolbar for your refresh. Then in you program, you need to tell it to use this status instead.

cl_salv_table=>factory( IMPORTING r_salv_table = gr_table

CHANGING t_table = ispfli ).

  • Here you are telling the alv object to use this gui status instead

gr_table->set_screen_status(

pfstatus = 'STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

Now, you will have your button on the toolbar, but you will still need to handle it.

Check program SALV_DEMO_TABLE_FUNCTIONS to see what the procedures are to handle your custom button.

Also, here is a tutorial which will walk you thru the entire process. With screenshots. Hope it is helpful.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/alv%20object%...

Reward if usefull

0 Kudos

Hai Naresh

That was really a helpful tutorial.

But the problem is

I am having all my declarations based on cl_gui_alv_grid. and used set_first_display for my alv display.

can u tell me how i can modify this for my requiremnt.

Thanks

Kiran

0 Kudos

Throw some light please.

Former Member
0 Kudos

solved on my own