[ALV]实现ALV显示可编辑,并可更新至数据库
(2011-10-17 18:21:12)
标签:
alvedit杂谈 |
分类: ABAP-ALV-Form |
实现步骤:
1. 定义存放显示数据的internal table it_output[], 定义一个class,并声明一个实例:
2. 如普通ALV Grid控件显示一样,完成基本步骤,然后将事件注册,并设置触发
3. 当数据改动后,回车会出发事件,事件会将改动的数据重新显示(貌似多余,先留着)
4. 点击SAVE时,PAI中进行处理,将数据更新至数据库,并重新显示
注意:在建立 Fieldcatalog时,需要将字段的edit设成'X'才能进行编辑
*&---------------------------------------------------------------------*
*& Report
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT
*Type pools for alv
TYPE-POOLS : slis.
*Structure for output display
TYPES : BEGIN OF ty_output.
TYPES : number TYPE n,
*internal table and work area declarations
DATA : it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
*Data declarations for dropdown lists for f4
DATA: it_dropdown TYPE lvc_t_drop,
*data declaration for refreshing of alv
*Global variable declaration
DATA: gstring TYPE c.
*Data declarations for ALV
DATA: c_ccont TYPE REF TO
cl_gui_custom_container,
*ok code declaration
DATA:
**************************************************************
* LOCAL CLASS Definition for data changed in fieldcatalog ALV
**************************************************************
CLASS lcl_event_receiver DEFINITION.
ENDCLASS.
**************************************************************
* LOCAL CLASS implementation for data changed in fieldcatalog ALV
**************************************************************
CLASS lcl_event_receiver IMPLEMENTATION.
ENDCLASS.
DATA: event_receiver TYPE REF TO lcl_event_receiver.
*initialization event
INITIALIZATION.
*start of selection event
START-OF-SELECTION.
*select the infotypes maintained
* Calling the ALV screen with custom container
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_0600 OUTPUT.
ENDMODULE.
* calling the PBO module ALV_GRID.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
*Creating objects of the container
*
*
* Set ALV attributes FOR LAYOUT
* Call ALV GRID
ENDMODULE.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*subroutine to build fieldcat
FORM alv_build_fieldcat.
*To create drop down for the field 'DAVO'
* with our own f4 help
** To assign dropdown in the fieldcataogue
ENDFORM.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*Subroutine for setting alv layout
FORM alv_report_layout.
ENDFORM.
* PAI module of the screen created. In case we use an interactive ALV or
*for additional functionalities we can create OK codes
*and based on the user command we can do the coding.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE pai INPUT.
*To change the existing values and refresh the grid
*And only values in the dropdown or in the default
*F4 can be given , else no action takes place for the dropdown
*and error is thrown for the default F4 help and font changes to red
*and on still saving, value is not changed
*
*
*
*
*
*Based on the user input
*When user clicks 'SAVE;
*A pop up is called to confirm the saving of changed data
*
*
*When the User clicks 'YES'
*Subroutine to display the ALV with changed data.
*When user clicks NO or Cancel
**When the user clicks the 'EXIT; he is out
ENDMODULE.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
*
*----------------------------------------------------------------------*
FORM redisplay .
*Cells of the alv are made non editable after entering OK to save
*
*
*
*Row and column of the alv are refreshed after changing values
*REfreshed ALV display with the changed values
*This ALV is non editable and contains new values
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
ENDFORM.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM save_data .
*
*
ENDFORM.