今天写了个查看 ABAP 类层级的程序

论坛 期权论坛 脚本     
匿名技术用户   2021-1-4 16:12   60   0

以前一直很少贴代码,今天这个写的比较满意,贴出来大家看看。

ContractedBlock.gifExpandedBlockStart.gifCode
*&---------------------------------------------------------------------*
*& Report ZCLASSTREE
*&
*&---------------------------------------------------------------------*
*& Author: QiangSheng@hotmail.com
*& Create: 2009-06-09
*&
*& This Program can find the inheritance tree of a class,
*& from it's root class, to all the sub-class of this root.
*&
*& There is a little bug in this report. because of the function-code
*& mechanism in SAP List Tree function modules, when you press the
*& "Expand" button on left of a node, it will return the double-click
*& function-code, and you will be navigate to the "Class Builder"
*& first, then when come back, the node expanded.
*& If you don't want this, use the Expand button on Application Bar
*& instead.
*&---------------------------------------------------------------------*

REPORT zclasstree.

TABLES: seometarel, seoclass.

PARAMETERS: pclsname LIKE seometarel
-clsname OBLIGATORY.
SELECTION
-SCREEN COMMENT /1(80) comm1.
SELECTION
-SCREEN COMMENT /1(80) comm2.

*TYPE-POOLS : fibs,stree.
DATA : t_node TYPE snodetext.
DATA : node_tab LIKE t_node OCCURS
0 WITH HEADER LINE.

DATA: fclsname LIKE seometarel
-clsname.

AT SELECTION
-SCREEN OUTPUT.
comm1
= 'Input the class name, I will create it''s inheritance tree for you.'(c01).
comm2
= 'In the navigate tree, double click a node to go to the Class Builder.'(c01).

AT SELECTION
-SCREEN.
SELECT SINGLE
* FROM seoclass WHERE clsname = pclsname.
IF sy
-subrc NE 0.
MESSAGE
'Class not exist!'(m01) TYPE 'E'.
ENDIF.


START
-OF-SELECTION.
fclsname
= pclsname.
* Search for the root class.
DO.
SELECT SINGLE
* FROM seometarel WHERE clsname = fclsname AND reltype = 2.
IF sy
-subrc EQ 0.
fclsname
= seometarel-refclsname.
ELSE.
EXIT.
ENDIF.
ENDDO.

* Search for all sub-class and create the list tree.
PERFORM search_subclass USING fclsname
'01'.
IF lines( node_tab ) EQ
1.
MESSAGE
'Class is standalone.'(m02) TYPE 'S'.
ENDIF.

* Create the list tree.
CALL FUNCTION
'RS_TREE_CONSTRUCT'
TABLES
nodetab
= node_tab.

CALL FUNCTION
'RS_TREE_LIST_DISPLAY'
EXPORTING
callback_program
= sy-repid
callback_user_command
= 'USER_COMMAND'
status
= 'STANDARD'
use_control
= 'L'. "F: display as control, L: display as list.


*&---------------------------------------------------------------------*
*& Form search_subclass
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FCLSNAME text
*----------------------------------------------------------------------*
FORM search_subclass USING uclsname ulevel.
DATA: clevel TYPE n LENGTH
2.
node_tab
-type = 'P'.
node_tab
-name = uclsname.
node_tab
-tlevel = ulevel.
node_tab
-nlength = '40'.
IF uclsname EQ pclsname.
node_tab
-color = 6.
ELSE.
node_tab
-color = 4.
ENDIF.
SELECT SINGLE descript FROM seoclasstx INTO node_tab
-text WHERE clsname = uclsname AND langu = sy-langu.
* node_tab-text = ''.
node_tab
-tlength ='70'.
node_tab
-tcolor = 3.
APPEND node_tab.

SELECT
* FROM seometarel WHERE refclsname = uclsname.
clevel
= ulevel + 1.

PERFORM search_subclass USING seometarel
-clsname clevel.
ENDSELECT.
ENDFORM.
" search_subclass

*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->NODE text
* -->COMMAND text
* -->EXIT text
* -->LIST_REFRESH text
*----------------------------------------------------------------------*
FORM user_command TABLES node STRUCTURE seucomm
USING command
CHANGING exit
list_refresh.
IF command EQ
'TRPI'.
SET PARAMETER ID
'CLASS' FIELD node-name.
CALL TRANSACTION
'SE24' AND SKIP FIRST SCREEN.
ENDIF.
ENDFORM.
"user_command
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP