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

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

 

ContractedBlock.gif ExpandedBlockStart.gif Code
*&---------------------------------------------------------------------*
*& 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

转载于:https://www.cnblogs.com/qiangsheng/archive/2009/06/09/1499812.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值