如何從SAP中查找BADI


如何從SAP中查找BADI

http://blog.csdn.net/CompassButton/article/details/1231652

BADI作為SAP的第三代用戶出口,他的應用也越來越廣泛,但如何找到合適的badi是許多abap程序員的困惑。我這里就介紹一下我個人的應用的經驗,供大家參考。

1、badi對象的信息存儲在SXS_INTER, SXC_EXIT, SXC_CLASS 和SXC_ATTR 這四個表中(參見SECE包);

2、sap程序都會調用cl_exithandler=>get_instance來判斷對象是否存在,並返回實例;其實get_instance就是對上述幾個表和他們的視圖(V_EXT_IMP 和 V_EXT_ACT)進行查詢和搜索。

3、基於這個機理,我查用ST05來監控一個TCODE來跟蹤,然后選擇查找有關上述幾個表和視圖的操作,就可獲得相關BADI。

 4、se18 查找接口,se19 實現接口就可以實現用戶增強。
示例:用LE_SHP_DELIVERY_PROC控制跨月Cancel

METHOD IF_EX_LE_SHP_DELIVERY_PROC~CHANGE_DELIVERY_HEADER .
data : thismonth(2) type c.
data : wa_likp type line of SHP_LIKP_T.
data : wa_log type line of SHP_BADI_ERROR_LOG_T.
clear ct_log[],thismonth.
thismonth = sy-datum+4(2). "----->這一個月的月份
loop at it_xlikp into wa_likp.
check IS_V50AGL-WARENAUSG_STORNO ='X'."--->代表作GI cancel
if wa_likp-WADAT_IST+4(2) < thismonth.
wa_log-VBELN = cs_likp-vbeln.
wa_log-MSGTY = 'E'. "錯誤訊息
wa_log-MSGID = 'ZDN_ERROR'. "這一個class要自己建
wa_log-MSGNO = '001'.
append wa_log to ct_log. "Error log寫入
endif.
endloop.
ENDMETHOD.

5、補充7.00版后badi的幾個處理變化

  • 以前的CL_EXITHANDLER=>GET_PROG_AND_DYNP_FOR_SUBSCR被CL_ENH_BADI_RUNTIME_FUNCTIONS=>GET_PROG_AND_DYNP_FOR_SUBSCR 代替.
  • 以前的 PUT_DATA_TO_SCREEN和GET_DATA_FROM_SCREEN不在需要。用戶可以創建自己的數據傳輸函數,通過CALL BADI來調用.
  •   用戶也不需要調用CL_EXITHANDLER=>SET_INSTANCE_FOR_SUBSCREENS 和 CL_EXITHANDLER=>GET_INSTANCE_FOR_SUBSCREENS函數. These methods are now unnecessary as they only place the BAdI reference in a temporary storage.
    SET_INSTANCE_FOR_SUBSCREENS is no longer necessary.
    GET_INSTANCE_FOR_SUBSCREENS can, if necessary, be replaced by GET BADI.

相關連接
http://blog.csdn.net/CompassButton/archive/2006/09/16/1230344.aspx
http://blog.csdn.net/CompassButton/archive/2006/09/16/1230614.aspx
http://blog.csdn.net/compassbutton/archive/2006/08/07/1032686.aspx
http://blog.csdn.net/compassbutton/archive/2006/08/07/1032510.aspx

 

 

http://www.cnblogs.com/wolly/archive/2010/10/08/1845886.html

方法一:

             1. Go to the TCode SE24 and enter CL_EXITHANDLER as object type.

2. In 'Display' mode, go to 'Methods' tab.

3. Double click the method 'Get Instance' to display it source code.

4. Set a breakpoint on 'CALL METHOD cl_exithandler=>get_class_name_by_interface'.

5. Then run your transaction.

6. The screen will stop at this method.

7. Check the value of parameter 'EXIT_NAME'. It will show you the BADI for that transaction.
if found helpfull do reward.

方法二:BADI作為SAP的第三代用戶出口,他的應用也越來越廣泛,但如何找到合適的badi是許多abap程序員的困惑。我這里就介紹一下我個人的應用的經驗,供大家參考。

1、badi對象的信息存儲在SXS_INTER, SXC_EXIT, SXC_CLASS 和SXC_ATTR 這四個表中(參見SECE包);

2、sap程序都會調用cl_exithandler=>get_instance來判斷對象是否存在,並返回實例;其實get_instance就是對上述幾個表和他們的視圖(V_EXT_IMP 和 V_EXT_ACT)進行查詢和搜索。 ------個人感覺SAP操作BADI_SPOT的時候會有BADI出現

3、基於這個機理,我查用ST05來監控一個TCODE來跟蹤,然后選擇查找有關上述幾個表和視圖的操作,就可獲得相關BADI。

方法三:在TCODE的原代碼里面查找cl_exithandler=>get_instance中的EXPORTING exit_name 后的值就是。

 

對於根據事務代碼查找對應的BADI,網上介紹的方法很多,但總結下來無非就兩種方法,在此把它記錄下來,方便以后自己查閱了。
(1)通過SE24,輸入CL_EXITHANDLER,然后在方法GET_INSTANCE中設置斷點,然后運行事務代碼判斷 exit_name的值,操作過程如下:
輸入se24,然后輸入cl_exithandler


進去雙擊get_instance設置斷點查看exit_name的值:



(2)通過st05跟蹤,badi對應的數據表為 SXS_INTER, SXC_EXIT, SXC_CLASS 和 SXC_ATTR,而這些表都是通過視圖V_EXT_IMP 和 V_EXT_ACT來查詢的。

     1、打開運行事務碼: ST05 選擇“table buffer trace”而不是常用的"SQL trace"

     2、activate trace(開始跟蹤)

     3、運行事務碼:me21n

     4、創建一個采購訂單,保存

     5、deactivate trace(結束跟蹤)

     6、點擊display trace,在出來的選擇條件中: objects中輸入:V_EXT_IMP和V_EXT_ACT;在 operations中輸入“OPEN”

     7、查詢

通過查詢的結果可以看出,視圖V_EXT_IMP的BADI的接口類名字都是以IF_EX_開頭的,其中IF_EX_之后的就是對應BADI接口的定義。

 

 

 

在SAP系統中,SAP提供了Badi和用戶出口來方便用戶對標准程序來進行增強,那么我們可以通過如下方法來找到它們:

獲取用戶出口:

方法一:用SAP提供的一個程序來執行獲取,這個程序不是已經內嵌到系統中,需要下載代碼,放到自定義的程序中來執行,

代碼下載地址:http://www.sap-img.com/ab038.htm 或者:http://saptechnical.com/Tutorials/ExitsBADIs/FindUserExitswithTCode.htm

方法二:Tcode:SMOD,進去后,寫星號,按F4,調用搜索幫助,調出所有清單,從清單中搜索得到‘user exit’的項目;

獲取BADI(以下從SDN轉帖):

方法一:Goto Transaction SE24->class name as CL_EXITHANDLER->
Display->double click on get_instance mathod->Now u will go inside the method->Now put break point on the cl_exithandler.
Now enter transaction code .
U will be stopped on the break point at cl_exithandler .In the exit name u can find list of badi's attached to the tcode..
Find the sutable BADI according to your requirement
方法二: Go to any transaction (say CV02N) and from the menu, select System ->Status to get the program name.
In the program, search for CL_EXITHANDLER=>GET_INSTANCE with the radio button “In Main Program” selected.
Select one program from the list of programs containing calls to BAdIs.
The changing parameter INSTANCE will have the interface assigned to it.
Find out the corresponding BAdI Interface and definition
For eg: if the inteface name is IF_EX_DOCUMENT_MAIN02 is the interface , the BAdI definition name will be DOCUMENT_MAIN02.

 

 

查找BADi的六種方法

 http://scnblogs.techweb.com.cn/sariel/archives/76.html

1.SE37查看SXV_GET_CLIF_BY_NAME,設置斷點,運行事務,DEBUG查看NAME的值。
2.SE24查看CL_EXITHANDLER類的GET_INSTANCE方法,在 “CALL METHOD  cl_exithandler=>get_class_name_by_interface”設置斷點,運行事務,DEBUG查看EXIT_NAME的值。
3.SPRO查看Business Add-Ins for xxxx子項。
4.SE80》Repository Browser》Package》[開發類名]》Enhancements 》Classic BAdIs (Def.)
5.查找事務碼的程序代碼,cl_exithandler=>get_instance的EXPORTING參數exit_name。
6.ST05跟蹤事務碼,顯示Trace后查找“V_EXT_IMP”和“V_EXT_ACT”;查找以“IF_EX_”開頭的字符串,該字符串為接口名,“IF_EX_”后即為BADi名。

 

 

Finding the user-exits of a SAP transaction code

*http://www.erpgreat.com/ab038.htm
* Finding the user-exits of a SAP transaction code
*
* Enter the transaction code in which you are looking for the user-exit
* and it will list you the list of user-exits in the transaction code.
* Also a drill down is possible which will help you to branch to SMOD.
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*              http://www.erpgreat.com
*

report zuserexit no standard page heading.
tables : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir.
         tables : tstct.
data : jtab like tadir occurs 0 with header line.
data : field1(30).
data : v_devclass like tadir-devclass.
parameters : p_tcode like tstc-tcode obligatory.

select single * from tstc where tcode eq p_tcode.
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.
       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.
                    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.
        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.

at line-selection.
   get cursor field field1.
   check field1(4) eq 'JTAB'.
   set parameter id 'MON' field sy-lisel+1(10).
   call transaction 'SMOD' and skip first   screen.

*---End of Program



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 .
TABLES : TSTC, TADIR, MODSAPT, MODACT, TRDIR, TFDIR, ENLFDIR, SXS_ATTRT, TSTCT.
DATA : JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE.
DATA : FIELD1(30).
DATA : V_DEVCLASS LIKE TADIR-DEVCLASS.
DATA WA_TADIR TYPE TADIR.
 
PARAMETERS : P_TCODE LIKE TSTC-TCODE,
P_PGMNA LIKE TSTC-PGMNA .
 
START-OF-SELECTION.
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.
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.
  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.
 
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.




[轉帖]SAP BADI應用

http://space.itpub.net/10500555/viewspace-616097

上一篇 / 下一篇  2009-10-08 10:40:34 / 個人分類:SAP學習

1.定義BADI
         1) T-Code:  SE18     Business Add-In Define.

   2) 輸入要創建的BADI的名字,點擊"Create"。

   3) 輸入BADI的描述性文本,在"Interface"選項卡上輸入接口的名字,也可以采用SAP建議的接口的名字。同時,BADI類也        會被創建。

     例如:對於BADI "ZTEST",SAP會建議"ZIF_EX_TEST"作為接口的名字,"ZCL_EX_TEST"作為類的名字。

   4) 保存BADI。

   5) 雙擊接口的名字,會跳轉到Class Builder界面,在這里你可以定義接口的方法。

   6) 保存並激活接口。

2.實現BADI
         1) T-Code:  SE19     Business Add-In Implementation
         2) 輸入BADI實現的名字,點擊"Create"。
         3) 輸入BADI定義的名字。
         4) 輸入實現的描述性文本,在"Interface"選項卡上輸入實現類的名字。可以采用SAP建議的名字。

    例如:"ZIMPTEST",SAP會建議"ZCL_IM_IMPTEST"。

   5) 保存實現。

   6) 雙擊某一方法名會跳轉到Class Builder界面,在這里你可以添加代碼來重定義接口方法。

   7) 激活實現。

3. 程序中調用BADI

1) 先用類型參照引用出要調用的BADI
      2) 實例化BADI
      3) 實例化后就可以任意調用BADI 中的方法了。

REPORT  ZZW_BAPI_01                                                 .

data exit type ref to ZIF_EX_ZW_BD_TEST.

call method cl_exithandler=>get_instance
     changing
        instance = exit.

call method exit->Z_ZW_01.

==》
badi 小記
BADI作為SAP的第三代用戶出口,他的應用也越來越廣泛,但如何找到合適的badi是許多abap程序員的困惑。我這里就介紹一下我個人的應用的經驗,供大家參考。

1、badi對象的信息存儲在SXS_INTER, SXC_EXIT, SXC_CLASS 和SXC_ATTR 這四個表中(參見SECE包);

2、sap程序都會調用cl_exithandler=>get_instance來判斷對象是否存在,並返回實例;其實get_instance就是對上述幾個表和他們的視圖(V_EXT_IMP 和 V_EXT_ACT)進行查詢和搜索。

3、基於這個機理,我查用ST05來監控一個TCODE來跟蹤,然后選擇查找有關上述幾個表和視圖的操作,就可獲得相關BADI。

4、se18 查找接口,se19 實現接口就可以實現用戶增強。
示例:用LE_SHP_DELIVERY_PROC控制跨月Cancel

METHOD IF_EX_LE_SHP_DELIVERY_PROC~CHANGE_DELIVERY_HEADER .
data : thismonth(2) type c.
data : wa_likp type line of SHP_LIKP_T.
data : wa_log type line of SHP_BADI_ERROR_LOG_T.
clear ct_log[],thismonth.
thismonth = sy-datum+4(2). "----->這一個月的月份
loop at it_xlikp into wa_likp.
check IS_V50AGL-WARENAUSG_STORNO ='X'."--->代表作GI cancel
if wa_likp-WADAT_IST+4(2) < thismonth.
wa_log-VBELN = cs_likp-vbeln.
wa_log-MSGTY = 'E'. "錯誤信息
wa_log-MSGID = 'ZDN_ERROR'. "這一個class要自己建
wa_log-MSGNO = '001'.
append wa_log to ct_log. "Error log寫入
endif.
endloop.
ENDMETHOD.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM