alv中alv的简单实例
程序员文章站
2024-02-24 13:57:40
...
alv的简单实例
END-OF-SELECTION.
PERFORM frm_get_alv.
"ALV显示所需参数
DATA: i_fieldcat_alv TYPE slis_t_fieldcat_alv, " WITH HEADER LINE,
i_layout TYPE slis_layout_alv,
i_fieldcat TYPE slis_fieldcat_alv,
w_repid LIKE sy-repid,
git_events TYPE slis_t_event,
git_list_comments TYPE slis_t_listheader.
FORM frm_get_alv .
PERFORM frm_get_events. "用于定义ALV表单的表头
PERFORM frm_layout_build. "用于定义ALV表单的相关格式、属性
PERFORM frm_fields. "用来定义表单中的各个列的相关信息,比如列名等
SORT gt_data BY pernr. "按员工编号排序 zje 20190128
PERFORM frm_display_data. "用来显示ALV表单
ENDFORM.
"用于定义ALV表单的表头
FORM frm_get_events .
DATA l_events TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = git_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR l_events.
ENDFORM.
"用于定义ALV表单的相关格式、属性
FORM frm_layout_build .
i_layout-zebra = 'X'.
i_layout-detail_popup = 'X'. "是否弹出详细信息窗口
w_repid = sy-repid. "程序为当前程序
i_layout-f2code = '&ETA'.
"设置触发弹出详细信息窗口的功能码,这里是双击
i_layout-no_vline = ' '. "这个用来设置列间隔线
i_layout-colwidth_optimize = 'X'. "优化列宽选项是否设置
i_layout-detail_initial_lines = 'X'.
i_layout-detail_titlebar = '详细内容'. "设置弹出窗口的标题栏
ENDFORM.
FORM frm_display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid "当前程序
i_save = ''
it_events = git_events
is_layout = i_layout
"子函数layout_build填充的格式定义
i_callback_pf_status_set = 'FRM_STATUS_SET' "屏幕内容
it_fieldcat = i_fieldcat_alv[] "子函数fields填充的各列
i_callback_user_command = 'USER_COMMAND' "按钮操作
TABLES
t_outtab = gt_data. "假设数据都在ALV内表中
ENDFORM. "frm_display_data
"用来定义表单中的各个列的相关信息,比如列名等
FORM frm_fields .
DATA: l_pos TYPE i.
REFRESH i_fieldcat_alv.
l_pos = 1.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'NO'.
i_fieldcat-seltext_l = '序号' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'STEXT1'.
i_fieldcat-seltext_l = '事业部' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'STEXT_O'.
i_fieldcat-seltext_l = '末级' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'STEXT'.
i_fieldcat-seltext_l = '岗位' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'PERNR'.
i_fieldcat-seltext_l = '工号' .
i_fieldcat-emphasize = 'C100' . "列的颜色
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'SNAME'.
i_fieldcat-seltext_l = '姓名' .
i_fieldcat-emphasize = 'C100' . "列的颜色
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'RLZRQ'.
i_fieldcat-seltext_l = '入职日期/离职日期' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'AZ101'.
i_fieldcat-seltext_l = '工资总额' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'ASB'.
i_fieldcat-seltext_l = '社保' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'AZ362'.
i_fieldcat-seltext_l = '公积金' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3804'.
i_fieldcat-seltext_l = '年金' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'AZ403'.
i_fieldcat-seltext_l = '所得税' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3805'.
i_fieldcat-seltext_l = '税后年金' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3002'.
i_fieldcat-seltext_l = '手续费' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3001'.
i_fieldcat-seltext_l = '工会费' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3009'.
i_fieldcat-seltext_l = '电话费' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'AZF'.
i_fieldcat-seltext_l = '杂费' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3008'.
i_fieldcat-seltext_l = '代扣社保' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3011'.
i_fieldcat-seltext_l = '扣货款' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3025'.
i_fieldcat-seltext_l = '扣借款' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3105'.
i_fieldcat-seltext_l = '预留款' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'A3024'.
i_fieldcat-seltext_l = '暂扣货款' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'AFN'.
i_fieldcat-seltext_l = '返纳' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'AZSF'.
i_fieldcat-seltext_l = '实发' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
l_pos = l_pos + 1.
i_fieldcat-col_pos = l_pos.
i_fieldcat-fieldname = 'DMBTR'.
i_fieldcat-seltext_l = '发票' .
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
ENDFORM.
"用来显示ALV表单
ENDFORM.
FORM frm_display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid "当前程序
i_save = ''
it_events = git_events
is_layout = i_layout
"子函数layout_build填充的格式定义
i_callback_pf_status_set = 'FRM_STATUS_SET' "屏幕内容
it_fieldcat = i_fieldcat_alv[] "子函数fields填充的各列
i_callback_user_command = 'USER_COMMAND' "按钮操作
TABLES
t_outtab = gt_data. "假设数据都在ALV内表中
ENDFORM.
"浏览器按钮
FORM frm_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'WE'.
ENDFORM.
"按钮功能
FORM user_command USING ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
CASE ucomm.
WHEN 'EXPORT'.
IF gt_data[] IS NOT INITIAL.
PERFORM frm_export_data.
ELSE.
MESSAGE '没有数据,请检查!' TYPE 'S' DISPLAY LIKE 'W'.
STOP.
ENDIF.
WHEN 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDFORM.
"屏幕内容
FORM frm_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'WE'.
ENDFORM.
上一篇: 开发中的问题解决
下一篇: 如何使用Flex Menu