通过Tcode查找Badi或者客户出口
阅读原文时间:2023年07月15日阅读:1

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

Created by Naresh Reddy K, last modified by Smruti Ranjan Mohanty

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 WITH HEADER LINE.
DATA : field1().
DATA : v_devclass LIKE tadir-devclass.
DATA wa_tadir TYPE tadir.

*&---------------------------------------------------------------------*
*& Selection Screen Parameters
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK s01 WITH FRAME TITLE text-.
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 .
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 .  
  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:/() 'Transaction Code - ',  
      () p\_tcode,  
      () tstct-ttext.  
SKIP.  
IF NOT jtab\[\] IS INITIAL.  
  WRITE:/() sy-uline.  
  FORMAT COLOR COL\_HEADING INTENSIFIED ON.  

* Sorting the internal Table
SORT jtab BY object.
DATA : wf_txt() TYPE c,
wf_smod TYPE i ,
wf_badi TYPE i ,
wf_object2() 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:/ sy-vline,
'Enhancement/ Business Add-in',
sy-vline ,
'Description',
sy-vline.
WRITE:/() 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:/ sy-vline,  
             wf\_object2,  
             sy-vline.  
    ENDAT.

    CASE wa\_tadir-object.  
      WHEN 'SMOD'.  
        wf\_smod = wf\_smod + .  
        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 + .
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:/ sy-vline,  
           wa\_tadir-obj\_name HOTSPOT ON,  
           sy-vline ,  
           wf\_txt,  
           sy-vline.

    AT END OF object.  
      WRITE : /() sy-uline.  
    ENDAT.  
  ENDLOOP.  
  WRITE:/() 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:/() 'No userexits or BADis exist'.  
ENDIF.  

ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/() '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() EQ 'WA_TADIR'.
READ TABLE jtab WITH KEY obj_name = sy-lisel+().
MOVE jtab-object TO wf_object.
CASE wf_object.
WHEN 'SMOD'.
SET PARAMETER ID 'MON' FIELD sy-lisel+().
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
WHEN 'SXSD'.
SET PARAMETER ID 'EXN' FIELD sy-lisel+().
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

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章