通过Tcode查找Badi或者客户出口

https://wiki.scn.sap.com/wiki/display/ABAP/Code+To+Find+BAdi

The following program asks for a transaction code or a program name. If a transaction code is entered, its called program is used as the program name. With the program name, its package is retrieved, and all the Enhancements (Customer Exits) and classic BAdIs of this package are displayed.

It means this program is an help to find some Enhancements (customer exits) and BAdIs in the same package, but maybe they are not related to this transaction or program, and moreover, this transaction or program may call many Enhancements (customer exits) and BAdIs which will not be listed by this program. Instead, prefer Finding a BADI using Buffer trace - Transaction ST05 (Screenshots) or Find a BADI through SPRO.

 REPORT z_find_badi NO STANDARD PAGE HEADING.

*&---------------------------------------------------------------------*
*&  Enter the transaction code or pragram name that you want to search through
*&  in order to find which Standard SAP# User Exits exists or BAdis.
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Tables
*&---------------------------------------------------------------------*

TABLES : tstc, "SAP# Transaction Codes
         tadir,    "Directory of Repository Objects
         modsapt,  "SAP# Enhancements - Short Texts
         modact,   "Modifications
         trdir,    "System table TRDIR
         tfdir,    "Function Module
         enlfdir,  "Additional Attributes for Function Modules
         sxs_attrt,"Exit: Definition side: Attributes, Text table
         tstct.    "Transaction Code Texts

*&---------------------------------------------------------------------*
*& Variables
*&---------------------------------------------------------------------*

DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
DATA : field1(30).
DATA : v_devclass LIKE tadir-devclass.
DATA wa_tadir TYPE tadir.

*&---------------------------------------------------------------------*
*& Selection Screen Parameters
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK s01 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS : p_tcode LIKE tstc-tcode,
             p_pgmna LIKE tstc-pgmna.
SELECTION-SCREEN END OF BLOCK s01.

*&---------------------------------------------------------------------*
*& Start of main program
*&---------------------------------------------------------------------*

START-OF-SELECTION.

* Validate Transaction Code
  IF NOT p_tcode IS INITIAL.
    SELECT SINGLE * FROM tstc WHERE tcode EQ p_tcode.
  ELSEIF NOT p_pgmna IS INITIAL.
    tstc-pgmna = p_pgmna.
  ENDIF.

* Find Repository Objects for transaction code
  IF sy-subrc EQ 0.
    SELECT SINGLE * FROM tadir
          WHERE pgmid = 'R3TR'
            AND object = 'PROG'
            AND obj_name = tstc-pgmna.

    MOVE : tadir-devclass TO v_devclass.

    IF sy-subrc NE 0.
      SELECT SINGLE * FROM trdir
            WHERE name = tstc-pgmna.

      IF trdir-subc EQ 'F'.
        SELECT SINGLE * FROM tfdir
              WHERE pname = tstc-pgmna.

        SELECT SINGLE * FROM enlfdir
              WHERE funcname = tfdir-funcname.

        SELECT SINGLE * FROM tadir
              WHERE pgmid = 'R3TR'
                AND object = 'FUGR'
                AND obj_name EQ enlfdir-area.

        MOVE : tadir-devclass TO v_devclass.
      ENDIF.
    ENDIF.

* Find SAP# Modifications
    SELECT * FROM tadir INTO TABLE jtab
          WHERE pgmid = 'R3TR'
            AND object IN ('SMOD', 'SXSD')
            AND devclass = v_devclass.

    SELECT SINGLE * FROM tstct
          WHERE sprsl EQ sy-langu
            AND tcode EQ p_tcode.

    FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
    WRITE:/(19) 'Transaction Code - ',
          20(20) p_tcode,
          45(50) tstct-ttext.
    SKIP.
    IF NOT jtab[] IS INITIAL.
      WRITE:/(105) sy-uline.
      FORMAT COLOR COL_HEADING INTENSIFIED ON.
* Sorting the internal Table
      SORT jtab BY object.
      DATA : wf_txt(60) TYPE c,
            wf_smod TYPE i ,
            wf_badi TYPE i ,
            wf_object2(30) TYPE c.
      CLEAR : wf_smod, wf_badi , wf_object2.
* Get the total SMOD.
      LOOP AT jtab INTO wa_tadir.
        AT FIRST.
          FORMAT COLOR COL_HEADING INTENSIFIED ON.
          WRITE:/1 sy-vline,
                2 'Enhancement/ Business Add-in',
                41 sy-vline ,
                42 'Description',
                105 sy-vline.
          WRITE:/(105) sy-uline.
        ENDAT.

        CLEAR wf_txt.

        AT NEW object.
          IF wa_tadir-object = 'SMOD'.
            wf_object2 = 'Enhancement' .
          ELSEIF wa_tadir-object = 'SXSD'.
            wf_object2 = ' Business Add-in'.
          ENDIF.
          FORMAT COLOR COL_GROUP INTENSIFIED ON.
          WRITE:/1 sy-vline,
                2 wf_object2,
                105 sy-vline.
        ENDAT.

        CASE wa_tadir-object.
          WHEN 'SMOD'.
            wf_smod = wf_smod + 1.
            SELECT SINGLE modtext INTO wf_txt
                  FROM modsapt
                  WHERE sprsl = sy-langu
                    AND name = wa_tadir-obj_name.

            FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
          WHEN 'SXSD'.
* For BADis
            wf_badi = wf_badi + 1 .
            SELECT SINGLE text INTO wf_txt
                  FROM sxs_attrt
                  WHERE sprsl = sy-langu
                    AND exit_name = wa_tadir-obj_name.

            FORMAT COLOR COL_NORMAL INTENSIFIED ON.
        ENDCASE.
        WRITE:/1 sy-vline,
              2 wa_tadir-obj_name HOTSPOT ON,
              41 sy-vline ,
              42 wf_txt,
              105 sy-vline.

        AT END OF object.
          WRITE : /(105) sy-uline.
        ENDAT.
      ENDLOOP.
      WRITE:/(105) sy-uline.
      SKIP.
      FORMAT COLOR COL_TOTAL INTENSIFIED ON.
      WRITE:/ 'No.of Exits:' , wf_smod.
      WRITE:/ 'No.of BADis:' , wf_badi.
    ELSE.
      FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
      WRITE:/(105) 'No userexits or BADis exist'.
    ENDIF.
  ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(105) 'Transaction does not exist'.
  ENDIF.

* Take the user to SMOD or SXSD for the Exit or BAdi that was selected.
AT LINE-SELECTION.
  DATA : wf_object TYPE tadir-object.
  CLEAR wf_object.
  GET CURSOR FIELD field1.
  CHECK field1(8) EQ 'WA_TADIR'.
  READ TABLE jtab WITH KEY obj_name = sy-lisel+1(20).
  MOVE jtab-object TO wf_object.
  CASE wf_object.
    WHEN 'SMOD'.
      SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
      CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
    WHEN 'SXSD'.
      SET PARAMETER ID 'EXN' FIELD sy-lisel+1(20).
      CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.
  ENDCASE.

*Text elements
*----------------------------------------------------------
* 001 Enter the Transaction Code or Program name that you want to search


*Selection texts
*----------------------------------------------------------
* P_PGMNA         Program name to Search
* P_TCODE         Transaction Code to Search

转载于:https://www.cnblogs.com/hulianfei/p/7059792.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值