ABAP OOALV模板

ops/2024/11/29 10:16:41/

自用模板,可能存在问题

一、主程序

*&---------------------------------------------------------------------*
*& Report ZVIA_OO_ALV
*&---------------------------------------------------------------------*
REPORT ZVIA_OO_ALV.INCLUDE ZVIA_OO_ALV_TOP1."OO ALV定义相关 (可能需要修改)
INCLUDE ZVIA_OO_ALV_TOP2."程序数据定义相关 (需要修改)
INCLUDE ZVIA_OO_ALV_S01."选择屏幕,获取用户输入 (需要修改)
INCLUDE ZVIA_OO_ALV_F01."取数逻辑等子例程 (需要修改)
INCLUDE ZVIA_OO_ALV_F02."OO ALV 相关 (需要修改)START-OF-SELECTION.PERFORM FRM_GET_DATA.END-OF-SELECTION.CALL SCREEN 2000.

二、OO ALV定义相关

*&---------------------------------------------------------------------*
*& 包含               ZVIA_OO_ALV_TOP1
*&---------------------------------------------------------------------*
DATA:gv_ucomm TYPE sy-ucomm,ok_code  TYPE sy-ucomm.DATA:gv_col_pos             LIKE sy-cucol,g_wa_allfields         TYPE lvc_s_fcat,g_grid_alv             TYPE REF TO cl_gui_alv_grid, "列表g_container_alv        TYPE scrfname VALUE 'GC_2000', "容器 (可能需要修改)g_custom_container_alv TYPE REF TO cl_gui_custom_container,gw_layout_alv          TYPE lvc_s_layo,gt_fieldcat_alv        TYPE lvc_t_fcat,gw_fieldcat_alv        TYPE lvc_s_fcat,gw_exclude_alv         TYPE ui_func,gt_exclude_alv         TYPE TABLE OF ui_func.*OO ALV Display*
DATA:go_alv TYPE REF TO cl_gui_alv_grid."声明ALV对象

 需要创建屏幕2000

三、程序数据相关

*&---------------------------------------------------------------------*
*& 包含               ZVIA_OO_ALV_TOP2
*&---------------------------------------------------------------------**根据报表数据结构来定义内表和结构体*
DATA:git_stu TYPE STANDARD TABLE OF zvia_stu,"内表gw_stu  TYPE zvia_stu."结构体TABLES:zvia_stu."使用到的表

四、选择屏幕

确认要使用到的用户选择字段

*&---------------------------------------------------------------------*
*& 包含               ZVIA_OO_ALV_S01
*&---------------------------------------------------------------------*
SELECT-OPTIONS:s_id FOR zvia_stu-stuid.

五、 取数逻辑等子例程

写自己的取数逻辑,这里写的比较简单

*&---------------------------------------------------------------------*
*& 包含               ZVIA_OO_ALV_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& 取数逻辑
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .SELECT *from  ZVIA_STUINTO TABLE git_stuWHERE stuid in s_id.
ENDFORM.

六、OO ALV 显示等相关 

*&---------------------------------------------------------------------*
*& 包含               ZVIA_OO_ALV_F02
*&---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.PUBLIC SECTION.METHODS:handle_top_of_pageFOR EVENT top_of_page OF cl_gui_alv_gridIMPORTING e_dyndoc_id,handle_double_clickFOR EVENT double_click OF cl_gui_alv_gridIMPORTING e_row e_column es_row_no,handle_toolbar_alvFOR EVENT toolbar OF cl_gui_alv_gridIMPORTING e_object e_interactive,handle_user_command_alvFOR EVENT user_command OF cl_gui_alv_gridIMPORTING e_ucomm,handle_onf4_helpFOR EVENT onf4 OF cl_gui_alv_gridIMPORTING e_fieldnamees_row_no"ER_EVENT_DATE,er_event_data,"HANDLE_DATE_CHANGED_alvHANDLE_DATA_CHANGED_alvFOR EVENT data_changed OF cl_gui_alv_gridIMPORTING er_data_changed.PRIVATE SECTION.
ENDCLASS.CLASS lcl_event_receiver IMPLEMENTATION.METHOD handle_double_click.MESSAGE 'SHUANG JI' TYPE 'S'.ENDMETHOD.METHOD handle_toolbar_alv.DATA:ls_toolbar TYPE stb_button.CLEAR: ls_toolbar.ls_toolbar-butn_type = 3."分隔符"APPEND LS_TOOLBAR TO E_ONJECT->MT_TOOLBAR.APPEND ls_toolbar TO e_object->mt_toolbar.CLEAR: ls_toolbar.ENDMETHOD.METHOD handle_user_command_alv.ENDMETHOD.METHOD handle_onf4_help.er_event_data->m_event_handled = 'X'.ENDMETHOD.METHOD handle_data_changed_alv.PERFORM handle_data_changed USING er_data_changed.ENDMETHOD.METHOD handle_top_of_page.ENDMETHOD.
ENDCLASS.FORM sub_set_field USING VALUE(p_first)VALUE(p_col_pos)VALUE(p_fieldname)VALUE(p_coltext)VALUE(p_key)VALUE(p_edit)VALUE(p_outputlen)VALUE(p_f4availabl)VALUE(p_checkbox).CLEAR g_wa_allfields.g_wa_allfields-col_pos = p_col_pos.g_wa_allfields-fieldname = p_fieldname.g_wa_allfields-coltext = p_coltext.g_wa_allfields-key = p_key.g_wa_allfields-edit = p_edit.g_wa_allfields-outputlen = p_outputlen.g_wa_allfields-f4availabl = p_f4availabl.g_wa_allfields-checkbox = p_checkbox.IF p_first = '1'.APPEND g_wa_allfields TO gt_fieldcat_alv.ENDIF.
ENDFORM.
*&---------------------------------------------------
*&FORM FRM_SET_ALV.行项目-需要修改-ALV报表需要显示哪些列
*&按照自己的需求改这里的列对应的字段和列名--------------
*&---------------------------------------------------
FORM frm_set_alv.CLEAR:gv_col_pos,gt_fieldcat_alv,gw_fieldcat_alv.gv_col_pos = gv_col_pos + 1.PERFORM sub_set_field USING '1' gv_col_pos 'STUID' '学生ID' '' '' '10' '' ''.gv_col_pos = gv_col_pos + 1.PERFORM sub_set_field USING '1' gv_col_pos 'STUNAME' '学生姓名' '' '' '10' '' ''.gv_col_pos = gv_col_pos + 1.PERFORM sub_set_field USING '1' gv_col_pos 'GENDER' '性别' '' '' '10' '' ''.gv_col_pos = gv_col_pos + 1.PERFORM sub_set_field USING '1' gv_col_pos 'AGE' '年龄' '' '' '10' '' ''.
ENDFORM.
*&---------------------------------------------------
*&FORM FRM_PREPARE_LAYOUT
*&ALV 显示相关的参数-比如是否可以编辑,是否可以选择
*&---------------------------------------------------
*&---------------------------------------------------
*&---------------------------------------------------
FORM frm_prepare_layout CHANGING cs_layout TYPE lvc_s_layo.cs_layout-zebra = 'X'."可选行颜色cs_layout-smalltitle = 'X'."标题大小cs_layout-edit_mode = 'X'."编辑模式cs_layout-cwidth_opt = 'X'."优化列宽度cs_layout-edit = ''."准备输入
*    CS_LAYOUT-NO ROWMWARK = ''."禁用行选择
*    CS_LAYOUT-SEL_MODE = 'R'."选择方式cs_layout-stylefname = 'STYLE'."内部表字段的字段名称cs_layout-info_fname = 'CLR'."WEB中显示的行数
*    CS_LAYOUT-NO_HGRIDLN = 'X'."隐藏水平网格线
ENDFORM.*&---------------------------------------------------
*&FORM HANDLE_DATA_CHANGED
*&---------------------------------------------------
FORM handle_data_changed USING p_er_data_changed TYPE REF TO cl_alv_changed_data_protocol.DATA: lw_mod_cell TYPE lvc_s_modi.DATA: lv_jine TYPE p DECIMALS 4.DATA:lv_shul TYPE p DECIMALS 4.IF p_er_data_changed->mt_mod_cells IS NOT INITIAL.LOOP AT p_er_data_changed->mt_mod_cells INTO lw_mod_cell.ENDLOOP.PERFORM sub_alv_refresh.ENDIF.
ENDFORM.*&---------------------------------------------------
*&FORM SUB_ALV_REFRESH
*&---------------------------------------------------
FORM sub_alv_refresh.DATA: lw_stable TYPE lvc_s_stbl."刷新稳定性lw_stable-row = 'X'.lw_stable-col = 'X'.CALL METHOD g_grid_alv->refresh_table_displayEXPORTING is_stable = lw_stable.
ENDFORM.*&---------------------------------------------------
*&MODULE STATUS_2000 OUTPUT.
*&---------------------------------------------------
*&这里面需要手动创建STATUS/TITLEBAR-------------------
*&---------------------------------------------------
MODULE status_2000 OUTPUT.SET PF-STATUS 'ZPF'."复制标准菜单栏(双击创建)SET TITLEBAR 'ZTITLE'."ALV显示的标题行(双击创建)PERFORM frm_prepare_layout CHANGING gw_layout_alv.PERFORM frm_2000_alv_show.
ENDMODULE.*&---------------------------------------------------
*&MOUDLE USER_COMMAND_2000 INPUT
*&---------------------------------------------------
*&用来响应用户的操作----------------------------------
*&---------------------------------------------------
MODULE user_command_2000 INPUT.gv_ucomm = ok_code.CASE gv_ucomm.WHEN '&F03' OR '&F12' OR '&F15'.LEAVE TO SCREEN 0."返回上一屏幕WHEN 'TEST'.MESSAGE 'TEST CLICKED' TYPE 'S'.WHEN OTHERS.ENDCASE.
ENDMODULE.*&---------------------------------------------------
*&FORM SUB SCREEN 2000
*&---------------------------------------------------
FORM sub_screen_2000.PERFORM frm_prepare_layoutCHANGINGgw_layout_alv.
ENDFORM.
*&---------------------------------------------------
*&FORM FRM 2000 ALV SCREEN
*&---------------------------------------------------
FORM frm_2000_alv_show.DATA:lw_variant           TYPE disvariant,lo_event_handler_alv TYPE REF TO lcl_event_receiver.lw_variant-report = sy-repid.PERFORM frm_set_alv.CREATE OBJECT lo_event_handler_alv.IF g_grid_alv IS INITIAL.CREATE OBJECT g_custom_container_alvEXPORTINGcontainer_name = g_container_alv."带参数的构造函数CREATE OBJECT g_grid_alvEXPORTINGi_parent = g_custom_container_alv."带参数的构造函数CALL METHOD g_grid_alv->set_table_for_first_displayEXPORTINGis_layout            = gw_layout_alvit_toolbar_excluding = gt_exclude_alvi_save               = 'A'is_variant           = lw_variantCHANGINGit_fieldcatalog      = gt_fieldcat_alvit_outtab            = git_stu[].SET HANDLER lo_event_handler_alv->handle_toolbar_alv FOR g_grid_alv.CALL METHOD g_grid_alv->register_edit_eventEXPORTINGi_event_id = cl_gui_alv_grid=>mc_evt_modified.*用户操作SET HANDLER lo_event_handler_alv->handle_user_command_alv FOR g_grid_alv.SET HANDLER lo_event_handler_alv->handle_data_changed_alv FOR g_grid_alv.*ALV双击SET HANDLER lo_event_handler_alv->handle_double_click FOR g_grid_alv.CALL METHOD g_grid_alv->set_toolbar_interactive.ELSE.CALL METHOD g_grid_alv->refresh_table_display.CALL METHOD cl_gui_cfw=>flush.ENDIF.
ENDFORM.


http://www.ppmy.cn/ops/137624.html

相关文章

Ubuntu系统上安装和启动SSH服务

安装OpenSSH服务器 打开终端。更新软件包列表&#xff1a;sudo apt update安装OpenSSH服务器&#xff1a;sudo apt install openssh-server启动并启用SSH服务 启动SSH服务&#xff1a; sudo systemctl start ssh设置SSH服务开机自启&#xff1a; sudo systemctl enable ssh检查…

【数据结构】插入排序

1.简单插入排序 1.1 基本思想 假设待排序记录集合为 &#xff0c;&#xff0c;... &#xff0c; 简记为 。插入排序方法由趟组成&#xff0c;假设要进行第 趟&#xff0c;此时第 ~ 个记录已经插入排好序&#xff0c;第 趟是将第 个记录插入到有序序列中&#xff0c…

List集合的进一步学习:性能优化

|| 持续分享系列教程&#xff0c;关注一下不迷路 || || B站视频教程&#xff1a;墨轩大楼 || || 知识星球&#xff1a;墨轩编程自习室 || 在Java集合框架中&#xff0c;选择合适的集合类型和使用正确的操作…

注意http-proxy-middleware要解决跨域问题,想修改origin请求头不要设置changeOrigin=true

在使用http-proxy-middleware的时候&#xff0c;有一个配置是“changeOrigin”&#xff0c;通过名字来看这个字段是用来控制是否修改origin的&#xff0c;但是实际使用下来&#xff0c;你会发现&#xff0c;当设置为true的时候&#xff0c;header中的origin的值并不会修改&…

4、常量和进制转换

1、常量 1.1、常量 常量是在程序运行中值不能内改变&#xff08;常数&#xff09;。 整型:12 55 实型:21.5 字符型常量: ‘A’ 1.2、常量不同进制表示 常量数据在计算机中除了用 十进制 表示&#xff0c;还可以用 二进制、八进制、十六进制表示。 十进制数据&…

快手守城之战

科技新知 原创作者丨樱木 编辑丨蕨影 双11过后&#xff0c;大厂来到了交卷时刻。三季度虽然是传统的淡季&#xff0c;但在电商重新洗牌、短视频流量见顶的关键之年&#xff0c;此刻的平淡则显得异常扎眼。 从业务类型来看&#xff0c;略显保守的快手似乎成了资本狙击的对象&a…

5G基础学习笔记

功能软件化 刚性网络&#xff1a;固定连接、固定功能、固化信令交互 柔性网络&#xff1a;网元拆解成服务模块&#xff0c;基于API接口调用 服务化架构&#xff08;SBA&#xff09; Service based Architecture &#xff08;SBA&#xff09;: 借鉴了业界成熟的SOA、微服务架…

蓝桥杯备赛笔记(一)

这里的笔记是关于蓝桥杯关键知识点的记录&#xff0c;有别于基础语法&#xff0c;很多内容只要求会用就行&#xff0c;无需深入掌握。 文章目录 前言一、编程基础1.1 C基础格式和版本选择1.2 输入输出cin和cout&#xff1a; 1.3 string以下是字符串的一些简介&#xff1a;字符串…