版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、BAPI Step by Step ExampleAbout the exampleThis BAPI reads system status for a production order from table JEST and system status text from table TJ02T 此BAPI是從JEST讀取生產(chǎn)訂單系統(tǒng)狀態(tài)和從表TJ02T中讀取文本狀態(tài)Name ZGetOrderStatus (bapi名稱)Function group ZBAPISTATUS (功能組)Function module: Z_BAPI_GET_ORDER_STATUS (功能模
2、塊)Import parameters: ORDER_STATUS_IMPORT type ZBAPI_ORDER_STATUS_IMPORT: 定義左邊變量類型為右· AUFNR Order number (Keyfield) · SPRAS Language · ExcludeInactive - Checkbox - Exclude inactive status Tables T_BAPISTAT type ZBAPISTAT: · OBJNR like JEST-OBJNR · STAT like JEST-STAT · I
3、NACT like JEST-INACT · TXT04 like TJ02T-TXT04 · TXT30 likeTJ02T-TXT30 Export parameters RETURN like BAPIRETURN Step1:定義BAPI用到的結構體 在此步驟里,BAPI中用到功能模塊的表和參數(shù)均已在這里定義使用數(shù)據(jù)類型-結構定義以下結構:結構1:ZBAPI_ORDER_STATUS_IMPORT包含以下字段· ORDERID Order number (Keyfield) 訂單號· SPRAS Language 語言&
4、#183; ExcludeInactive - Checkbox - Exclude inactive status 結構2:ZBAPISTAT: OBJNR like JEST-OBJNR · STAT like J_STAT · INACT like J_INACT · TXT04 like J_TXT04 · TXT30 like J_TXT30 · OBJNR like J_OBJNR Important note: You will have to define a structure for every paramete
5、r in the BAPI. You cannot use the same structures used in existing applications because BAPI structures are frozen when BAPIs are released and then there are restrictions on changing them. 你必須為每個BAPI中的參數(shù)定義結構,當BAPI被釋放后是限制更改他們的,因為bapi會被凍結,所以你不能在存在的應用中使用同一個結構ZBAPI_ORDER_STATUS_IMPORT 結構1 ZBAPIST
6、AT -結構2 第二步:寫入功能模塊Important notes: · 每個BAPI必須有他們自己的函數(shù)組(功能組) · 在屬性tab里記住選擇存取類型是Remote Enabled module,否則功能模塊不能通過RFC來invoke它做為一個BAPI來使用· 輸入/輸出參數(shù)僅僅能被BY VALUE 對于RFC enabled的功能模塊· 我們在此僅創(chuàng)建了一個BAPI,但你能創(chuàng)建相關的BAPI在同一模塊池中,使得他們能共享全局信息功能模塊的屬性設定輸入?yún)?shù) 這里定義功能模塊的輸入?yún)?shù)為訂單輸入?yún)?shù)的結構,即是引入結構ZBA
7、PI_ORDER_STATUS_IMPORT做為bapi_order_status_import的參照 Export Parameters Tables Code Notes: · The subroutine SET_RETURN_MESSAGE is a standard routine used for BAPIs that use the BAPIRETURN structure· SET_RETURN_MESSAGE子程序是在BAPI中標準的子程序用來使用BAPIRETURN 結構 · 在FORM Z_BAPI_GET
8、_ORDER_SYSTEM_STATUS里有個測試是IF 1=2,如果這測試結果為真,則信息就顯示,但是這個條件永遠不會為真,所以我們就不可能在BAPI里顯示出這個信息,為什么要包含這個的原因是,為信息創(chuàng)建一個參照,因此這時SAP標準控制方法,拷貝公司代碼層面的代碼GetList BAPI.· In form Z_BAPI_GET_ORDER_SYSTEM_STATUS there is a test IF 1 = 2. If the test is true a message is displayed. The condition will obviously never be
9、true, and we will never want to display a message in a BAPI. The reason why it is included is, that it create a reference for the message, so that the WHERE USED functionality can be used for the message. This is the SAP standard way to handle it, copied from the Company Code GetList BAPI. INCLUDE L
10、ZBAPISTATUSUXX * THIS FILE IS GENERATED BY THE FUNCTION LIBRARY. * NEVER CHANGE IT MANUALLY, PLEASE! *INCLUDE LZBAPISTATUSU02. "Z_BAPI_GET_ORDER_SYSTEM_STATUSINCLUDE LZBAPISTATUSTOP - Global data FUNCTION-POOL ZBAPISTATUS. "MESSAGE-ID Z3Types: begin of Type_tj02t, istat like tj02t-istat, t
11、xt04 like tj02t-txt04, txt30 like tj02t-txt30, end of type_tj02t.DATA:* Declarations for TABLE parameter T_BAPISTAT like ZBAPISTAT occurs 0, G_BAPISTAT like ZBAPISTAT,* Table for object texts t_tj02t type type_tj02t occurs 0, g_tj02t type type_tj02t.* Structure for return messagesDATA: BEGIN OF MESS
12、AGE, MSGTY LIKE SY-MSGTY, MSGID LIKE SY-MSGID, MSGNO LIKE SY-MSGNO, MSGV1 LIKE SY-MSGV1, MSGV2 LIKE SY-MSGV2, MSGV3 LIKE SY-MSGV3, MSGV4 LIKE SY-MSGV4, END OF MESSAGE.INCLUDE LZBAPISTATUSF01 - Subroutines *INCLUDE LZBAPISTATUSF01 .*-*&-*& Form SET_RETURN_MESSAGE*&-* This routine is used
13、for setting the BAPI return message.* The routine is a standard routine for BAPIs that handles the message* structure for the BAPIRETURN structure. It has been copied from the* BAPI Company Code Getlist*-* ->P_MESSAGE text* <-P_RETURN text*-*form SET_RETURN_MESSAGE USING VALUE(P_MESSAGE) LIKE
14、MESSAGE CHANGING P_RETURN LIKE BAPIRETURN. CHECK NOT MESSAGE IS INITIAL. CALL FUNCTION 'BALW_BAPIRETURN_GET' EXPORTING TYPE = P_MESSAGE-MSGTY CL = P_MESSAGE-MSGID NUMBER = P_MESSAGE-MSGNO PAR1 = P_MESSAGE-MSGV1 PAR2 = P_MESSAGE-MSGV2 PAR3 = P_MESSAGE-MSGV3 PAR4 = P_MESSAGE-MSGV4* LOG_NO =
15、39; '* LOG_MSG_NO = ' ' IMPORTING BAPIRETURN = P_RETURN EXCEPTIONS OTHERS = 1. endform. " SET_RETURN_MESSAGEFUNCTION Z_BAPI_GET_ORDER_STATUS FUNCTION z_bapi_get_order_system_status.*"-*"*"Local interface:*" IMPORTING*" VALUE(I_AUFNR) TYPE AUFNR*" V
16、ALUE(I_SPRAS) TYPE SPRAS DEFAULT SY-LANGU*" VALUE(I_EXCLUDEINACTIVE) TYPE CHAR1 OPTIONAL*" EXPORTING*" VALUE(RETURN) TYPE BAPIRETURN*" TABLES*" T_BAPISTAT STRUCTURE ZBAPISTAT*"-*"Local interface:*" IMPORTING*" VALUE(I_AUFNR) TYPE AUFNR*" VALUE(I_SPRA
17、S) TYPE SPRAS DEFAULT SY-LANGU*" VALUE(I_EXCLUDEINACTIVE) TYPE CHAR1 OPTIONAL*" EXPORTING*" VALUE(RETURN) TYPE BAPIRET2*" TABLES*" T_BAPISTAT STRUCTURE ZBAPISTAT DATA: l_aufnr LIKE afko-aufnr, l_objnr LIKE jest-objnr.* Check if order exists* SELECT SINGLE aufnr FROM afko INT
18、O l_aufnr WHERE aufnr = BAPI_ORDER_STATUS_IMPORT-orderid. IF sy-subrc NE 0. CLEAR message. message-msgty = 'E'. message-msgid = 'Z3'. message-msgno = '000'. message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid. PERFORM set_return_message USING message CHANGING return. IF 1 = 2.*
19、The only reason to include this statement, that will obviously* never execute, is that it will create a referecence so that you* can find out where a particular message is being used. This* functionality is used by the BAPIs programmed by SAP MESSAGE e000(z3). ENDIF. ENDIF. CHECK return IS INITIAL.*
20、 Read order status* CONCATENATE 'OR' BAPI_ORDER_STATUS_IMPORT-orderid INTO l_objnr. IF BAPI_ORDER_STATUS_IMPORT-i_excludeinactive = 'X'. SELECT objnr stat inact FROM jest INTO TABLE t_bapistat WHERE objnr = l_objnr AND inact <> 'X'. ELSE. SELECT objnr stat inact FROM je
21、st INTO TABLE t_bapistat WHERE objnr = l_objnr. ENDIF. IF sy-subrc <> 0.* No object status found CLEAR message. message-msgty = 'E'. message-msgid = 'Z3'. message-msgno = '001'. message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid. PERFORM set_return_message USING message C
22、HANGING return. IF 1 = 2. MESSAGE e001(z3). ENDIF. ENDIF. CHECK return IS INITIAL.* Read order status texts* SELECT istat txt04 txt30 FROM tj02t INTO TABLE t_tj02t FOR ALL ENTRIES IN t_bapistat WHERE istat = t_bapistat-stat AND spras = BAPI_ORDER_STATUS_IMPORT-i_spras. SORT t_tj02t BY istat. L
23、OOP AT t_bapistat INTO g_bapistat. READ TABLE t_tj02t WITH KEY istat = g_bapistat-stat BINARY SEARCH INTO g_tj02t. IF sy-subrc = 0. MOVE: g_tj02t-txt04 TO g_bapistat-txt04, g_tj02t-txt30 TO g_bapistat-txt30. MODIFY t_bapistat FROM g_bapistat TRANSPORTING txt04 txt30. ENDIF. ENDLOOP.ENDFUNCTION.
24、; STEP 3 - Create the API Method Using the BAPI WIZARDThe BAPI wizard is used toTo expose the remote function module as a BAPI. The wizard will generate some additional code, so the function module is a valid method of the BOR. This allows the BAPi to be called as a workflow method in addition to be
25、 called by an outside program. Note: Each functionmodule corresponds to a method in the BOR Go to the Busines Object Builder SWO1. You can either create the new Object type as a subtype of an existing business object or create a new business object from scratch. In this example it would be obvious t
26、o create the Object type as a subtype of BUS2005 Production order. However, to illustrate how to create a new Object type from scratch, we will do this. In the Object/Interface type field write the name of the new Business Object: ZORDERSTAT. Press enter and fill in the additional fields necessary t
27、o create the object type. Supertype: Not relevant because we are creating our object from scratch Program. This is the name of the program where the wizard generates code for the Object type, NOT the function module we craeted earlier. The program name must not be the name of an existinbg program. &
28、#160; Press enter and create the new business object. Note that when you create the business object a standard interface, an attribute ObjectType and the methods ExistenceCheck and Display are automatically generated. These cannot be changed ! The next step is to add the Z_BAPI_GET_ORD
29、ER_STATUS method to the business object. Select Utillities -> API methods -> Add method and write the name of the functionmodule in the dialogbox. Next the dialogbox show below will be shown. This is the start screen of the BAPI wizard. Proceed with wizard by pressing the button. After you hav
30、e finished the wizard, tyou will notice that the ZGetOrderStatus has been added to the business object: You can doubleclick on the method to see its properties. To use the business object you must change the Object type status to Implemented. Use menu Edit->Change releases status->Object type-
31、>To implemented. No you can test thge object (Press F8). Note that the BAPI wizard has added a wrapper class for the function module so it can be sued as method in the business object. Choose menu Goto->Program to display the program: * Implementation of object type ZORDERSTAT *INCLUDE <OBJ
32、ECT>.BEGIN_DATA OBJECT. " Do not change. DATA is generated* only private members may be inserted into structure privateDATA:" begin of private," to declare private attributes remove comments and" insert private attributes here ." end of private, KEY LIKE SWOTOBJID-OBJKEY.
33、END_DATA OBJECT. " Do not change. DATA is generatedBEGIN_METHOD ZGETORDERSTATUS CHANGING CONTAINER.DATA: BAPIORDERSTATUSIMPORT LIKE ZBAPI_ORDER_STATUS_IMPORT, RETURN LIKE BAPIRETURN, TBAPISTAT LIKE ZBAPISTAT OCCURS 0. SWC_GET_ELEMENT CONTAINER 'BapiOrderStatusImport' BAPIORDERSTATUSIMPORT.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度裝合同終止協(xié)議書:綠色環(huán)保產(chǎn)業(yè)園建設項目合同終止
- 二零二五年度房地產(chǎn)項目市場調研委托合同
- 二零二五年度葡萄酒產(chǎn)區(qū)生態(tài)保護與購銷合同
- 2025年度藥品研發(fā)合作與全球市場推廣合同范本
- 湖南省張家界五道水鎮(zhèn)中學2025屆中考聯(lián)考生物試題含解析
- 南京理工大學《西方文學與文化》2023-2024學年第一學期期末試卷
- 南京交通職業(yè)技術學院《車輛工程專業(yè)導論》2023-2024學年第一學期期末試卷
- 南京工業(yè)職業(yè)技術大學《建筑漫游》2023-2024學年第一學期期末試卷
- 南華大學《新聞采訪與寫作3》2023-2024學年第一學期期末試卷
- 南昌醫(yī)學院《寵物醫(yī)學》2023-2024學年第一學期期末試卷
- GB/T 34241-2017卷式聚酰胺復合反滲透膜元件
- GB/T 12494-1990食品機械專用白油
- 運輸供應商年度評價表
- 成熙高級英語聽力腳本
- 北京語言大學保衛(wèi)處管理崗位工作人員招考聘用【共500題附答案解析】模擬試卷
- 肺癌的診治指南課件
- 人教版七年級下冊數(shù)學全冊完整版課件
- 商場裝修改造施工組織設計
- 統(tǒng)編版一年級語文上冊 第5單元教材解讀 PPT
- 加減乘除混合運算600題直接打印
- ASCO7000系列GROUP5控制盤使用手冊
評論
0/150
提交評論