• 如何从SAP中查找BADI


    如何从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.

  • 相关阅读:
    洛谷 P1325 雷达安装 解题报告
    洛谷 P2184 贪婪大陆 解题报告
    洛谷 P3942 将军令 解题报告
    洛谷 P3698 [CQOI2017]小Q的棋盘 解题报告
    洛谷 P1436 棋盘分割 解题报告
    C++生成dump文件,调试dump文件
    判断机器大小端的两种实现方法
    判断机器大小端的两种实现方法
    Visual Studio 代码生成 运行时库的选择
    Visual Studio 代码生成 运行时库的选择
  • 原文地址:https://www.cnblogs.com/goodsmith/p/3601065.html
Copyright © 2020-2023  润新知