以下是纯顾问群~
QQ群 :SAP干货铺, 群号:775662808
所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!
如果您觉得这篇干货文章有用,请帮忙转载、分享给更多人,谢谢~
直接上干货吧~
最近写了几个 Function ALV 复选框+刷新的报表,
为了方便复制粘贴到其他项目修改,做了个demo。
效果
选中,删除
结构和 status
代码
REPORT zalv_demo
DATA:lt_alv_show LIKE TABLE OF ztest_spfli.
DATA:i_grid_title TYPE lvc_title.
DATA:lv_line TYPE int4.
DATA:ls_line TYPE string.
DATA:lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA:is_layout TYPE slis_layout_alv.
FIELD-SYMBOLS <ls_filed> LIKE LINE OF lt_fieldcat." CHECKBOX
START-OF-SELECTION.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_alv_show.
DESCRIBE TABLE lt_alv_show LINES lv_line.
ls_line = lv_line.
CONCATENATE '数据条目数:' ls_line INTO i_grid_title.
CLEAR lt_fieldcat[].
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZTEST_SPFLI'
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lt_fieldcat ASSIGNING <ls_filed> WHERE fieldname = 'CHECKBOX'.
<ls_filed>-checkbox = 'X'.
<ls_filed>-edit = 'X'.
<ls_filed>-seltext_l = '选择'.
<ls_filed>-seltext_m = '选择'.
<ls_filed>-seltext_s = '选择'.
ENDLOOP.
is_layout-colwidth_optimize = 'X' .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_grid_title = i_grid_title
i_callback_program = sy-repid "
is_layout = is_layout
it_fieldcat = lt_fieldcat[]
i_callback_pf_status_set = 'ZFORM_SET_PF_STATUS' "
i_callback_user_command = 'ALV_USER_COMMAND'
TABLES
t_outtab = lt_alv_show
EXCEPTIONS
program_error = 1
OTHERS = 2.
*&---------------------------------------------------------------------*
*& Form zform_set_pf_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM zform_set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD' .
ENDFORM. "zform_set_PF_STATUS
*&---------------------------------------------------------------------*
*& Form alv_user_command
*&---------------------------------------------------------------------*
FORM alv_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA:lv_err TYPE string.
DATA: l_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS <ls_alv> LIKE LINE OF lt_alv_show.
DATA:ls_alv LIKE LINE OF lt_alv_show.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
CALL METHOD l_grid->refresh_table_display.
CASE r_ucomm.
WHEN 'DEL'.
DELETE lt_alv_show WHERE checkbox = 'X' .
WHEN 'ALL'.
LOOP AT lt_alv_show ASSIGNING <ls_alv> .
<ls_alv>-checkbox = 'X'.
ENDLOOP.
WHEN 'SAL'.
LOOP AT lt_alv_show ASSIGNING <ls_alv> .
<ls_alv>-checkbox = ''.
ENDLOOP.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'LEAVE'.
LEAVE PROGRAM.
ENDCASE .
DESCRIBE TABLE lt_alv_show LINES lv_line.
ls_line = lv_line.
CONCATENATE '数据条目数:' ls_line INTO i_grid_title.
CALL METHOD l_grid->set_gridtitle
EXPORTING
i_gridtitle = i_grid_title.
CALL METHOD l_grid->check_changed_data.
CALL METHOD l_grid->refresh_table_display.
**
* rs_selfield-refresh = 'X'.
*
* rs_selfield-col_stable = 'X'.
* rs_selfield-row_stable = 'X'.
ENDFORM . "ALV_USER_COMMAND
标签:11,REUSE,show,fieldcat,alv,lt,grid,ALV,line From: https://blog.51cto.com/u_15680210/5757794