Application Development and Automation 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: 
Read only

ALV EDITABLE AND SAVING INTO DATABASE TABLE

Former Member
0 Likes
5,548

HI, this program is working fine but data is not saving in the database table.

REPORT ZALV_INSERT.

*

DATA : itab TYPE STANDARD TABLE OF ztest,"Output table

i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,"Field catalog

i_selected_rows TYPE lvc_t_row,"Selected Rows

w_selected_rows TYPE lvc_s_row,

i_modified TYPE STANDARD TABLE OF ztest,"For getting modified rows

w_modified TYPE ztest,

wa TYPE ztest,

w_variant TYPE disvariant,

o_docking TYPE REF TO cl_gui_docking_container,"Docking Container

o_grid TYPE REF TO cl_gui_alv_grid."Grid

FIELD-SYMBOLS : <fs_fieldcat> TYPE lvc_s_fcat.

TABLES ztest.

SELECT-OPTIONS s_matnr FOR ztest-matnr.

SELECT * FROM ztest INTO TABLE itab WHERE matnr IN s_matnr.

CALL SCREEN 9000.

&----


*& Module STATUS_9000 OUTPUT

&----


  • PBO

----


MODULE status_9000 OUTPUT.

IF o_docking IS INITIAL.

SET PF-STATUS 'ZSTATUS'. "GUI Status

SET TITLEBAR 'ZTITLE'. "Title

  • Creating Docking Container and grid

PERFORM create_object.

  • Filling the fieldcatalog table

PERFORM create_fieldcat.

  • Modifying the fieldcatalog table

PERFORM modify_fieldcat.

  • Registering edit

PERFORM register_edit.

  • Displaying the output

PERFORM display_output.

ENDIF.

ENDMODULE. " STATUS_9000 OUTPUT

&----


*& Module USER_COMMAND_9000 INPUT

&----


  • PAI

----


MODULE user_command_9000 INPUT.

DATA lv_ucomm TYPE sy-ucomm.

lv_ucomm = sy-ucomm.

CASE lv_ucomm.

WHEN 'CANCEl' OR 'EXIT'.

PERFORM free_objects.

LEAVE PROGRAM.

WHEN 'BACK'.

PERFORM free_objects.

SET SCREEN '0'.

LEAVE SCREEN.

WHEN 'SAVE'.

PERFORM save_database.

CALL METHOD o_grid->refresh_table_display.

ENDCASE.

ENDMODULE. " USER_COMMAND_9000 INPUT

&----


*& Form create_object

&----


  • Creating Docking Container and grid

----


FORM create_object .

  • Creating Docking Container

CREATE OBJECT o_docking

EXPORTING ratio = '95'.

IF sy-subrc EQ 0.

  • Creating Grid

CREATE OBJECT o_grid

EXPORTING i_parent = o_docking.

ENDIF.

ENDFORM. " create_object

&----


*& Form create_fieldcat

&----


  • Filling the fieldcatalog table

----


FORM create_fieldcat .

  • Filling the fieldcatalog table

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING i_structure_name = 'ztest'

CHANGING ct_fieldcat = i_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

ENDFORM. " create_fieldcat

&----


*& Form modify_fieldcat

&----


  • Making the column as ediable

----


FORM modify_fieldcat .

LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>.

CASE <fs_fieldcat>-fieldname.

WHEN 'STKOT'.

  • Making a column as Editable

<fs_fieldcat>-edit = 'X'.

ENDCASE.

ENDLOOP.

ENDFORM. " modify_fieldcat

&----


*& Form register_edit

&----


  • Registering Edit

----


FORM register_edit .

CALL METHOD o_grid->register_edit_event

EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified.

ENDFORM. " register_edit

&----


*& Form display_output

&----


  • Displaying the output

----


FORM display_output .

w_variant-report = sy-repid.

  • Displaying the output

CALL METHOD o_grid->set_table_for_first_display

EXPORTING

is_variant = w_variant

i_save = 'A'

CHANGING

it_outtab = itab

it_fieldcatalog = i_fieldcat

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.

ENDFORM. " display_output

&----


*& Form free_objects

&----


  • Free Objects

----


FORM free_objects .

CALL METHOD o_grid->free

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD o_docking->free

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " free_objects

&----


*& Form save_database

&----


  • Save in database

----


FORM save_database .

  • Getting the selected rows index

CALL METHOD o_grid->get_selected_rows

IMPORTING et_index_rows = i_selected_rows.

  • Through the index capturing the values of selected rows

LOOP AT i_selected_rows INTO w_selected_rows.

READ TABLE itab INTO wa INDEX w_selected_rows-index.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING wa TO w_modified.

  • APPEND w_modified TO i_modified.

INSERT W_MODIFIED INTO TABLE I_MODIFIED.

ENDIF.

ENDLOOP.

ENDFORM.

5 REPLIES 5
Read only

Former Member
0 Likes
1,482

INSERT W_MODIFIED INTO TABLE I_MODIFIED. I guess I_MODIFIED is an internal table and not a databse table!

Regards,

John.

Read only

0 Likes
1,482

your correct jhon, but i tried with database table aswel but its not saving data on database table.

plz check

sat

Read only

Former Member
0 Likes
1,482

before perform save data.

use class check_changed_data before get selected rows.

i_modify should of type same as database table.

in ur program i did not see any update startment for database table.

write this statemet after the loop of get selected rows.

UPDATE ztest FROM TABLE i_modify .

Read only

Former Member
0 Likes
1,482

WHEN 'SAVE'.

use check_changed_data method.... replicate the data changed into the internal table...then call save

PERFORM save_database.

Read only

Former Member
0 Likes
1,482

&----


*& Form save_database

&----


  • Save in database

-


FORM save_database .

  • Getting the selected rows index

CALL METHOD o_grid->get_selected_rows

IMPORTING et_index_rows = i_selected_rows.

  • Through the index capturing the values of selected rows

LOOP AT i_selected_rows INTO w_selected_rows.

READ TABLE itab INTO wa INDEX w_selected_rows-index.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING wa TO w_modified.

  • APPEND w_modified TO i_modified.

INSERT W_MODIFIED INTO TABLE I_MODIFIED. <<Provide database table name

ENDIF.

ENDLOOP.

ENDFORM.

1st collect all the records and then insert records at a time to the database table.

use the statement :

Insert dbtab FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...

Edited by: Joyjit Ghosh on Jun 24, 2008 2:52 PM