ABAP OOALV模板

server/2024/11/28 21:19:34/

自用模板,可能存在问题

一、主程序

*&---------------------------------------------------------------------*
*& 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/server/145721.html

相关文章

定制独立站系统需要哪些技术支持?

定制独立站系统需要的技术支持主要包括以下几个方面&#xff1a; 网站开发与设计&#xff1a;建立一个专业的网站需要网站开发人员和设计师&#xff0c;他们能够使用各种编程语言和框架&#xff08;如HTML、CSS、JavaScript、PHP、Python等&#xff09;来创建用户友好的界面和功…

Flink四大基石之Window

Window Flink 认为 Batch 是 Streaming 的一个特例&#xff0c;所以Flink 底层引擎是一个流式引擎&#xff0c;在上面实现了流处理和批处理。而窗口&#xff08;window&#xff09;就是从 Streaming 到 Batch 的一个桥梁。Flink 提供了非常完善的窗口机制。 为什么需要Windo…

网络安全:攻击和防御练习(全战课), DDos压力测试

XSS 跨站脚本攻击&#xff1a; Cross-site scripting&#xff08;简称xss&#xff09;跨站脚本。 一种网站的安全漏洞的攻击&#xff0c;代码注入攻击的一种。XSS攻击通常指的是通过利用网页开发时留下的漏洞&#xff0c;通过巧妙的方法注入恶意指令代码到网页&#xff0c;使…

ElasticSearch的下载和基本使用(通过apifox)

1.概述 一个开源的高扩展的分布式全文检索引擎&#xff0c;近乎实时的存储&#xff0c;检索数据 2.安装路径 Elasticsearch 7.8.0 | Elastic 安装后启动elasticsearch-7.8.0\bin里的elasticsearch.bat文件&#xff0c; 启动后就可以访问本地的es库http://localhost:9200/ …

2024年11月24日Github流行趋势

项目名称&#xff1a;FreeCAD 项目维护者&#xff1a;wwmayer, yorikvanhavre, berndhahnebach, chennes, WandererFan等项目介绍&#xff1a;FreeCAD是一个免费且开源的多平台3D参数化建模工具。项目star数&#xff1a;20,875项目fork数&#xff1a;4,117 项目名称&#xff1…

Oracle如何记录登录用户IP

在运维场景中&#xff0c;在定位到某个SQL引起系统故障之后&#xff0c;想知道是哪台机器发过来的&#xff0c;方便定位源头&#xff0c;该如何解决&#xff1f; 在 Oracle 数据库中记录登录用户的 IP 地址可以通过多种方法实现。以下是几种常见的方法&#xff0c;包括使用触发…

【Threejs进阶教程-着色器篇】9.顶点着色器入门

【Threejs进阶教程-着色器篇】9.顶点着色器入门 本系列教程第一篇地址&#xff0c;建议按顺序学习认识顶点着色器varying介绍顶点着色器与片元着色器分别的作用Threejs在Shader中的内置变量各种矩阵gl_Position 尝试使用顶点着色器增加分段数增强效果 制作平面鼓包效果鼓包效果…

23种设计模式-外观(Facade)设计模式

文章目录 一.什么是外观设计模式&#xff1f;二.外观设计模式的特点三.外观设计模式的结构四.外观设计模式的优缺点五.外观设计模式的 C 实现六.外观设计模式的 JAVA 实现七.代码解析八.总结 类图&#xff1a; 外观设计模式类图 一.什么是外观设计模式&#xff1f; 外观设计模…