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: 

save function at alvgrid

Former Member
0 Kudos

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

5 REPLIES 5

Former Member
0 Kudos

Hi,

Try to use the Function Module

call method g_grid->register_edit_event

exporting

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

Thanks&Regards

Ruthra.R

Former Member
0 Kudos

Hi Ambi,

Just add

UPDATE sflight

FROM TABLE gi_sflight

in the eventhandler (handle_user_command) for the SAVE button. (if needed you could call METHOD CHECK_CHANGED_DATE of the grid).

Kind regards,

John.

0 Kudos

hai john,

does the using of update statement correct?

if so pls tell me how to refresh the changes.

should i have to call below methods or ?

CALL METHOD go_grid->refresh_table_display.

CALL METHOD cl_gui_cfw=>flush.

or

call go_grid->set_table_for_first_display

pls update me..

ambichan

0 Kudos

In

o_grid_container   TYPE REF TO cl_gui_custom_container

*----------------------------------------------------------------------
* Control Object [o_grid]
*----------------------------------------------------------------------
o_grid  TYPE REF TO cl_gui_alv_grid


MODULE user_command_0100 INPUT.

*----------------------------------------------------------------------
*  As the events are registered as application events, control is first
*  passed to the program's PAI. The call 'cl_gui_cfw=>dispatch' will
*  forward control to ABAP object event handling and the appropriate
*  event handler will be called (if present). This allows the user to
*  selectively process events.
*----------------------------------------------------------------------
  DATA: i_return_code TYPE i .

  CALL METHOD cl_gui_cfw=>dispatch
      IMPORTING return_code = i_return_code.
  ws_save_ok = ok_code.
  CASE ws_save_ok.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      PERFORM exit_program.
  ENDCASE.
  CLEAR ws_save_ok.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&--------------------------------------------------------------------*
*&      Form  EXIT_PROGRAM
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM exit_program.

  CALL METHOD o_grid_container->free.

  CALL METHOD cl_gui_cfw=>flush.
  IF sy-subrc NE 0.
*     Error in FLush
  ENDIF.

  LEAVE TO SCREEN 0.
ENDFORM.                  " EXIT_PROGRAM

Hope this helps.

0 Kudos

Hi Ambi Chan,

Yes the update statement is correct, it will update the database table using the key fields. As you have filled the internal table with the exact same structure as the database table this should work fine.

As to my knowledge you don't have to call any additional methods.

Regards,

John.