本文主要是介绍ABAP OO ALV模板(Docking 容器),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
来了新入职的开发同事,因为之前双方都来自不同的乙方公司,所以开发习惯上有挺大的差异
我之前的公司是使用的LVC函数进行的报表开发,另一位同事是公司是使用的OO ALV进行开发,借此机会拓展一下知识面,再补补报表开发的基础
感觉Docking容器的应用应该比Custome Control来的多一些,毕竟不需要在屏幕上固定划出一块区域作为ALV展示的自定义容器,用户还能通过拖拽自定义容器的大小
开发步骤如下:
新建屏幕
开发Docking 容器的OO ALV只需要新建一个屏幕即可
OO ALV中常用的是ALV的tool bar,所以会把应用程序工具栏隐藏掉,勾选【无应用程序工具栏】即可
在屏幕流逻辑中新建module
新建GUI 状态 & GUI 标题
新建的GUI状态是空白的,标准工具栏的功能大多数都没有,至少把退出的几个功能先实现出来,否则用户进入ALV之后就无法退出
新建GUI标题,代码中可以用占位符&填充自定义文本
代码实现
********************************************************************
* 事务代码: *
* 程序名称: *
* 程序目的:OO ALV Docking容器 *
* 设 计 人: *
* 开 发 人: *
* 设计时间:2023-05-30 *
* 程序类型: ABAP/4 程序 ,报表程序 *
* 应用类型: XX *
* 描 述: *
*(修改日志)--------------------------------------------------------*
* *
* 日志号 修改人 修改时间 修改说明 传输号码 *
* ---- ---- ------ -----------
* 001 Seele 2023-05-29 创建报表程序 *
********************************************************************REPORT zdemo_seele10.
*----------------------------------------------------------------------*
* 数据库表声明/Database table declaration
*----------------------------------------------------------------------*
TABLES:mkpf, " 物料凭证抬头mara,mseg. " 物料凭证行项目*----------------------------------------------------------------------*
* 结构声明类型/Structure type declaration
*----------------------------------------------------------------------*
*&---主表数据/master table data
TYPES:BEGIN OF ty_output,matnr TYPE makt-matnr , " 物料maktx TYPE makt-maktx , " 物料描述spras TYPE makt-spras , " 语言代码box TYPE c , " 选择框END OF ty_output.*----------------------------------------------------------------------*
* 全局变量定义/Global variable definition
*----------------------------------------------------------------------*
*&---全局内表定义
DATA:gt_output TYPE TABLE OF ty_output. " 主数据表*&---全局结构定义
DATA:gs_output TYPE ty_output. " 主数据结构*&---全局变量定义
DATA:gv_lines TYPE string. " 统计行数*&---------------------------------------------------------------------*
*& 字段串定义/Field-symbols *
*&---------------------------------------------------------------------*
FIELD-SYMBOLS:<fs_output> TYPE ty_output.*&---------------------------------------------------------------------*
*& 类定义/Class *
*&---------------------------------------------------------------------*
CLASS cl_events DEFINITION.PUBLIC SECTION." ALV工具栏按钮METHODS: handle_toolbar FOR EVENT toolbar OF cl_gui_alv_gridIMPORTING e_object e_interactive,handle_user_command FOR EVENT user_command OF cl_gui_alv_gridIMPORTING e_ucomm.ENDCLASS.*&---------------------------------------------------------------------*
*& 类实现/Class Implementation *
*&---------------------------------------------------------------------*
CLASS cl_events IMPLEMENTATION." ALV工具栏按钮METHOD handle_toolbar.PERFORM frm_handle_toolbar CHANGING e_object e_interactive.ENDMETHOD." ALV工具栏事件METHOD handle_user_command.PERFORM frm_handle_command CHANGING e_ucomm.ENDMETHOD.ENDCLASS.*&---------------------------------------------------------------------*
*& 对象定义/Object *
*&---------------------------------------------------------------------*
DATA: go_events TYPE REF TO cl_events,go_alv TYPE REF TO cl_gui_alv_grid,go_dctn TYPE REF TO cl_gui_docking_container.*&---------------------------------------------------------------------*
*& ALV TYPE/ALV 类型定义
*&---------------------------------------------------------------------*
*&---ALV数据组,类型池
TYPE-POOLS:slis,vrm.*&---定义ALV显示的字段列及其描述等属性
DATA:gt_fieldcat TYPE TABLE OF lvc_s_fcat, " ALV 控制: 字段目录gs_fieldcat TYPE lvc_s_fcat, " ALV 控制: 字段目录gs_layout TYPE lvc_s_layo. " ALV 控制: 布局结构*&---------------------------------------------------------------------*
*& Macro 宏定义
*&---------------------------------------------------------------------*
DEFINE mcr_set_catalog.gs_fieldcat-fieldname = &1. " 字段技术名称gs_fieldcat-coltext = &2. " 显示名称gs_fieldcat-ref_table = &3. " 参照表gs_fieldcat-ref_field = &4. " 参照表字段gs_fieldcat-qfieldname = &5. " 参考计量单位的字段名称gs_fieldcat-key = &6. " key 值gs_fieldcat-edit = &7. " 可编辑APPEND gs_fieldcat TO gt_fieldcat.CLEAR gs_fieldcat.
END-OF-DEFINITION.*&---------------------------------------------------------------------*
*& Selection Screen/选择屏幕
*&---------------------------------------------------------------------*
*&---选择屏幕块
SELECTION-SCREEN BEGIN OF BLOCK blk01 WITH FRAME TITLE TEXT-101.*&---范围
SELECT-OPTIONS:s_matnr FOR mara-matnr . " 物料凭证SELECTION-SCREEN END OF BLOCK blk01.*&---------------------------------------------------------------------*
*& Start-of-selection/开始选择屏幕 *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---内表数据获取PERFORM frm_get_data.IF gt_output IS INITIAL.MESSAGE s000(zmm001) DISPLAY LIKE 'E'.EXIT.ENDIF.*&---------------------------------------------------------------------*
*& end-of-selection/结束选择屏幕(程序结束处理,输出等) *
*&---------------------------------------------------------------------*
END-OF-SELECTION.CALL SCREEN '9001'.*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_10 text
*----------------------------------------------------------------------*
FORM frm_get_data.DATA:lv_tabix TYPE i,lv_atinn TYPE ausp-atinn.FREE:gt_output.SELECTmatnr, " 物料编码maktx, " 物料描述spras " 语言代码FROM maktWHEREmatnr IN @s_matnrINTO CORRESPONDING FIELDS OF TABLE @gt_outputUP TO 100 ROWS.gv_lines = lines( gt_output ).gv_lines = gv_lines && TEXT-t01.ENDFORM. " frm_get_data*&---------------------------------------------------------------------*
*& Form FRM_INIT_SCREEN_9001
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_init_screen_9001 .
*&===ALV 输出
*&---设置ALV对象PERFORM frm_init_object.
*&---注册ALV事件PERFORM frm_register_event.
*&---设置ALV输出格式PERFORM frm_init_layout.
*&---设置ALV输出字段PERFORM frm_set_fieldcat.
*&---ALV 显示PERFORM frm_display_alv.
ENDFORM.*&---------------------------------------------------------------------*
*& Form frm_init_object
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_init_object ." 容器对象CREATE OBJECT go_dctnEXPORTINGrepid = sy-repid " 当前程序名dynnr = sy-dynnr " 当前屏幕号extension = 2000. " 当前长宽" GRID对象CREATE OBJECT go_alvEXPORTINGi_parent = go_dctn." 事件对象CREATE OBJECT go_events.ENDFORM. " frm_init_object*&---------------------------------------------------------------------*
*& Form FRM_REGISTER_EVENT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_register_event .SET HANDLER go_events->handle_toolbar FOR go_alv.SET HANDLER go_events->handle_user_command FOR go_alv.
ENDFORM.*&---------------------------------------------------------------------*
*& Form frm_init_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_init_layout .CLEAR gs_layout.gs_layout-zebra = 'X' . " 斑马线gs_layout-cwidth_opt = 'X' . " 自动调整ALVL列宽
* gs_layout-no_toolbar = 'X' . " 隐藏工具栏gs_layout-sel_mode = 'A'. "选择模式gs_layout-box_fname = 'BOX'. "选择字段
ENDFORM. " frm_init_layout
*&---------------------------------------------------------------------*
*& Form frm_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat .
*&---ALV 输出字段目录,涉及字段必须大写mcr_set_catalog: 'MATNR' TEXT-a01 'MAKT' 'MATNR' '' '' '', " 物料'MAKTX' TEXT-a02 'MAKT' 'MAKTX' '' '' '', " 物料描述'SPRAS' TEXT-a03 'MAKT' 'SPRAS' '' '' ''. " 语言代码ENDFORM. " frm_fieldcat*&---------------------------------------------------------------------*
*& Form frm_display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_display_alv .
*&---ALV 显示函数IF go_alv IS BOUND.CALL METHOD go_alv->set_table_for_first_displayEXPORTING
* is_variant = ls_variantis_layout = gs_layouti_save = 'A'i_default = 'X'CHANGINGit_outtab = gt_outputit_fieldcatalog = gt_fieldcat.ENDIF.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.
ENDFORM. " frm_display_alv
*&---------------------------------------------------------------------**&---------------------------------------------------------------------*
*& Form FRM_HANDLE_TOOLBAR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- E_OBJECT
*& <-- E_INTERACTIVE
*&---------------------------------------------------------------------*
FORM frm_handle_toolbar CHANGING pe_object TYPE REF TO cl_alv_event_toolbar_setpe_interactive .DATA ls_toolbar TYPE stb_button." 设置竖线以区分按钮区域ls_toolbar-butn_type = 3.APPEND ls_toolbar TO pe_object->mt_toolbar.CLEAR ls_toolbar." 自定义功能按钮ls_toolbar = VALUE #( function = 'PRT'icon = icon_printtext = '打印'quickinfo = 'Print' ).APPEND ls_toolbar TO pe_object->mt_toolbar.ENDFORM.*&---------------------------------------------------------------------*
*& Form FRM_USER_COMMAND_9001
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_user_command_9001 .CASE sy-ucomm.WHEN 'BACK'.LEAVE TO SCREEN 0.WHEN 'EXIT'.LEAVE PROGRAM.WHEN OTHERS.ENDCASE.ENDFORM.*&---------------------------------------------------------------------*
*& Form FRM_HANDLE_COMMAND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- E_UCOMM
*&---------------------------------------------------------------------*
FORM frm_handle_command CHANGING pe_ucomm.CASE pe_ucomm.WHEN 'PRT'.MESSAGE '点击打印' TYPE 'S'.WHEN OTHERS.ENDCASE.
ENDFORM.*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9001 OUTPUT.SET PF-STATUS 'STATUS_9001'.SET TITLEBAR 'TITLE_9001' WITH gv_lines.PERFORM frm_init_screen_9001.
ENDMODULE.*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.PERFORM frm_user_command_9001.
ENDMODULE.
效果图
参考文档:大佬夜猫君的博客
这篇关于ABAP OO ALV模板(Docking 容器)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!