Você está na página 1de 37

SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.

ppt/ 1
Robert Chu (www.sap.com)
Thomas G. Schuessler (www.arasoft.de)
Programming with BAPIs in
Visual Basic (Advanced)
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 2
First things first...
Copied from www.blackjackcharts.com
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 3
Overview
l DCOM Connector Overview
l Programming Steps
l Advanced Concepts
l Exercise
l More Information
l Questions and Answers
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 4
DCOM Connector Overview
l Access to BAPIs and other RFMs (RFC-enabled Function
Modules)
l Alternative to the SAP ActiveX controls
l Smaller client footprint
l Better performance
l Uses generated proxy classes (C++) to
n Avoid runtime metadata retrieval
n Support IntelliSense
l Support for ActiveX Data Objects (ADO)
n Used for structure and table parameters
n Data binding with ADO-aware ActiveX controls
l Use with or without MTS
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 5
Fully distributable,
scalable n-tier architecture
Intranet Client
Dynamic HTML,
Java
Internet Client
Dynamic HTML
via ASP and/or
Remote Data
Service (RDS)
etc.
Web
Server
Fat Client
Visual Basic,
C++, Java
Microsoft Transaction
Server
Language-neutral,
strongly-typed interfaces
Common Programming Model
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 6
Installation
l Use 4.6C or later version of SDC regardless of the back-end
R/3 release.
l DCOM Connector can be installed with or without Microsoft
Transaction Server (MTS).
l MTS recommended for high-volume Internet/Intranet
applications.
l Microsoft Visual C++ 6.0 required to generate proxies.
l Visual Studio Service Pack 3 highly recommended.
l Internet Explorer required for administration.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 7
System Administration
l Define destinations
n Supports load balancing (logon groups) and individual
application servers.
l Generate business object and RFM proxies
RFM = RFC-enabled Function Module
l BAPIs and non-BAPI RFMs cannot be generated into the same
DLL.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 8
Proxy Generation
l The make file name (C++ Project) determines the DLL name, e.g.
T46BCompanyCodeProject.mak will result in
T46BCompanyCodeProject.dll.
l The file name of the DLL can be changed later.
l The Namespace parameter and the make file name determine
the component name (Type Library name) in VB, e.g.
n Dim oCompanyCode As _
T46BCompanyCodeProjectLib.CompanyCode
l The Namespace parameter determines the ProgId, e.g.
n Set oCompanyCode = _
oSession.CreateInstance("T46B.CompanyCode")
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 9
References in the VB Project
l Microsoft ActiveX Data Objects Recordset 2.1 Library
(msador15.dll)
l Generated business object proxies and RFM proxies
l SAP: Remote Function Call: COM support 1.0 Type Library
(librfc32.dll)
n Required only if you want to use
w RfcSession
w RfcGuiSink
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 10
Programming Steps I
l Define Session object
n Global oSession As CompanyCodeProjectSessionComponent
l Create Session object
n Set oSession = New CompanyCodeProjectSessionComponent
l Set session information / logon
n oSession.PutSessionInfo _
Destination:="<destination name", _
UserID:="<userid>", Password:="<password>", _
Client:="<client>", Language:="<language code>"
n If oSession.Logon(sLogonError) Then
String parameter contains error information.
n Alternative: Use a visual logon component, e.g. freeware at
www.sap.com/solutions/technology/bapis/com/ara_dcom_2.zip
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 11
Programming Steps II
l Create business object proxies
n Dim oCompanyCode As _
T46BCompanyCodeProjectLib.CompanyCode
Set oCompanyCode = _
oSession.CreateInstance("T46B.CompanyCode")
l Set key fields for instance BAPIs
n oCompanyCode.InitKeys "0001"
Calling the InitKeys method does not check the existence of the
particular record in the R/3 database.
Call an instance method BAPI like ExistenceCheck or GetDetail
instead.
Keys are read-only properties of the proxy object.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 12
Programming Steps III
l Create structure/table parameter recordsets for import
parameters
n Dim rsCompanyCodeList As Recordset
Call oCompanyCode.DimAs("BapiGetList", _
"CompanyCodeList", rsCompanyCodeList)
Not required in this case, since CompanyCodeList is an
export-only table.
BAPI and parameter name parameters are case-sensitive!
l Fill import structure/table parameters using ADO
l Call the BAPI
n Dim rsReturn As Recordset
oCompanyCode.BapiGetList _
CompanyCodeList:=rsCompanyCodeList, _
Return:=rsReturn
BAPI name must be prefixed by "Bapi".
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 13
Programming Steps IV
l Check the return code
n If Not (rsReturn("TYPE") = "S" Or _
rsReturn("TYPE") = "I" Or _
rsReturn("TYPE") = "") Then
MsgBox rsReturn("TYPE") & rsReturn("CODE") & ":" & _
rsReturn("MESSAGE")
Exit Sub
End If
l Use the returned data
n Set DataGrid1.DataSource = rsCompanyCodeList
l Empty tables are returned as Nothing, not as recordsets with no
rows.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 14
Visual Logon Component Client Code
Dim oSession As SessionComponent
Dim sErrorMessage As String
Dim ldSuccess As ARAsoftDLC.LOGONDIALOGRESULT
Set oSession = New SessionComponent
ldSuccess = ARAsoftDLC.LogonDialog(oSession, sErrorMessage)
If ldSuccess = Success Then
MsgBox "Okay"
ElseIf ldSuccess = Failure Then
MsgBox sErrorMessage
ElseIf ldSuccess = Cancel Then
' User cancelled the logon dialog
End If
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 15
Advanced Concepts
l Transaction handling
l Connection properties
l Debugging
l Data conversion
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 16
Transaction Handling
l All 3.1 update BAPIs execute their own COMMIT WORK.
l BAPIs since 4.0 are not supposed to do this.
l Double-check which category the BAPIs you want to use fall
into.
n There is no metadata attribute for this
n Read the documentation
n OSS Note 131838 should list all BAPIs that execute their own
COMMIT WORK
n If in doubt, test...
l Be careful when using BAPIs from both categories in the
same session.
l Your own BAPIs must use the Update Task to support the
new concept.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 17
Commit/Rollback BAPIs
l Supported starting with 4.5 by the BapiService methods
n TransactionCommit
w WAIT parameter allows the client program to wait for the
completion of the Update Task.
This can severely impact performance!
w Return parameter (filled only when WAIT = "X")
n TransactionRollback
l Supported starting with 4.0 by the RFC-enabled functions
modules
n BAPI_TRANSACTION_COMMIT
n BAPI_TRANSACTION_ROLLBACK
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 18
Transaction Handling in SDC
l Commit and Rollback are methods of the RfcSession object
n oSession.CommitWork
n oSession.CommitWorkAndWait (not implemented)
n oSession.RollbackWork
l Alternative: Use the appropriate BAPIs of BapiService
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 19
Connection Properties
l Function GetConnectionAttribute([AttrName As String])
n Returns one attribute (as a Variant) or, if attribute name is omitted,
a recordset.
n Dim rsX As Recordset
Set rsX = oSession.GetConnectionAttribute
l Most important fields
n DESTINATION
n SYSID
n PARTNER_HOST
n SYSTNR
n USER
n PARTNER_REL
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 20
Debugging
l Client side
n RFC trace
w "trace=1" in the destination string
w Writes to file rfcnnnnn_nnnnn.trc
n Component to display recordsets during debugging
l Server side
n Debug ABAP code
n Requires SAP-GUI and some ABAP Workbench knowledge
w Dim oSink As RfcGuiSink
Set oSink = New RfcGuiSink
oCompanyCode.AdviseRfcGuiSink oSink, 1, 0
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 21
The BapiService Object I
l Support functions for BAPI programming
l BAPIs (4.0)
n DataConversionInt2Ext
n DataConversionExt2Int
l Additional BAPIs (4.5A)
n ApplicationLogGetDetail
n FieldhelpGetDocu
n InterfaceGetDocu
n MessageGetDetail
n TransactionCommit
n TransactionRollback
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 22
The BapiService Object II
l Additional BAPIs (4.5B)
n DataConversionExt2int1 (sic!)
n DataConversionInt2Ext1
l Additional BAPIs (4.6)
n HyperLinkGetText
l Renamed BAPIs (4.6)
n DataConversionExt2Int1 (sic!)
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 23
Conversion BAPIs
l BAPIs often deliver and require the internal SAP data format.
l Examples:
n Customer numbers
n Material numbers
n Language-dependent codes
w Units of measure etc.
l Check the conversion exit field of a field's domain to
determine whether conversion is required.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 24
DataConversionInt2Ext
l Converts internal to external format
l Parameters
n Data (table)
w OBJTYPE Internal name of object
w OBJNAME "Official" name of object
w METHOD Name of BAPI
w PARAMETER Name of parameter
w FIELD Field name in structure or table
w ROWNUMBER Row number in this table
w INT_FORMAT Internal format to be converted
w EXT_FORMAT Result in external format
n Return (table)
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 25
DataConversionExt2Int
l Converts external to internal format
l Parameters
n Data (table)
w OBJTYPE Internal name of object
w OBJNAME "Official" name of object
w METHOD Name of BAPI
w PARAMETER Name of parameter
w FIELD Field name in structure or table
w ROWNUMBER Row number in this table
w INT_FORMAT Result in internal format
w EXT_FORMAT External format to be converted
n Return (table)
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 26
Exercise 1
l Build a DcomServices component for DCOM Connector, Part 1
l Retrieve connection information for the current session
l Open project group CompanyCode 2.vbg
l Follow the instructions in the template (GlobalServices).
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 27
Exercise 2
l Build a DcomServices component for DCOM Connector, Part 2
l Display a recordset during debugging
l Open project group CompanyCode 2.vbg
l Follow the instructions in the template (Debugging).
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 28
Exercise 3
l Display the ISO language code for this company code in the
Detail form.
l Use the appropriate conversion BAPI
(DataConversionInt2Ext1).
l Open project CompanyCode 3.vbp
l Follow the instructions in the template (form fmDetail)
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 29
ARAsoft Windows Products I
l ARAsoft Metadata Server for SAP R/3
n Supports 3.1 - 4.6
n Retrieves all(!) metadata available in R/3
n Uses the RFC ActiveX Control
n Can only be licensed by software companies
n Can be ported to DCOM Connector and Java upon request
l ARAsoft BAPI Debugging Library
n Helps debugging ActiveX Controls- and SDC-based applications
n Evaluation copy at
http://www.sap.com/solutions/technology/bapis/com/aradebug.zip
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 30
ARAsoft Windows Products II
l ARAsoft ADO SAP Table Library
n For ActiveX Control-based applications
n Makes SAP Table objects look like ADO recordsets
l ARAsoft OIW Library
n For ActiveX Control-based applications
n Encapsulates access to the OIW BAPIs
l ARAsoft Product Catalog Component
n For ActiveX Control-based applications
n Encapsulates access to the ProductCatalog BAPIs
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 31
ARAsoft Windows Products III
l ARAsoft BAPI Support Library
n For ActiveX Control-based applications
n Support for
w Structures, Fields
w Helpvalues
w Conversions
w SAP Systems (saplogon.ini)
w many other functions
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 32
ARAsoft Windows Products IV
l ARAsoft DCOM Connector Destination Manager for SAP R/3
n Freeware
n Download from
http://www.sap.com/solutions/technology/bapis/com/ara_dest.zip
l ARAsoft DCOM Connector Logon Component for SAP R/3
n Freeware
n Download from
http://www.sap.com/solutions/technology/bapis/com/ara_dcom_2.zip
n Source code can be purchased
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 33
ARAsoft Windows Products V
l ARAsoft DCOM BAPI Object Factory for SAP R/3
n Support for
w Structure, Fields
w Helpvalues
w Matchcodes
w Conversions
w Destinations
w Metadata
w Open Information Warehouse
w Product Catalog
w Error handling
n Includes
w ARAsoft Visual Matchcode Component
w ARAsoft Structure Browser
w ARAsoft Helpvalues Browser
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 34
ARAsoft Java BAPI Object Factory for SAP R/3 I
l Encapsulates all difficult / error-prone / performance-related
aspects of BAPI/RFM programming, e. g.
n Check tables (Helpvalues), conversions, metadata
l Significantly reduces the amount of SAP know-how
developers need to build world-class applications.
l Significantly speeds up development projects.
l Significantly reduces maintenance and R/3 release upgrade
cost.
l Provides release-independence.
l Allows you to avoid hard-coded solutions that will come
back to haunt you in the future.
l Optimizes performance of your application through just-in-
time data retrieval and caching.
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 35
ARAsoft Java BAPI Object Factory for SAP R/3 II
l Tested for R/3 releases 4.0B through 4.6C.
l Tested with JDK 1.1 and Java 2; 100 percent pure Java.
l Works with any Java RFC middleware (HAHT, SAP, IBM).
l No proxies required.
l Supports desktop and server/web applications.
l Evaluation copy available on request.
l On-site developer training (all aspects of BAPI programming)
available on request.
l An earlier version of this component was described in the
article "Simplifying BAPI Programming with Components" in
the Nov/Dec 1999 issue of the SAP Professional Journal
(www.sappro.com)
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 36
Additional Information
l CA925: Programming with BAPIs in Visual Basic
n Offered in Germany, UK, USA
l www.sap.com/bapi
l www.sappro.com
l www.sapinsider.com
l "The BABI Bible for SAP Programmers: The comprehensive
guide to integrating SAP products with Web, desktop, and
mobile applications using Java, Visual Basic, and ABAP"
published in late 2000 by SAP Professional
SAP Labs, Inc. and ARAsoft GmbH SAP TechEd 2000 June 2023, 2000 BAPI03.ppt/ 37
ARAsoft GmbH
l Products, Consulting, Custom-development, Training
offered world-wide.
http://www.arasoft.de
Alte Bruchsaler Str. 60
69168 Wiesloch
Germany
+49-6222-91171 (phone)
+49-6222-91176 (fax)
+49-6227-748727 (SAP)
tgs@arasoft.de
thomas.schuessler@sap.com

Você também pode gostar