1 BAPI的优点
bapi是面向对象的设计;
bapi是固定的,一般不能修改;
bapi可以被sap内部部件和非sap程序使用;
bapi的成功和错误信息始终通过RETURN返回;
bapi可以被许多开发平台使用;
2 何时该考虑使用BAPI设计程序
用VB/JAVA?C++等语言编写非SAPGUI程序访问和处理sap数据;
SAP不同部件之间通讯;
与非sap程序或者老系统交换数据:
使用异步通信分发数据如:ALE
可以通过SAP Business Connector or Internet Application Components与因特网程序集成;
3 关于RETURN
RETURN用于BAPI返回错误和成功的消息,它可以是BAPIRETURN,BAPIRETURN,BAPIRET1,BAPIRET2和BAPIRET2_FIX中的一种类型.这些结构一般都包括以下字段:
TYPE
CHAR 1
S= successmessage
E = error message
W = warning message
I = information message
A = termination message (abort)ID
CHAR 20
Message ID The structure BAPIRET2takes into account the name space extension for the message classas of Release 4.0. If you want messages to be compatible withearlier R/3 Releases, use the message classes before Release4.0.
NUMBER
NUMC 3
Message number
MESSAGE
CHAR 220
Full message text from the messagetable. All variables (in fields Message_V1 to Message_V4) have beenreplaced with text.
MESSAGE_V1
MESSAGE_V2
MESSAGE_V3 MESSAGE_V4CHAR 50
Fields for the variable texts of themessage
4BAPI的程序框架
Log on
(Source code)
CallBAPI
(Source code)
CallBAPI
(Source code)
Call BAPIBapiService.TransactionCommit()
(Source code)
CallBAPI
(Source code)
CallBAPI
(Source code)
Call BAPIBapiService.TransactionCommit()
(Source code)
Log off
5 相关函数
'BALW_BAPIRETURN_GET2':取生成返回消息
CALLFUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
TYPE = 'E'
CL = 'BC_BOR'
NUMBER = 163
PAR1 = MSG1_HLP
PAR2 = MSG2_HLP
IMPORTING
RETURN = RETURN.
BAPI_TRANSACTION_COMMIT和 API_TRANSACTION_ROLLBACK: BAPI事务函数
BUFFER_SUBSCRIBE_FOR_REFRESH和BUFFER_REFRESH_ALL:缓冲区处理函数
'TRANSACTION_BEGIN,'TRANSACTION_STATUS' 和'TRANSACTION_END' 的调用示例
callfunction 'TRANSACTION_BEGIN' "94702/KB
importing "94702/KB
transaction_id =transaction_id "94702/KB
exceptions "94702/KB
others =1. "94702/KB
callfunction'BAPI_PO_CREATE' "94702/KB
exporting "94702/KB
po_header =po_head "94702/KB
importing "94702/KB
purchaseorder =h_ebeln "94702/KB
tables "94702/KB
po_items =po_item "94702/KB
po_item_schedules =po_sched "94702/KB
po_item_account_assignment =po_acct "94702/KB
po_item_text =po_text "94702/KB
return =return "94702/KB
exceptions "94702/KB
others =0. "94702/KB
callfunction 'TRANSACTION_STATUS' "94702/KB
importing "94702/KB
status =status_of_transaction "94702/KB
exceptions "94702/KB
others =1. "94702/KB
ifstatus_of_transaction =commit_work. "94702/KB
commit work andwait. "94702/KB
endif. "94702/KB
callfunction'TRANSACTION_END' "94702/KB
exporting "94702/KB
transaction_id =transaction_id "94702/KB
exceptions "94702/KB
others =1. "94702/KB