Wednesday, March 18, 2009

Program to find BADI's and User-exits of a Transaction Code

*&---------------------------------------------------------------------*
*& Report ZDEMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZDEMO NO STANDARD PAGE HEADING.
*& Enter the transaction code that you want to search through in order *
*& to find which Standard SAP User Exits exists. *
*& *
*&---------------------------------------------------------------------\*
*&---------------------------------------------------------------------\*
*& 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
TSTCT, "Transaction Code Texts
RSSTCD,
TRKEY.
*&---------------------------------------------------------------------\*
*& Definition of Types *
*&---------------------------------------------------------------------\*
TYPES: BEGIN OF T_BADI_LIST,
OBJ_NAME TYPE SOBJ_NAME ,
DEVCLASS TYPE DEVI_CLASS ,
DLVUNIT TYPE DLVUNIT,
IMP_NAME TYPE EXIT_IMP ,
PACKNAME TYPE DEVCLASS ,
DLVUNIT2 TYPE DLVUNIT,
TEXT TYPE SXC_ATTRT-TEXT,
END OF T_BADI_LIST.
TYPES: BEGIN OF T_BADI_LIST2,
OBJ_NAME TYPE SOBJ_NAME ,
DEVCLASS TYPE DEVI_CLASS ,
DLVUNIT TYPE DLVUNIT,
END OF T_BADI_LIST2.
*&---------------------------------------------------------------------\*
*& Data Declaration *
*&---------------------------------------------------------------------\*
DATA: LT_BADI_LIST TYPE TABLE OF T_BADI_LIST,
LT_BADI_LIST2 TYPE TABLE OF T_BADI_LIST2,
LS_BADI_LIST TYPE T_BADI_LIST OCCURS 0 WITH HEADER LINE,
LS_BADI_LIST2 TYPE T_BADI_LIST2.
RANGES: R_BADI FOR TADIR-OBJ_NAME ,
RT_BADI FOR TADIR-OBJ_NAME .
*&---------------------------------------------------------------------\*
*& Variables *
*&---------------------------------------------------------------------\*
DATA : JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE,
P_TRKEY LIKE TRKEY.
DATA : FIELD1(30),
BADINAME(20),
COUNT TYPE P.
DATA : V_DEVCLASS LIKE TADIR-DEVCLASS,
P_DEVCLASS LIKE TADIR-DEVCLASS,
P_OLD_LANGU LIKE SY-LANGU,
P_MOD_LANGU LIKE SY-LANGU.
*&---------------------------------------------------------------------\*
*& Selection Screen Parameters *
*&---------------------------------------------------------------------\*
SELECTION-SCREEN BEGIN OF BLOCK A01 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN SKIP.
PARAMETERS : P_TCODE LIKE TSTC-TCODE OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK A01.
*&---------------------------------------------------------------------\*
*& Start of report *
*&---------------------------------------------------------------------\*
START-OF-SELECTION.
* Validate Transaction Code
SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE.
*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.
* This section is used if a FGR is involved\!
CALL FUNCTION 'RS_ACCESS_PERMISSION'
EXPORTING
GLOBAL_LOCK = 'X'
OBJECT = P_TCODE
OBJECT_CLASS = 'TRAN'
MODE = 'SHOW'
LANGUAGE_UPD_EXIT = 'RS_TRANSACTION_LANGUAGE_EXIT'
SUPPRESS_LANGUAGE_CHECK = SPACE
IMPORTING
NEW_MASTER_LANGUAGE = P_OLD_LANGU
MODIFICATION_LANGUAGE = P_MOD_LANGU
TRANSPORT_KEY = P_TRKEY
DEVCLASS = P_DEVCLASS
EXCEPTIONS
CANCELED_IN_CORR = 1
OTHERS = 2.
IF SY-SUBRC = 0. " Success
MOVE: P_DEVCLASS TO V_DEVCLASS.
ELSE. " For the case that nothing is found\!
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 = P_DEVCLASS.
MOVE: TADIR-DEVCLASS TO V_DEVCLASS.
ENDIF.
ENDIF.
ENDIF.
*Find SAP Modifactions
SELECT * FROM TADIR INTO TABLE JTAB
WHERE PGMID = 'R3TR'
AND OBJECT = 'SMOD'
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.
FORMAT COLOR COL_POSITIVE INTENSIFIED ON.
SKIP.
WRITE:/1 'The application area is:', V_DEVCLASS.
SKIP.
IF NOT JTAB[] IS INITIAL.
WRITE:/(95) SY-ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 SY-VLINE, 2 'Exit Name', 21 SY-VLINE, 22 'Description', 95 SY-VLINE.
WRITE:/(95) SY-ULINE.
LOOP AT JTAB.
SELECT SINGLE * FROM MODSAPT
WHERE SPRSL = SY-LANGU
AND NAME = JTAB-OBJ_NAME.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/1 SY-VLINE, 2 JTAB-OBJ_NAME HOTSPOT ON, 21 SY-VLINE , 22 MODSAPT-MODTEXT,
95 SY-VLINE.
ENDLOOP.
WRITE:/(95) SY-ULINE.
DESCRIBE TABLE JTAB.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , SY-TFILL.
SKIP.
WRITE:/(83) SY-ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 SY-VLINE, 2 'Badi Name', 22 SY-VLINE, 23 'Description', 83 SY-VLINE.
WRITE:/(83) SY-ULINE.
* select the BAdI Definitions from the tables sxc_exit and sxc_attr
SELECT T~OBJ_NAME T~DEVCLASS TC~DLVUNIT SX~IMP_NAME SAT~TEXT
INTO CORRESPONDING FIELDS OF TABLE LT_BADI_LIST
FROM ( ( ( ( TADIR AS T
INNER JOIN
TDEVC AS TC ON T~DEVCLASS = TC~DEVCLASS )
INNER JOIN
SXC_EXIT AS SX ON SX~EXIT_NAME = T~OBJ_NAME )
INNER JOIN
SXC_ATTR AS SA ON SX~IMP_NAME = SA~IMP_NAME )
INNER JOIN
SXC_ATTRT AS SAT ON SX~IMP_NAME = SAT~IMP_NAME )
WHERE T~PGMID = 'R3TR'
AND T~OBJECT = 'SXSD' "means BAdI
AND T~DEVCLASS = V_DEVCLASS "narrow down seach with Dev.Class
AND SAT~SPRSL = SY-LANGU.
SORT LT_BADI_LIST.
DELETE ADJACENT DUPLICATES FROM LT_BADI_LIST.
* create Ranges
LOOP AT LT_BADI_LIST INTO LS_BADI_LIST .
R_BADI-SIGN = 'I' .
R_BADI-OPTION ='EQ' .
R_BADI-LOW = LS_BADI_LIST-IMP_NAME .
R_BADI-HIGH = LS_BADI_LIST-IMP_NAME .
APPEND R_BADI TO RT_BADI .
ENDLOOP.
* select the implementations
SELECT T~OBJ_NAME T~DEVCLASS TC~DLVUNIT
INTO CORRESPONDING FIELDS OF TABLE LT_BADI_LIST2
FROM TADIR AS T
INNER JOIN
TDEVC AS TC ON T~DEVCLASS = TC~DEVCLASS
FOR ALL ENTRIES IN RT_BADI
WHERE T~OBJ_NAME = RT_BADI-LOW
AND T~PGMID = 'R3TR'
AND T~OBJECT = 'SXCI'.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/(83) SY-ULINE.
COUNT = '0'.
LOOP AT LT_BADI_LIST INTO LS_BADI_LIST .
WRITE:/1 SY-VLINE, 2 LS_BADI_LIST-OBJ_NAME HOTSPOT ON, 22 SY-VLINE,
23 LS_BADI_LIST-TEXT, 83 SY-VLINE.
COUNT = COUNT + 1.
ENDLOOP.
WRITE:/(83) SY-ULINE.
DESCRIBE TABLE LS_BADI_LIST.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of BADIs:' , COUNT.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'No User Exit exists'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'Transaction Code Does Not Exist'.
ENDIF.
*&---------------------------------------------------------------------\*
*& Call SMOD or SE18 to lead the user to the selected exit or badi *
*&---------------------------------------------------------------------\*
AT LINE-SELECTION.
GET CURSOR FIELD FIELD1.
IF FIELD1(4) EQ 'JTAB'.
SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
ELSEIF FIELD1(12) EQ 'LS_BADI_LIST'.
CALL FUNCTION 'SXO_BADI_SHOW'
EXPORTING
EXIT_NAME = SY-LISEL+1(20)
EXCEPTIONS
ACTION_CANCELED
ACCESS_FAILURE
BADI_NOT_EXIXTING.
ELSE.
ENDIF.

1 comment:

Anonymous said...

Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.