A sad story with a happy end.
I wanted to write a small application that would update some Oracle tables based on data read from SAP using Delphi 6. Very soon I realized that it all came down to installing the various ActiveX components required for Delphi to connect to SAP, be able to execute functions and read the returned results.
And this is where the sad part of the story begins. Looking around at various sources I could find some instructions explaining how to perform the required installation but none of them seemed to be accurate enough or straightforward enough in order to produce the desired results. In my opinion the problem occurs because our German colleagues who provided the "how-to's" tried to translate the menus from their German Delphi to English and that caused the misunderstanding. Additionally, while following the directions provided I also run into compilations errors increasing my frustration. The following article provides my how to install SAP ActiveX controls on Delphi 6 and I hope to make it as clear as possible.
I have to admit that I owe everything to the guy who wrote and maintained the BAPI/RFC Programming with Delphi Page and to my good friend Marilena who found the page for me. The page has enough examples required in order for the average Delphi programmer to understand how to program the necessary communication. An other page that gives information regarding the pre-installation steps is this one found at SDN.
So here is the list of the steps I followed in order to install SAP ActiveX controls on my version of Delphi 6 If you are using Delphi 2006 then it you might beter have a look here.
- Create an additional package page to host the new components.
- Right click on the Delphi palette → Properties → Click the Add button.
- Type a name for the new page SAP will do just fine
- Use the Move Up and Move Down buttons to position the page at the correct position. Caution : Since the page will initially be empty it will not appear on the Delphi palette.
- Create an additional directory to hold the units for the new controls. In my case I created : C:\Program Files\Borland\Delphi6\Imports\SAPControls\.
- Go to main menu Component → Import ActiveX Control
- Select the SAP Logon Control Version 1.1 (wdtlog.OCX). The displayed class name should be TSAPLogonControl
- Select SAP as the Palette Page
- Change the directory of the unit file name to the new path created in the previous step.
- Click install. The first time select to create a new package, name it SAPControls and put it the path we are already using. The controls we will install next will be added to the package as well.
- Perform the same steps this time installing the TSAPBapiControl class from SAP BABPI Control Version 1.2
- Go to main menu Project → Import Type Library.
- Select SAP Remote Function Call Controll (Version 5.0). This will provide you with the TSAPFunctions, TFunction, TParameter, TExports, TImports, TStructure clases
- Click install and choose the SAPCOntrols package created previously.
- Press compile to compile the project. At this point I got many errors, but I will show you how to resolve them.
Many errors appear in functions with code like the following :
procedure TStructure.Set_Value(index: OleVariant; Param2: OleVariant);
begin
DefaultInterface.Set_Value(index) := Param2;
end;
This should be corrected like this :
procedure TStructure.Set_Value(index: OleVariant; Param2: OleVariant);
begin
// DefaultInterface.Set_Value(index) := Param2;
DefaultInterface.Value[index] := Param2;
end;
The general error pattern is that there are unknown identifiers for functions of the form
Set_XXX(i). These should be changed to indexed properties like
XXX[i] Additionally I have had many functions not returning a value. The worst part is that the Delphi complier did not issue any warnings for some of them, so I had to look at each one separately.
The worst case was the NewConnection method of the TSAPLogonControl class. The generated code was
function TSAPLogonControl.NewConnection: IDispatch;
begin
DefaultInterface.NewConnection;
end;
and it had to be corrected to
function TSAPLogonControl.NewConnection: IDispatch;
begin
// had to add Result :=
Result := DefaultInterface.NewConnection;
end;
Failure to correct this results to all new Connections being returned null afterwards, making connections to R3 practically impossible.
After you correct all the functions with warnings, you should be finished. Just press "Install" on the package dialog and you 're done The examples in
BAPI RFC with Delphi page are good and they may get you started immediately.
If I ever get any examples of my own I will post them in this page for future reference.