ALV-TREE -转
****要注意创建相应程序的屏幕0100****
在一些情况下,输出的ALV可能用树形结构更容易展现数据之间的相互关联,为了输出ALV-TREE主要用到的是容器类(如CL_GUI_CONTAINER或CL_GUI_CUSTOM_CONTAINER等)和ALV-TREE控制器类CL_GUI_ALV_TREE。
对于类CL_GUI_ALV_TREE,主要用其ADD_NODE的方法添加节点。
下面直接给出仿照SAP示例程序BCALV_TREE_02创建的一个DEMO:
输出目标(汇总可用库存字段/双击节点对应的文件夹图标能展开其子节点):
*&---------------------------------------------------------------------*
*& Report Z15540_OOALV_TREE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z15540_OOALV_TREE.
*&---------------------------------------------------------------------*
*&数据对象定义
*&---------------------------------------------------------------------*
DATA:BEGIN OF GS_ALV,
WERKS TYPE MARD-WERKS,
LGORT TYPE MARD-LGORT,
MATNR TYPE MARD-MATNR,
MAKTX TYPE MAKT-MAKTX,
LABST TYPE MARD-LABST,
MEINS TYPE MARA-MEINS,
END OF GS_ALV.
DATA GT_ALV LIKE TABLE OF GS_ALV.
DATA:GS_FCAT TYPE LVC_S_FCAT,
GT_FCAT TYPE LVC_T_FCAT.
DATA:LCL_CONTAINER TYPE REF TO CL_GUI_CONTAINER, "容器类引用变量
LCL_TREE TYPE REF TO CL_GUI_ALV_TREE. "树形ALV控制器引用变量
DATA:OK_CODE TYPE SY-UCOMM, "获取100屏幕触发的功能码
SAVE_CODE TYPE SY-UCOMM.
*&---------------------------------------------------------------------*
*&事件接受类定义
*&---------------------------------------------------------------------*
CLASS LCL_HANDLE DEFINITION.
PUBLIC SECTION.
"定义双击节点事件触发时的处理方法
METHODS HANDLE_NODE_DCLICK
FOR EVENT NODE_DOUBLE_CLICK OF CL_GUI_ALV_TREE
IMPORTING NODE_KEY SENDER.
"其中SENDER这个参数是一个隐式的事件参数,是由ABAP对象运行系统提供,它指向了触发这个事件的实例,可以直接使用它来调用这个实例的方法。
ENDCLASS.
CLASS LCL_HANDLE IMPLEMENTATION.
"定义处理方法的具体实施
METHOD HANDLE_NODE_DCLICK.
DATA: LT_CHILDREN TYPE LVC_T_NKEY.
*检查被点击的NODE几点下面有无子节点,有则展开节点。
CALL METHOD SENDER->GET_CHILDREN
EXPORTING
I_NODE_KEY = NODE_KEY
IMPORTING
ET_CHILDREN = LT_CHILDREN.
IF NOT LT_CHILDREN IS INITIAL.
CALL METHOD SENDER->EXPAND_NODE
EXPORTING
I_NODE_KEY = NODE_KEY
I_LEVEL_COUNT = 2.
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'TITLE'.
IF LCL_TREE IS INITIAL.
PERFORM INIT_TREE.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Automation Queue failure'
TXT1 = 'Internal error:'
TXT2 = 'A method in the automation queue'
TXT3 = 'caused a failure.'.
ENDIF.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form INIT_TREE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM INIT_TREE .
"1.实例化容器对象
LCL_CONTAINER = CL_GUI_CONTAINER=>SCREEN0.
"2.实例化TREE控制器
CREATE OBJECT LCL_TREE
EXPORTING
PARENT = LCL_CONTAINER "绑定容器
NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE
ITEM_SELECTION = 'X'
NO_HTML_HEADER = 'X'
NO_TOOLBAR = ''
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
ILLEGAL_NODE_SELECTION_MODE = 5
FAILED = 6
ILLEGAL_COLUMN_NAME = 7.
IF SY-SUBRC <> 0.
MESSAGE E208(00) WITH '实例化ALV TREE控制器失败!'. "
ENDIF.
"3.设置NODE描述字段信息
DATA L_HIERARCHY_HEADER TYPE TREEV_HHDR.
PERFORM BUILD_HIERARCHY_HEADER CHANGING L_HIERARCHY_HEADER.
"4.设置ALV字段
PERFORM FRM_FILLFIELD USING: 'WERKS' '工厂',
'LGORT' '仓库',
'MATNR' '物料号',
'MAKTX' '物料描述',
'LABST' '非限制使用库存',
'MEINS' '数量单位'.
"5设置ALV显示字段
CALL METHOD LCL_TREE->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_HIERARCHY_HEADER = L_HIERARCHY_HEADER
CHANGING
IT_FIELDCATALOG = GT_FCAT
IT_OUTTAB = GT_ALV. "此表必须一直为空,且为全局变量
"6.设置根节点,填充叶节点数据
PERFORM CREATE_HIERARCHY.
"7.注册事件
PERFORM REGISTER_EVENTS.
* 更新汇总字段
CALL METHOD LCL_TREE->UPDATE_CALCULATIONS.
*前端显示数据
CALL METHOD LCL_TREE->FRONTEND_UPDATE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form build_hierarchy_header
*&---------------------------------------------------------------------*
* build hierarchy-header-information
*----------------------------------------------------------------------*
* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
*----------------------------------------------------------------------*
FORM BUILD_HIERARCHY_HEADER CHANGING
P_HIERARCHY_HEADER TYPE TREEV_HHDR.
P_HIERARCHY_HEADER-HEADING = '工厂/仓库'.
P_HIERARCHY_HEADER-TOOLTIP = '节点依据'.
P_HIERARCHY_HEADER-WIDTH = 50.
P_HIERARCHY_HEADER-WIDTH_PIX = ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_FILLFIELD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_
*& --> P_
*&---------------------------------------------------------------------*
FORM FRM_FILLFIELD USING P_FIELDNAME TYPE LVC_FNAME
P_COLTEXT TYPE LVC_TXTCOL.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = P_FIELDNAME.
GS_FCAT-COLTEXT = P_COLTEXT.
IF P_FIELDNAME = 'WERKS' OR P_FIELDNAME = 'LGORT' OR P_FIELDNAME = 'MATNR' .
GS_FCAT-NO_OUT = 'X'."隐藏右侧输出的MATNR/WERKS/LGORT字段
ELSEIF P_FIELDNAME = 'LABST'.
GS_FCAT-QFIELDNAME = 'MEINS'.
GS_FCAT-DO_SUM = 'X'."汇总可用库存字段
GS_FCAT-H_FTYPE = 'SUM'.
GS_FCAT-REF_FIELD = 'LABST'.
GS_FCAT-REF_TABLE = 'MARD'.
GS_FCAT-OUTPUTLEN = '30'.
ELSEIF P_FIELDNAME = 'MAKTX'.
GS_FCAT-OUTPUTLEN = '30'.
ENDIF.
APPEND GS_FCAT TO GT_FCAT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_HIERARCHY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM CREATE_HIERARCHY .
DATA: LS_NODE LIKE GS_ALV,
LS_ALV LIKE GS_ALV,
LT_ALV LIKE TABLE OF GS_ALV,
L_LAST_WERKS TYPE MARD-WERKS,
L_LAST_LGORT TYPE MARD-LGORT.
DATA: L_WERKS_KEY TYPE LVC_NKEY,
L_LGORT_KEY TYPE LVC_NKEY,
L_LAST_KEY TYPE LVC_NKEY,
L_TOP_KEY TYPE LVC_NKEY.
DATA L_NODE_TEXT TYPE LVC_VALUE.
SELECT D~MATNR,
D~WERKS,
D~LGORT,
D~LABST,
A~MEINS,
T~MAKTX
INTO CORRESPONDING FIELDS OF TABLE @LT_ALV UP TO 200 ROWS
FROM MARD AS D INNER JOIN MARA AS A
ON D~MATNR = A~MATNR
LEFT OUTER JOIN MAKT AS T
ON D~MATNR = T~MATNR
WHERE T~SPRAS = @SY-LANGU.
SORT LT_ALV BY WERKS LGORT.
"添加祖节点
CALL METHOD LCL_TREE->ADD_NODE
EXPORTING
I_RELAT_NODE_KEY = ''
I_RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
I_NODE_TEXT = '可用库存'
IMPORTING
E_NEW_NODE_KEY = L_TOP_KEY. "祖节点标识
"按照工厂->仓库层次设置节点,设置”叶片“,填充"叶片"数据
LOOP AT LT_ALV INTO LS_ALV.
"设置工厂节点
IF L_LAST_WERKS NE LS_ALV-WERKS.
L_LAST_WERKS = LS_ALV-WERKS.
"若此次循环到的工厂与上一次不相同,则创造新的工厂节点
"ADD NODE
CLEAR L_NODE_TEXT.
L_NODE_TEXT = LS_ALV-WERKS.
CALL METHOD LCL_TREE->ADD_NODE
EXPORTING
I_RELAT_NODE_KEY = L_TOP_KEY "处于祖节点之下
I_RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
I_NODE_TEXT = L_NODE_TEXT
IS_OUTTAB_LINE = LS_NODE
IMPORTING
E_NEW_NODE_KEY = L_WERKS_KEY. "工厂节点标识
CLEAR L_LAST_LGORT."当创建新的工厂节点时,清空上一个库存节点
ENDIF.
"设置库存节点
IF L_LAST_LGORT NE LS_ALV-LGORT.
L_LAST_LGORT = LS_ALV-LGORT.
"若此次循环到的库存点点与上一次不相同,则创造新的库存节点
"ADD NODE
CLEAR L_NODE_TEXT.
L_NODE_TEXT = LS_ALV-LGORT.
CALL METHOD LCL_TREE->ADD_NODE
EXPORTING
I_RELAT_NODE_KEY = L_WERKS_KEY "处于工厂节点之下
I_RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
I_NODE_TEXT = L_NODE_TEXT
IS_OUTTAB_LINE = LS_NODE
IMPORTING
E_NEW_NODE_KEY = L_LGORT_KEY. "工厂节点标识
ENDIF.
"设置”叶片“,填充"叶片"数据
CLEAR L_NODE_TEXT.
L_NODE_TEXT = LS_ALV-MATNR.
CALL METHOD LCL_TREE->ADD_NODE
EXPORTING
I_RELAT_NODE_KEY = L_LGORT_KEY "处于库存节点之下
I_RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
I_NODE_TEXT = L_NODE_TEXT
IS_OUTTAB_LINE = LS_ALV "有数据
IMPORTING
E_NEW_NODE_KEY = L_LAST_KEY. "工厂节点标识
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form REGISTER_EVENTS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM REGISTER_EVENTS .
"注册前端后后端事件
DATA: LT_EVENTS TYPE CNTL_SIMPLE_EVENTS,
L_EVENT TYPE CNTL_SIMPLE_EVENT,
L_EVENT_RECEIVER TYPE REF TO LCL_HANDLE.
*1。获取已注册的前端事件
CALL METHOD LCL_TREE->GET_REGISTERED_EVENTS
IMPORTING
EVENTS = LT_EVENTS.
"2.添加前端双击时间
L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_NODE_DOUBLE_CLICK.
APPEND L_EVENT TO LT_EVENTS.
*3.重新设置前端注册时间
CALL METHOD LCL_TREE->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = LT_EVENTS
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
ILLEGAL_EVENT_COMBINATION = 3.
IF SY-SUBRC <> 0.
MESSAGE E208(00) WITH '注册前端事件失败!'. "#EC NOTEXT
ENDIF.
*--------------------
"4.注册后端事件
CREATE OBJECT L_EVENT_RECEIVER.
SET HANDLER L_EVENT_RECEIVER->HANDLE_NODE_DCLICK FOR LCL_TREE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
SAVE_CODE = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_CODE.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
"释放容器,退出程序
CALL METHOD LCL_CONTAINER->FREE.
LEAVE PROGRAM.
WHEN OTHERS.
"为正确调用工具栏按钮功能,必须调用该方法
CALL METHOD CL_GUI_CFW=>DISPATCH.
ENDCASE.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDMODULE.
本文转载自:https://www.cnblogs.com/jianglaizhen/p/8870859.html
ALV-TREE -转的更多相关文章
- OO方式下,ALV TREE和ALV GRID的不同之处
作为大部分报表程序的基础,ALV GRID差不多是每个ABAP开发者必须了解和掌握的内容,因此网上也不乏相关资料,而ALV TREE的应用相对较少,中文资料也就比较少见了.实际上,ALV TREE和A ...
- ALV TREE 实例
ALV TREE 实例 REPORT ZRPT_PS_PS021TREE . TABLES: PROJ, "项目定义数据 PRPS, "WBS元素数据 ZCJ30, "A ...
- ALV TREE中双击触发PAI事件的方法
用事件类实现双击事件,实例化后使用set handler注册到ALV对象.斜体部分为事件方法的具体实现. 代码如下 CLASS lcl_tree_event_receiver DEFINITION. ...
- ALV Tree demo(WBS元素分层显示)[引用别人的]
原文地址:http://www.xuebuyuan.com/1666753.html 按层次显示WBS编码及描述,附加节点双击展开事件和Item双击跳转CJ03功能. 因为本人懒,本例代码都是从标准的 ...
- ALV tree标准DEMO
BCALV_TREE_01 ALV 树控制:构建层次树 BCALV_TREE_02 ALV 树控制:事件处理 BCALV_TREE_03 ALV 树控制:使用自己的上下文菜单 BCALV_TREE_0 ...
- ALV tree DUMP 问题处理-20180328
Category ABAP Programming Error Runtime Errors MESSAGE_TYPE_X ABAP Program SAPLOLEA Application Comp ...
- ALV详解:OO ALV
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 屏幕 Dynpro
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- ABAP知识点提纲
编号 课程名称 课程内容 预计课时 10.1.1~10.1.2 SAP系统与产品集 1. 了解SAP常见产品 ,了解SAP系统架构 1 10.1.3~10.1.4 导航界面与用户界面 1. 了解SAP ...
随机推荐
- Storm监控文件夹变化 统计文件单词数量
监控指定文件夹,读取文件(新文件动态读取)里的内容,统计单词的数量. FileSpout.java,监控文件夹,读取新文件内容 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- leetCode题解之根据字符出现的频率排序
1.题目描述 Given a string, sort it in decreasing order based on the frequency of characters. Example 1: ...
- [Asp.net mvc]Asp.net mvc 中使用LocalStorage
目前使用比较多的本地存储方案有比如Flash SharedObject.Google Gears.Cookie.LocalStorage.User Data.Open Database等方案.综合比较 ...
- Aheadof Time Compilation(AOT) vs (JIT)Just In Time compilation approach
像java这样的高级语言,往往先做好部分编译,在运行时,再使用JIT将前面编译的中间件输出编译为机器语言,放到机器上运行.这可能会影响到运行的性能. 再比如,像angular的web 应用,angul ...
- docker集群部署
一.使用自定义网桥连接跨主机容器 要是Linux可以工作在网桥模式,必须安装网桥工具bridge-utils,运行命令:# yum install bridge-utils 查看桥连状态:# brct ...
- [翻译] AYVibrantButton
AYVibrantButton https://github.com/a1anyip/AYVibrantButton AYVibrantButton is a stylish button with ...
- Hadoop HBase概念学习系列之HBase里的宽表设计概念(表设计)(二十七)
在下面这篇博文里,我给各位博客们,分享了创建HBase表,但这远不止打好基础. HBase编程 API入门系列之create(管理端而言)(8) 在关系型数据库里,表的高表和宽表是不存在的.在如HBa ...
- ES6中map和set用法
ES6中map和set用法 --转载自廖雪峰的官方网站 一.map Map是一组键值对的结构,具有极快的查找速度. 举个例子,假设要根据同学的名字查找对应的成绩,如果用Array实现,需要两个Arra ...
- 针对 Linux 环境下 gdb 动态调试获取的局部变量地址与直接运行程序时不一致问题的解决方案
基础的缓冲区溢出实践通常需要确定运行状态下程序中的某些局部变量的地址,如需要确定输入缓冲区的起始地址从而获得注入缓冲区中的机器指令的起始地址等.在 Linux 环境下,可通过 gdb 对程序进行动态调 ...
- Angular总结一:环境搭建
工欲善其事必先利其器,开发 Angular 项目首先要搭建环境.Angular 的环境搭建包括三个方面,开发环境 WebStorm,命令行工具 Angular CLI,以及 nodejs. 一.安装 ...