BAPI / RFC with Delphi

      Introduction

         Preface
        Preparation
        The Component TSAPLogonControl    
        The Component TSAPFunctions
        The Component TSAPBAPIControl     
        Tips
        General Notes

 

pfeil7.gif (373 Byte) end of page

 

 

 

 

 

 

Preface:

This page is to give a short idea of the BAPI / RFC - programming with Delphi. Mostly the largest problem a start is to be found, because the documentation’s are very meagre to this topic. This " first step " is to be facilitated hereby. Further I am in this area also rather beginner, for this reason am I very interested in your experiences and ask therefore for feedback whether this introduction helped you. For each comment, questions or suggestions I am very grateful.

top of page

 

Preparation:

Required is the SAPGui (local or installed in the net), the SAP software development kit (SDK) which you can find on the SAP-Install-CD. Also the SAP-Assistant and SAPlogon and naturally Delphi.

At the moment I’m using the SAPGui 4.6D, SAPAssistant 3.0 and Delphi 5.0 professional.

During the Installation from the SDK, any OCX-files become installed, which included active x-components. These can be build in into Delphi.

The ActiveX components are merged as follows in Delphi:

 

After the Installation of the components these can get in a form from the register ActiveX of the component Menu. More information’s about this theme you can read in the Delphi-component-manual.

With the SDK, help files get installed, which are very useful. Here are the components described in details. The SAP-Assistant is a tool to check the connection to the R3-Systems and to test functions.

So can a function filled in with values and you can see the result immediately without programming one line. Also the Assistant gives you a quick survey about the necessary parameters and tables of the functions. Alternative you can use the function builder in R3. This you ca start with the transaction SE37.

With the program SAPLogon you can prepare an R3-connection. The advantage is, you must not give in the single parameters by every logon. The values in the SAPLogon can be used from the ActiveX-component.

 

top of page

 

The Component TSAPLogonControl

With this component a connection to the R3-System can be made. Depending upon parameter the pre-set data from the program SAPLogon will know used or the connecting data directly to be indicated. If the pre-set data are used, the log-on is made by a small dialog box which can not be changed. The more elegant way is the log-on over the so-called SilentLogOn, with which no dialog box appears. Here however the connecting parameters must be indicated explicitly. A connection made over this component can be used with TSAPFunctions or TBAPIControl.

Example 1 LogOn
Example 2 SilentLogOn

 

top of page

 

The Component TSAPFunctions

If not TSAPLogonControl is in use, the log-on takes place automatically to the R3-System with the first call of the BAPI/RFC function via the Object TSAPFunctions. Here the program SAPLogon is started, in which the connecting parameters are specified. The connection remains existing, until the application program is terminated and the object is released. Here the connection correct is separated.

For this introduction I structured 4 examples. From first to the last the difficulty grows. For this reason I guess to process the examples in sequence.

Example 3 Read all costcenters with the function RFC_READ_TABLE
Example 4 Read all costcenters with the function RFC_READ_TABLE and logon with SilentLogon
Example 5 Show the details of material the BAPI BAPI_MATERIAL_GET_DETAIL
Example 6 Create an purchaseorder with the BAPI BAPI_PO_CREATE

The clear advantage of the component TSAPFunctions is, that all RFC able functional modules can be addressed. Disadvantage: Pedantic programming, not object-oriented.

 

top of page

 

The Component TBAPIControl

If not TSAPLogonControl is in use, the log-on takes place automatically to the R3-System with the first call of the BAPI/RFC function via the Object TSAPBapiControl (see component TSAPFunctions).

With this component only BAPI's can be addressed. Programming is however substantially more elegant, because the functions are represented as objects here. In the R3-System these objects can be tested in the BOR (Business Object Repository) with the transaction SWO1. Around functions in the R3 to respond there are basically 2 possibilities: directly over the functional modules with the component TSAPFunctions or over the Business Object with TBAPIControl.


Source: SAP BAPI documentation

Example 7 Show the details of material with the BusinessObject BUS1001
Example 8 Create an purchaseorder with the BusinessObject BUS2012

 

top of page

TIPS:

Function values:
The separate values of the BAPI’S should be hand over in the same format like they are in the SAP tables. That means, stringlenght, uppercase or lowercase, and leading zeros at numeric values should keep unconditional. Otherwise an error can occur.

CommitWork:
With some BAPI's the posting takes place not directly, it must be locked with an explicit CommitWork. With which BAPI this is the case, must be taken of the respective documentation !

 

top of page

General Notes

The examples are tested and function on our system perfectly. For any errors I do not take responsibility. As mentions already initially, am I beginner in this area. Professionals may excuse me please small errors. For tips in this case I would be very grateful.

I hope to have helped you with this introduction . And again the request for feedback!!!!!

(Sorry for this bad english ;-)))


Thanks to Andreas Burrichter for the support with training into this topic and to Thomas Toll for the suggestions for the examples. All information of these pages is taken from the SAP documentation to the RFC-SDK and the BAPI section of the SAP-AG (http://www.sap.com/bapi).

top of page