*下面的代码是在alv字段中修改字段的内容,点击保存后就可以保存数据至数据表。
TABLES: spfli.
DATA:
wa_fieldcat TYPE lvc_s_fcat , " 相当于工作区
i_fieldcat TYPE lvc_t_fcat , " 存放输出栏位名称的列表
i_layout TYPE lvc_s_layo . " 负责整个ALV的全局属性
DATA tab_spfli LIKE TABLE OF spfli WITH HEADER LINE. " 定义内表
DATA wa_spfli TYPE spfli.
DATA it_spfli LIKE STANDARD TABLE OF spfli. " 定义内表
DATA lt_spfli TYPE spfli.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE tab_spfli. "将数据表中的数据存入内表中
PERFORM getfield.
PERFORM is_layout.
DATA: l_user_command TYPE slis_formname VALUE 'USER_COMMAND'. "定义返回事件
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' "定义显示内表
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_USER_COMMAND = l_user_command
IS_LAYOUT_LVC = i_layout
IT_FIELDCAT_LVC = i_fieldcat
I_SAVE = 'A'
TABLES
t_outtab = tab_spfli
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
FORM getfield. "定义显示字段
wa_fieldcat-col_pos = 1 .
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-just = 'C'.
wa_fieldcat-seltext = '航线代码'.
wa_fieldcat-fix_column = 'X'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 2 .
wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-just = 'C'.
wa_fieldcat-seltext = '航班连接号'.
wa_fieldcat-fix_column = 'X'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 3 .
wa_fieldcat-fieldname = 'CITYFROM'.
wa_fieldcat-just = 'C'.
wa_fieldcat-seltext = '起飞城市'.
wa_fieldcat-edit = 'X'. "设置成可编辑状态
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 4 .
wa_fieldcat-fieldname = 'CITYTO'.
wa_fieldcat-just = 'C'.
wa_fieldcat-seltext = '到达城市'.
wa_fieldcat-edit = 'X'. "设置成可编辑状态
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 5 .
wa_fieldcat-fieldname = 'DERTIME'.
wa_fieldcat-just = 'C'.
wa_fieldcat-seltext = '出发时间'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 6 .
wa_fieldcat-fieldname = 'ARRTIME'.
wa_fieldcat-just = 'C'.
wa_fieldcat-seltext = '到达时间'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
ENDFORM.
FORM is_layout. "定义ALV显示样式
i_layout-ZEBRA = 'X'.
i_layout-CWIDTH_OPT = 'X'.
ENDFORM.
FORM user_command USING r_ucomm