什么是BADI如何從SAP中查找BADI?_第1頁
什么是BADI如何從SAP中查找BADI?_第2頁
什么是BADI如何從SAP中查找BADI?_第3頁
什么是BADI如何從SAP中查找BADI?_第4頁
什么是BADI如何從SAP中查找BADI?_第5頁
已閱讀5頁,還剩17頁未讀, 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、什么是BADI,如何從SAP中查找BADI?官方說明: Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery. Since specific industries often require special functions, SAP

2、allows you to predefine these points in your software. 我的理解:SAP預定義了一些Interface,客戶可以自己定義實現Interface的Class進行客戶化,在標準程序中會使用調用客戶自定義 Class的Instance,在獲取Instance的過程使用了工廠模式,因此獲取過程對用戶是未知的。不過BADI也有一些局限性,就是有哪些 Interface是固定死的,有的時候會發現需要Mix客戶化代碼的時候找不到Interface,什么時候SAP的OO里面直接支持AOP就好了。如何從SAP中查找BADIBADI作為SAP的第三代用戶出口,

3、他的應用也越來越廣泛,但如何找到合適的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來跟蹤,然后選擇查找有關上述幾個表和視圖的操作,

4、就可獲得相關BADI。 4、se18 查找接口,se19 實現接口就可以實現用戶增強。示例:用LE_SHP_DELIVERY_PROC控制跨月 CancelMETHOD if_ex_le_shp_delivery_procchange_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,thism

5、onth.  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-vbel

6、n.      wa_log-msgty = 'E'. "錯誤訊息      wa_log-msgid = 'ZDN_ERROR'. "這一個class要自己建      wa_log-msgno = '001'.      APPEND wa_log TO ct_log. "Error log寫入  

7、;  ENDIF.  ENDLOOP.ENDMETHOD. "IF_EX_LE_SHP_DELIVERY_PROCCHANGE_DELIVERY_HEADERTCODE:SE18 SE19讀 寫PC機和服務器某路徑下文件到內表的方法最近分別使用了從PC機讀文件到SAP 內表和從SAP服務器讀取文件到內表,記錄一下備忘1、從 pc機讀取文件:FM  GUI_UPLOAD 如下  CALL FUNCTION 'GUI_UPLOAD'    EXPORTING    

8、;  FILENAME                      =  “文件全路徑名     FILETYPE                  &

9、#160;   = 'ASC' ”文件類型     HAS_FIELD_SEPARATOR           = ' X' “分隔方式*     HEADER_LENGTH                

10、= 0*     READ_BY_LINE                  = 'X'*     DAT_MODE                  &

11、#160;   = ' '*     CODEPAGE                      = ' '*     IGNORE_CERR         

12、0;         = ABAP_TRUE*     REPLACEMENT                   = '#'*     CHECK_BOM       &#

13、160;             = ' '*   IMPORTING*     FILELENGTH                    =*     HEADER

14、60;                       =    TABLES      DATA_TAB                

15、60;     =  ”對應內表,字段順序一定要和文件嚴格匹配*   EXCEPTIONS*     FILE_OPEN_ERROR               = 1*     FILE_READ_ERROR        &#

16、160;      = 2*     NO_BATCH                      = 3*     GUI_REFUSE_FILETRANSFER       = 4* &#

17、160;   INVALID_TYPE                  = 5*     NO_AUTHORITY                  = 6*   &#

18、160; UNKNOWN_ERROR                 = 7*     BAD_DATA_FORMAT               = 8*     HEADER_NOT_ALLOWED 

19、60;          = 9*     SEPARATOR_NOT_ALLOWED         = 10*     HEADER_TOO_LONG               = 11* &#

20、160;   UNKNOWN_DP_ERROR              = 12*     ACCESS_DENIED                 = 13*     DP_OUT_OF_MEMORY&#

21、160;             = 14*     DISK_FULL                     = 15*     DP_TIMEOUT    

22、;                = 16*     OTHERS                        = 17     

23、;       .  IF SY-SUBRC <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  ENDIF. 下載文件到PC * 下載導數過程日志文件  CALL FUNCTION 'WS_DOWNLOAD'  

24、EXPORTING*     BIN_FILESIZE                  = ' '*     CODEPAGE                 &

25、#160;    = ' '     FILENAME                      = 文件名     FILETYPE           

26、;           = 文件類型     MODE                          = '1'*     WK1_N_FORMAT&

27、#160;                 = ' '*     WK1_N_SIZE                    = ' '*   &#

28、160; WK1_T_FORMAT                  = ' '*     WK1_T_SIZE                    = ' '*&#

29、160;    COL_SELECT                    = ' '*     COL_SELECTMASK                = '

30、'*     NO_AUTH_CHECK                 = ' '*   IMPORTING*     FILELENGTH              

31、60;     =    TABLES      DATA_TAB                      = 內表*     FIELDNAMES      

32、0;             =   EXCEPTIONS     FILE_OPEN_ERROR               = 1     FILE_WRITE_ERROR     &#

33、160;        = 2*     INVALID_FILESIZE              = 3*     INVALID_TYPE              

34、0;   = 4*     NO_BATCH                      = 5*     UNKNOWN_ERROR             &

35、#160;   = 6*     INVALID_TABLE_WIDTH           = 7*     GUI_REFUSE_FILETRANSFER       = 8*     CUSTOMER_ERROR       

36、;         = 9*     NO_AUTHORITY                  = 10*     OTHERS           

37、0;            = 11            .  IF SY-SUBRC <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*         WITH SY-MSGV1 SY-MSGV2 SY-MS

38、GV3 SY-MSGV4.  ENDIF.2、操作服務器路徑下 的文件,使用open dataset的方式parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt',            d2 type localfile default '/usr/sap/TST/SYS/Data2.txt'.data: begin of itab occurs 0, &#

39、160;    rec(20) type c,      end of itab.data: wa(20) type c.start-of-selection.* open and read file 1 into an internal table  open dataset d1 for input in text mode.  if sy-subrc = 0.    do.      read dataset

40、d1 into wa.“讀取文件的一行,如果是多字段還需要分隔,      if sy-subrc  0.        exit.      endif.      itab-rec = wa.      append itab.    enddo.  endif. 

41、 close dataset d1.* Open file 2 and copy the contents to this file  open dataset d2 for output in text mode.  loop at itab.    transfer itab to d2.”寫文件  endloop.  close dataset d2.* Delete file 1  delete dataset d1.以下是從網上直接 的資料:1.TH_SELECT_SERVER這個函數的作用是獲取服務器名

42、稱(F4功能)。2.F4_DXFILENAME_4_DYNP這 個函數作用是獲取文件明名稱(F4功能),但前提是已知服務器名稱。3.DX_FILE_EXISTENCE_CHECK這個函數的作用 是檢查該文件是否存在。總體下來基本的功能已經實現,但是最大的一點就是必須要有服務器的名稱,因為2和3都是需要這項參數的。而如果不想涉及到 服務器的名字可以用下面的方法。二。1./SAPDMC/LSM_F4_SERVER_FILE這個函數作用是獲取文件明名稱(F4功 能),但不需要服務器名稱。2.SCMS_FILE_CHECK_EXISTENCE這個函數的作用是檢查該文件是否存在。以上 兩種方式對比而言,

43、第一種應用更為廣泛,不單單針對服務器上的文件,對本地文件也是支持的。另外一點,服務器文件有兩種類型,論理文件(類型為L)和物理 文件(類型為P),第一種方式對兩種文件都支持,第二種只對應物理文件。 什么是BADI,如何從SAP中查找BADI?SAP預定義了一些Interface,客戶可以自己定義實現 Interface的Class進行客戶化,在標準程序中會使用調用客戶自定義Class的Instance,在獲取Instance的過程使用了工廠模 式,因此獲取過程對用戶是未知的。不過BADI也有一些局限性,就是有哪些Interface是固定死的,有的時候會發現需要Mix客戶化代碼的時候找不 到In

44、terface,什么時候SAP的 OO里面直接支持AOP就好了。愛ERP網    www.LoveE如何從SAP中 查找BADIBADI作為SAP的 第三代用戶出口,他的應用也越來越廣泛,但如何找到合適的badi是許多abap程序員的困惑。我這里就介紹一下我個人的應用的經驗,供大家參考。1、badi對象的信息存儲在SXS_INTER, SXC_EXIT, SXC_CLASS 和SXC_ATTR 這四個表中(參見SECE包);2、sap程序都會調用cl_exithandler=>get_instance來判斷對象是否存在,并返回實例;其實 get_instan

45、ce就是對上述幾個表和他們的視圖(V_EXT_IMP 和 V_EXT_ACT)進行查詢和搜索。3、基于這個機理,我查用ST05來監控一個TCODE來跟蹤,然后選擇查找有關上述幾個表和視圖的操作,就可獲得相關BADI。 4、se18 查找接口,se19 實現接口就可以實現用戶增強。示例:用LE_SHP_DELIVERY_PROC控制跨月 CancelMETHOD if_ex_le_shp_delivery_procchange_delivery_header .  DATA : thismonth(2) TYPE c.  DATA : wa_likp TYPE LI

46、NE 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

47、 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 = &

48、#39;001'.      APPEND wa_log TO ct_log. "Error log寫入    ENDIF.  ENDLOOP.ENDMETHOD. "IF_EX_LE_SHP_DELIVERY_PROCCHANGE_DELIVERY_HEADERTCODE:SE18SE19BADI Business Add Ins are enhancements to the standard version of the code of SAP. They can be

49、inserted into the SAP system to accommodate user requirements too specific to be included in the standard delivery. Customers can find the possible enhancements (BADIs) in their SAP system in the Implementation Guide (IMG) and in the component hierarchy. BADI definitions are included in the IMG so t

50、hat the customer can create suitable, company-specific implementations. SAP guarantees the upward compatibility of all Business Add-In interfaces. Release upgrades do not affect enhancement calls from within the standard software nor do they affect the validity of call interfaces.Two different views

51、 are available: · In the definition view, an application programmer defines exit points in a source that allow specific industry sectors, partners, and customers to attach additional coding to standard SAP source code without having to modify the original object.· In the implementatio

52、n view, the users of Business Add-Ins can customize the logic they need or use a standard solution if one is available.Definition of A BAdI SAP application developer actually defines a Business Add-In available to an application program. Tcode SE18 can also be used to see the definition of exis

53、ting badi .The following are the steps in defining a BADI:1. Using the SAP BADI builder, the SAP application developer defines an enhancement (BADI). It consists of an interface with a method.2. The interface name is generated automatically and can be changed. The system branches to the Class Builde

54、r.3. Using the Class Builder, the developer assigns a method to the interface.4. For each method, he defines parameters. Parameters can either be importing or changing and these are the fields available for customer to use for enhancements. Importing parameters are the fields being passed from the c

55、alling program and changing parameters are the fields being passed back to the program.5. The Business Add-In is then activated in the Class Builder.Note: Documentation of the BADI usually provides the list of parameters and their definition. For example, for method DETERMINE_EXTPO, the available pa

56、rameters are:Importingo ITEM_DATA Item data (is a structure)Changingo BBP_EXTPO_GLo If the field has the value X, the request is subject to the extended classic scenario.o If the field is empty, the request is not subject to the extended classic scenario.Implementation of a BAdIIf a customer wishes

57、to use a Business Add-In, he or she first creates an implementation. The customer must implement the methods and the enhancements. You need to program the interface method in such a way that, when the add-in is called from the application program, it will perform the specific action the customer int

58、ends. The following are the steps customer can follow in implementing a BADI:1. In the SAP menu, choose ABAP Workbench ® Utilities ® Business Add-Ins (transaction SE19) or double-click the corresponding activity in the Implementation Guide (IMG).2. Enter a name for the implementation and t

59、hen click the Create pushbutton.3. Enter the name of the add-in for which you want to create an implementation for in the dialog box that appears. Choose the Interface tab.4. Choose ABAP Code as the implementation type.5. Navigate to the Class Builder by double-clicking the method. You must first en

60、ter a package before the Class Builder is displayed.6. Insert the desired source code for the implementation between the method if_ex_businessaddinmethod. and endmethod (statements that already exist) You need to use the parameters (importing and changing) as fields within the BADI. You can define a

61、dditional fields you need in the coding as local data fields.7. Save your entries and return to the Change Implementation screen.8. Choose Activate. The enhancements active components are then called at runtime.EXAMPLE (code)Definition name BBP_EXTLOCALPO_BADIImplementation Name ZEXTENDEDCLASSICInte

62、rface name IF_EX_BBP_EXTLOCALPO_BADIName of implementing class: ZCL_IM_EXTENDEDCLASSICMethod DETERMINE_EXTPOABAP Code Determination of Control for Extended METHOD IF_EX_BBP_EXTLOCALPO_BADIDETERMINE_EXTPO.DATA: zzecs type zecs. * local data field*extended classic will be activated only for speci

63、fic product categoriesIF item_data-category eq '420DD2C2CFDF56478E705E352FEC86CB'.bbp_extpo_gl-bbpexpo = 'X'.ELSE.SELECT single * from zecs into zzecs where product eq item_data-product.IF sy-subrc eq 0.bbp_extpo_gl-bbpexpo = 'X'.ENDIF.ENDIF.ENDMETHOD. Filter-Ddependent&

64、#160;BAdIBusiness Add-Ins may also be implemented on the basis of a filter value. The application program provides the filter value for the enhancement method. The filter parameter is defined within the method when creating the interface. For each method created in the interface of a filter-dependen

65、t enhancement, the filter value must be defined as the importing parameter so that the application program can provide the filter value to the enhancement method. The method then selects the active implementation for that value. The filter value is always declared using the parameter flt_val and is

66、predefined in the list of parametersFor example:You can use the Business Add-Ins BBP_DOC_CHANGE_BADI to make changes to the document, after user entry and before saving the document to the database. These changes are subject to the document-specific checks. The parameter FLT_VAL acts as a filter val

67、ue that assigns the BAdI implementation to a particular document type. You can use the BAdI to change some of these documents:o Shopping cart (filter value BUS2121 shopping cart EC)o Purchase order (filter value BUS2201 purchase order EC)o Confirmation (filter value BUS2203 confirmation of goods/ser

68、vices EC)o Invoice (filter value BUS2205 incoming invoice EC)o Bid invitation (filter value BUS2200 bid invitation EC) Calling A BAdI in The Applicat?on ProgramWhen a Business Add-In is created, enhancement management generates a class that implements the interface. The application developer us

69、es a factory method to create an instance of this adapter class in the application program and calls the corresponding method, if necessary.The adapter class method generated by add-in management decides whether one or several active implementations should be called. If necessary, these implementati

70、ons are subsequently executed. The application program ensures only that the adapter class method is called. The application program does not know which implementations are called.Step by Step之MIGO BAdI應用1T-code: SE19,創建ZKEVIN_MIGO Implementation2SE80 建立Program ZKEVINMIGO。同時可以根據提示建立ZKTOP3在ZKTOP中建立自定

71、義字段*&-*& Include ZKTOP                                            &

72、#160;Module Pool      ZKEVINMIGO*&*&-*PROGRAM  ZKEVINMIGO.DATA ZKEIVN(10) TYPE C. 4在ZKEVINMIGO中建立子屏幕1111,并繪制相關的LAYOUT 5用SE19進入之前建立的ZKEVIN_MIGO中, 在其PBO_DETAIL中鍵入如下代碼,并激活。同時激活BAdI  E_CPROG = 'ZKEVINMI

73、GO'.  E_DYNNR = '1111'.  E_HEADING = 'kevin sub'.現在我們能通過MIGO的看到那個子屏幕了,不過現在還沒做任何的數據處理 6.至于下面的問題就是數據如何傳入與輸出。發現自己寫的sample還是太簡單了,SAP系統自帶了一個 sample,寫得比較完整。用SE19中Goto->Sample code->Display/Copy如果要看文檔,用Definition Documenta。SAP的例子還是

74、比較完整,寫得也比較規范,可以把它拷出來,然后再進行修改。如何定義(Definition)并應用 (Implementation)SAP BADI1, T-CODE:SE18,進入如下界面,選中 Enhancement Spot 并輸入所決定的名稱. 2, 點擊上圖中的 Create 按鈕進入下一屏.在下面這個屏幕中輸入Short Text,然后選擇綠勾按鈕. 3,在上一屏,選擇綠勾按鈕后,出現下面這個屏 幕,輸入合適的package,可以使用本地對象這個package,然后點左下角的保存按鈕. 4,在上一屏保存之后出現下面的界面.選擇 Enh. Spot Element Definitions 這個頁簽(這個是進入后的默認頁簽),點擊該頁簽左上角的 Create BAdI 按鈕,進入下一屏. 5,在如下屏幕中輸入 BAdI Definition的na

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論