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 ...
随机推荐
- public 类、default 类、内部类、匿名内部类
0.父类里private的成员变量,子类只有拥有权,没有使用权. 1.default 类 和public 类 package HelloWorld; public class HelloWorld { ...
- with admin option /with grant option
1. with admin option是用在系统权限上的,with grant option是用在对象权限上的. SQL> grant create synonym to scott with ...
- ahjesus Axure RP 8.0注册码,亲测可用
ahjesus Axure RP 8.0注册码 ahjesus Axure RP 8.0注册码 用户名:aaa注册码:2GQrt5XHYY7SBK/4b22Gm4Dh8alaR0/0k3gEN5h7F ...
- 回归JavaScript基础(六)
主题:引用类型Date.RegExp的介绍. 上节主要主要介绍了Object.Array引用类型.这节将继续为大家介绍引用类型,并对书中的一些知识点进行总结与归纳,也借此巩固自己对JavaScript ...
- 9.Java注解(Annotation)
一.系统内置标准注解 1.@Override 是一个标记注解类型,它被用作标注方法. 它说明了被标注的方法重载了父类的方法,起到了断言的作用.如果我们使用了这种Annotation在一个没有覆盖父类方 ...
- CentOS6.4 下安装 MySql5.5.13
1.卸载系统自带的MySql 1.1.查看该操作系统上是否已经安装了mysql数据库 [root@xhTest-1 ~]# rpm -qa | grep mysql 1.2.删除原mysql数据库 1 ...
- [翻译] BAFluidView
BAFluidView https://github.com/antiguab/BAFluidView This view and it's layer create a 2D fluid anima ...
- ZT 人生真的是一场马拉松吗?
中国合伙人:孟晓俊:生活应该是什么样的?自己提出的问题应该由自己来回答,别人的回答是别人的答案,是别人的生活,而你应该过自己的生活,不是别人的生活. 人生真的是一场马拉松吗? 投递人 itwr ...
- 项目属性的target platform和target platform version到底是什么(vs2015开发windows驱动小记)
根据官方对属性页的介绍(General Property Page (Project))可了解: target platform是build后的结果会跑在哪个平台,例如windows,android, ...
- zookeeper for windows
1,安装java环境,安装完java之后,添加用户变量.并在命令行中测试 java -version . 2,下载zookeeper http://mirrors.shu.edu.cn/apache/ ...