Skip to Content
0
Former Member
Aug 17, 2005 at 07:21 AM

save function at alvgrid

14 Views

hay experts,

I want only one column should be edited in Alvgrid.

After editing one column or inputing value to that particular

column, when i click userdefined Save button. it should save it

the corresponding table.

I have created below program till editing one column. but i have one doubt

how to save the data.

could you pls advice me.

I will send my alv code below.

pls have a look.

ambichan.

Source code below

Report ZALVSAMPLE.

TYPE-POOLS: icon.

TABLES: SFLIGHT.

CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA: gi_sflight TYPE STANDARD TABLE OF sflight.

DATA: ok_code LIKE sy-ucomm,

g_wa_sflight LIKE sflight.

DATA:

go_grid TYPE REF TO cl_gui_alv_grid,

go_custom_container TYPE REF TO cl_gui_custom_container,

o_event_receiver TYPE REF TO lcl_event_receiver,

gt_fieldcat type lvc_t_fcat,

gs_layout TYPE lvc_s_layo.

START-OF-SELECTION.

CALL SCREEN 300.

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_menu_and_default_button TYPE i VALUE 1,

c_menu TYPE i VALUE 2,

c_separator TYPE i VALUE 3,

c_radio_button TYPE i VALUE 4,

c_checkbox TYPE i VALUE 5,

c_menu_entry TYPE i VALUE 6.

DATA:

ls_toolbar TYPE stb_button.

  • Append seperator to the normal toolbar

CLEAR ls_toolbar.

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.

CLEAR ls_toolbar.

MOVE 'SAVE' TO ls_toolbar-function.

MOVE 'icon_SAVE' TO ls_toolbar-icon.

MOVE 'Save Details' TO ls_toolbar-quickinfo.

MOVE 'SAVE' TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDMETHOD.

METHOD handle_user_command.

  • Handle own functions defined in the toolbar

CASE e_ucomm.

WHEN 'SAVE'.

  • CALL METHOD go_grid->refresh_table_display.

  • CALL METHOD cl_gui_cfw=>flush.

  • LEAVE TO SCREEN 0.

ENDCASE.

ENDMETHOD.

ENDCLASS.

*&----


*

*& Module STATUS_0300 OUTPUT

*&----


*

MODULE STATUS_0300 OUTPUT.

SET PF-STATUS '300'.

  • Create objects

IF go_custom_container IS INITIAL.

CREATE OBJECT go_custom_container

EXPORTING container_name = 'ZCUSTOM'.

CREATE OBJECT go_grid

EXPORTING

i_parent = go_custom_container.

CREATE OBJECT o_event_receiver.

SET HANDLER o_event_receiver->handle_user_command FOR go_grid.

SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.

data ls_fcat type lvc_s_fcat.

call function 'LVC_FIELDCATALOG_MERGE'

exporting

i_structure_name = 'SFLIGHT'

changing

ct_fieldcat = gt_fieldcat.

loop at gt_fieldcat into ls_fcat.

if ls_fcat-fieldname eq 'CONNID'.

*§2.Set status of column WUNIT to editable and set a dropdown handle.

ls_fcat-edit = 'X'.

modify gt_fieldcat from ls_fcat.

endif.

endloop.

Perform Loaddata.

ENDIF.

ENDMODULE. " STATUS_0300 OUTPUT

FORM Loaddata.

  • Read data from table SFLIGHT

SELECT * FROM sflight INTO TABLE gi_sflight.

  • Load data into the grid and display them

CALL METHOD go_grid->set_table_for_first_display

EXPORTING i_structure_name = 'sflight'

is_layout = gs_layout

CHANGING it_outtab = gi_sflight

it_fieldcatalog = gt_fieldcat.

CALL METHOD go_grid->set_toolbar_interactive.

ENDFORM.

*&----


*

*& Module USER_COMMAND_0300 INPUT

*&----


*

MODULE USER_COMMAND_0300 INPUT.

CASE ok_code.

WHEN 'EXIT'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0300