BAPI的使用说明_中文版_第1页
BAPI的使用说明_中文版_第2页
BAPI的使用说明_中文版_第3页
BAPI的使用说明_中文版_第4页
BAPI的使用说明_中文版_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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读取生产订单系统状态和从表TJ02T中读取文本状态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中用到功能模块的表和参数均已在这里定义使用数据类型-结构定义以下结构:结构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中的参数定义结构,当BAPI被释放后是限制更改他们的,因为bapi会被冻结,所以你不能在存在的应用中使用同一个结构ZBAPI_ORDER_STATUS_IMPORT 结构1   ZBAPIST

6、AT -结构2    第二步:写入功能模块Important notes: · 每个BAPI必须有他们自己的函数组(功能组) · 在属性tab里记住选择存取类型是Remote Enabled module,否则功能模块不能通过RFC来invoke它做为一个BAPI来使用· 输入/输出参数仅仅能被BY VALUE 对于RFC enabled的功能模块· 我们在此仅创建了一个BAPI,但你能创建相关的BAPI在同一模块池中,使得他们能共享全局信息功能模块的属性设定输入参数 这里定义功能模块的输入参数为订单输入参数的结构,即是引入结构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里显示出这个信息,为什么要包含这个的原因是,为信息创建一个参照,因此这时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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论