更改ALV字段并同步自建数据表
参考ABAP
数据表操作教程。
ALV报表数据怎么可以实现可编辑? 然后可以保存到自建表ZTVBAP_TEST
中?
-
修改ALV字段展示属性值。
"修改alv显示字段属性 edit wa_fieldcat-edit = 'X'. "指定显示字段可编辑 MODIFY it_fieldcat FROM wa_fieldcat TRANSPORTING edit WHERE fieldname = 'KWMENG'. CLEAR wa_fieldcat.
-
声明与自建表同名的工作区, 并定义一个内表
"声明与自建表同名的工作区 TABLES:ZTVBAP_TEST. "定义一个内表 DATA: IT_ZTVBAP_TEST TYPE STANDARD TABLE OF ZTVBAP_TEST.
-
执行点击保存事件,调子程序:
PERFORM SAVE_DATA.
* 定义 响应执行事件的子程序 FORM USER_COMMAND USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. CASE r_ucomm. WHEN '&IC1'. * MESSAGE I003(Z_FC). MESSAGE I002(Z_FC) WITH rs_selfield-tabindex rs_selfield-fieldname. WHEN 'MESS'. MESSAGE '你点击了消息按钮' TYPE 'I'. WHEN 'CLEAR'. PERFORM clear_data. "清空字段数据 rs_selfield-refresh = 'X'. "刷新界面 WHEN '&DATA_SAVE'. " 保存数据 PERFORM SAVE_DATA. WHEN OTHERS. ENDCASE. ENDFORM.
-
子程序
GET_GLOBALS_FROM_SLVC_FULLSCR
函数将传统的alv转变为面向对象的alv,可以保证数据同步。FORM save_data . DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID. " 使用OO 的刷新方式,先使用GET_GLOBALS_FROM_SLVC_FULLSCR接收屏幕ALV,放置容器,再调用刷新方法 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' * EXPORTING * IR_SALV_FULLSCREEN_ADAPTER = IMPORTING * ET_EXCLUDING = * E_REPID = * E_CALLBACK_PROGRAM = * E_CALLBACK_ROUTINE = E_GRID = G_GRID * ET_FIELDCAT_LVC = * ER_TRACE = * E_FLG_NO_HTML = * ES_LAYOUT_KKBLO = * ES_SEL_HIDE = * ET_EVENT_EXIT = * ER_FORM_TOL = * ER_FORM_EOL = . " 同步数据 将alv中的数据同步到内表中 CALL METHOD g_grid->check_changed_data * IMPORTING * e_valid = * CHANGING * c_refresh = 'X' . "获取数据 LOOP AT it_vbap INTO wa_vbap. " 只有 wa_vbap 中的字段与 ZTVBAP_TEST 字段一致的才会迁移。 " MOVE-CORRESPONDING wa_vbap TO ZTVBAP_TEST. ZTVBAP_TEST-ZWERKS = wa_vbap-werks. ZTVBAP_TEST-ZMATNR = wa_vbap-MATNR. ZTVBAP_TEST-ZKWMENG = wa_vbap-KWMENG. ZTVBAP_TEST-ZMEINS = wa_vbap-MEINS. APPEND ZTVBAP_TEST TO IT_ZTVBAP_TEST. CLEAR ZTVBAP_TEST. ENDLOOP. " 更新或新建数据 MODIFY ZTVBAP_TEST FROM TABLE IT_ZTVBAP_TEST. ENDFORM.