之前写过很多关于 CL_SALV_TABLE 显示alv的DEMO

但是使用这个class 实现 可控制的列编辑,单元格编辑一直没找到.

网上查得到的信息是:不支持

CL_SALV_TABLE <wbr>实现列编辑

​​

CL_SALV_TABLE <wbr>实现列编辑

然后有位外国小哥用下面的方法实现了列编辑:

效果如下,F8 执行后,双击某行

CL_SALV_TABLE <wbr>实现列编辑

代码如下,有兴趣可以自己研究下 

*----------------------------------------------------------------------*
* CLASS lcl_salv_buddy DEFINITION
*----------------------------------------------------------------------*
*
* Developed by Lino Lopes (lino2112@gmail.com) - Version 1.0
*
* This class is meant to be used with SALV objects to gain access to the GUI control that exist behind them.
* All SALV objects are descendants of the CL_SALV_MODEL_BASE class. Currently, there are the following SALV object classes:
* CL_SALV_TABLE
* CL_SALV_HIERSEQ_TABLE
* CL_SALV_TREE
*
* We inherit from the abstract class CL_SAL_CONTROLLER because SALV objects have it as a FRIEND, thus
* making us a FRIEND of SALV objects too. That allows us to have access to ALL attributes and methods of
* SALV objects, regardless of them being PUBLIC, PROTECTED or PRIVATE. Example: R_CONTROLLER.
* Since this class only has STATIC methods, there's no need to instantiate objects of its type, thus the CRIATE PRIVATE.
* Finally, I see no need to inherit from this class, so this class is declared FINAL.
*----------------------------------------------------------------------*
CLASS lcl_salv_buddy DEFINITION INHERITING FROM cl_salv_controller CREATE PRIVATE FINAL.

PUBLIC SECTION.

*----------------------------------------------------------------------*
* GET_CONTROL_RTTI - Returns runtime type information for the control that is behind a SALV object.
* Parameter E_ADAPTER_TYPE returns the adapter type of a SALV object.
* Based on this information, method GET_CONTROL will return a different control in its returrning parameter R_CONTROL.
* You can use this runtime type information to choose the right control object to supply to the returning parameter R_CONTROL of method GET_CONTROL.
* Parameter E_CONTROL_RTTI returns a TYPE HANDLE that you can use to create an object compatible with the returning parameter R_CONTROL of method GET_CONTROL.
* Below there is a correspondence between the adapter type returned in parameter E_ADAPTER_TYPE and
* the type of the control expected in parameter R_CONTROL of method GET_CONTROL:
* IF_SALV_ADAPTER~C_ADAPTER_TYPE_FULLSCREEN CL_GUI_ALV_GRID
* IF_SALV_ADAPTER~C_ADAPTER_TYPE_GRID CL_GUI_ALV_GRID
* IF_SALV_ADAPTER~C_ADAPTER_TYPE_HIERSEQ nothing (null)
* IF_SALV_ADAPTER~C_ADAPTER_TYPE_LIST CL_SALV_TABLE
* IF_SALV_ADAPTER~C_ADAPTER_TYPE_TREE CL_SALV_GUI_TREE
* IF_SALV_ADAPTER~C_ADAPTER_TYPE_APPEND nothing (null)
*----------------------------------------------------------------------*
CLASS-METHODS: get_control_rtti IMPORTING i_salv TYPE REF TO cl_salv_model_base
EXPORTING e_adapter_type TYPE salv_de_adapter_type
e_control_rtti TYPE REF TO cl_abap_typedescr,

*----------------------------------------------------------------------*
* GET_CONTROL - Returns the control that is behind the SALV object.
* MUST be called after the DISPLAY method of the SALV object, so that its control gets created.
* See method GET_CONTROL_RTTI above for a correspondence between what you supply in paramter I_SALV and what you get back in parameter R_CONTROL.
*----------------------------------------------------------------------*
get_control IMPORTING i_salv TYPE REF TO cl_salv_model_base
RETURNING value(r_control) TYPE REF TO object,

*----------------------------------------------------------------------*
* SET_EDITABLE - Enables OR disables editing on a CL_SALV_TABLE object.
* If you supply parameter I_FIELDNAME and supply it NOT INITIAL, you get that
* field enabled or disabled for editing, depending on parameter I_EDITABLE.
* If you do not supply parameter I_FIELDNAME or supply it INITIAL, you get
* all fields of the table enabled or disabled for editing, depending on parameter I_EDITABLE.
* Parameter I_SALV_TABLE is the CL_SALV_TABLE object you want to enable or disable editing for.
* Parameter I_EDITABLE should be ABAP_TRUE or ABAP_FALSE to enable or disable editing.
* Parameter I_REFRESH indicates whether you want the control to be refreshed or not. You'll only see the changes
* you've made using this method AFTER you do a refresh on the CL_SALV_TABLE object.
* NOTE: If you want field per field editing capabilities, you MUST make sure editing for the whole table is disabled.
* You can disable editing for the whole table simply by issuing a call to this method, omitting parameter I_FIELDNAME and
* passing parameter I_EDITABLE as ABAP_FALSE. After that you can enable or disable editing on a field per field basis.
* The CL_SALV_TABLE is disabled for editing by default.
*----------------------------------------------------------------------*
set_editable IMPORTING value(i_fieldname) TYPE csequence OPTIONAL
i_salv_table TYPE REF TO cl_salv_table