Alv Editable and Saving Into Database Table

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

ALV EDITABLE AND SAVING INTO

DATABASE TABLE
Posted on 24 de Jun de 2008 às 12:43 | 772 Views
Follow

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.

You might also like