Created
May 17, 2012 08:57
-
-
Save EkremGungormez/2717527 to your computer and use it in GitHub Desktop.
Editable Alv update database table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REPORT ZBC0818_EDITABLEALV_ALINAN. | |
* Data declarations | |
DATA : itab TYPE STANDARD TABLE OF 'Database Table Name',"Output table | |
i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,"Field catalog | |
i_modified TYPE STANDARD TABLE OF 'Database Table Name',"For getting modified rows | |
i_selected_rows TYPE lvc_t_row,"Selected Rows | |
w_selected_rows TYPE lvc_s_row, | |
w_modified TYPE 'Database Table Name', | |
wa TYPE 'Database Table Name', | |
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 | |
data : fs_fieldcat TYPE lvc_s_fcat. | |
SELECT * FROM 'Database Table Name' INTO TABLE itab . | |
CALL SCREEN 9000. | |
*&---------------------------------------------------------------------* | |
*& Module STATUS_9000 OUTPUT | |
*&---------------------------------------------------------------------* | |
* PBO | |
*----------------------------------------------------------------------* | |
MODULE status_9000 OUTPUT. | |
IF o_docking IS INITIAL. | |
SET PF-STATUS 'STATUS_9000'. "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 'UP'. | |
PERFORM free_objects. | |
SET SCREEN 0. | |
LEAVE SCREEN. | |
WHEN '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 = '"Database Table Name"' | |
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 into fs_fieldcat . | |
CASE fs_fieldcat-fieldname. | |
WHEN '"write here Fieldname"'. | |
fs_fieldcat-coltext = 'write here text you want to see as header on the list' . | |
MODIFY i_fieldcat FROM fs_fieldcat. | |
WHEN '"write here fieldname"'. | |
* Making a column as Editable | |
fs_fieldcat-coltext = 'write here text you want to see as header on the list' . | |
fs_fieldcat-edit = 'X'. | |
MODIFY i_fieldcat FROM fs_fieldcat. | |
WHEN 'write here fieldname'. | |
fs_fieldcat-coltext = 'write here text you want to see as header on the list' . | |
MODIFY i_fieldcat FROM fs_fieldcat. | |
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. | |
CALL METHOD o_grid->register_edit_event | |
EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified. | |
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. | |
ENDIF. | |
ENDLOOP. | |
MODIFY 'database table name' FROM TABLE i_modified. | |
ENDFORM. " save_database |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to save the drop down values of alv in a customise table in abap??