This website is not affiliated with, sponsored by, or approved by SAP AG.

Calling SAP From VB

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Calling SAP From VB

Postby gregs » Mon Oct 21, 2002 5:26 pm

Greetings everyone;

Please bear with me as I have noticed this topic being covered in old posts, but I must be missing something!

Query: Need to call a custom built SAP function module from VB, passing parameters in, and receiving a return code back to the VB app.

I am not a VB programmer, but am responsible from the SAP side and am trying to gather information to pass ONTO our VB expert, and thus my lack of terminology I can utilized in describing the interface requirements.

I realize there quite a few of connectors out there for R/3: java, .net, dcom, but in a straight forward scenario, does anyone have an example of calling a function module from VB?

Possibly a step by step list of how to implement one (registration, et...)?

We are currently on a 4.5b system.

Again, excuse my ignorance when it comes to any other language than ABAP :-)

Any examples would be GREATLY appreciated, my email address is gsoltys@csinc.biz

Cheers everyone;
Greg
gregs
 
Posts: 39
Joined: Mon Oct 21, 2002 4:28 pm

Postby Sunny » Tue Oct 22, 2002 3:58 am

Hi,
You can use BAPI.In VB,You will have to include SAPLogon Control on the form which can be found in Tools-->Additional controls.This control is used to longon to SAP.Now You can call different methods of a BAPI to carry out different functions. I think SAP help contains step by step details with Sales Order creation as an example.
Sunny
Sunny
 
Posts: 94
Joined: Mon Oct 21, 2002 5:07 am
Location: United Kingdom

Postby Deacon » Tue Oct 22, 2002 3:29 pm

You can write custom BAPI's and access them but you can also write a function and make it RFC enabled by selecting the Remote-Enabled module on the attributes tab in SE37. You can access this function using VB by the SAP DCOM connector, or for a more basic solution you can access the wdtfuncs.ocx(ActiveX control). It has a Logon control in it and if you look at the documentation provided when you install the SAP Automation (I think it is in the developers toolkit RFC SDK) it will give you some basic samples of how to use these controls. Or you can go to help.sap.com choose the correct version and do a find on "Example Application with the Function Control" and it should return the results to give your VB guy a good head start it will have sample code as well as tell him where some of the SAP provided samples reside on his desktop. If you need more details repost and I'll see what I can provide you.
Deacon
 
Posts: 51
Joined: Tue Oct 22, 2002 3:08 pm

Postby DBANKS » Tue Oct 22, 2002 3:39 pm

On the SAP side, you will need to make your FM remote enabled. Using SE37, make sure this is set on the attributes screen. You need to tell your VB expert all of the import, export, changing, tables, and exception parameters as they are defined in the FM or BAPI. Good news! You are really done on your side.

On the VB side, you need to do several things (this is very general but hits all of the key points):

1. make sure the system files wdtlog.ocx and librfc32.dll are registered on the "client" machine (loading SAPGUI or any of the connectors will take care of this)

2. in VB, create the SAP object
Set R3 = CreateObject("SAP.Functions")
R3.Connection.logon


3. If the login is successful, set the FM or BAPI object
Set MyRFC = R3.Add("SAP_FUNC_MOD")

4. Set the export/import parameters (parameters that are defined in the FM). You do not have to set ALL parameters; only the ones required and the ones that you need to use. This is helpful for some BAPIs that have many fields that DO NOT have to be set.
Set oExport1 = MyRFC.exports("SAP_EXPORT_PARM_1")
Set oExport2 = MyRFC.exports("SAP_EXPORT_PARM_2")
Set iImport1 = MyRFC.imports("SAP_IMPORT_PARM_1")
DIM tTable1 as Object

etc...

5. Populate the parameters to pass to SAP
oExport1.value = "Customer Number 12345"
etc...

6. Make the call to SAP
Result = MyRFC.CALL
IF RESULT = TRUE
iImport1.Value = MyRFC.imports("SAP_IMPORT_PARM_1")
SET tTable1 = MyRFC.Tables("SAP_TABLE_1")
Else
MsgBox MyRFC.EXCEPTION
End If


7. Logoff
R3.Connection.LOGOFF

This should be enough to get you started. :D

D. Banks
dbanks_99@yahoo.com
DBANKS
 

Postby gregs » Tue Oct 22, 2002 4:08 pm

Thanks guys, that's a huge help. I've passed your replies to our VB guy and he's rolling with it for now.

Your help was greatly appreciated and I'll post a follow-up if he comes back with any obstacles.

Thanks again! :D

Cheers,
greg
gregs
 
Posts: 39
Joined: Mon Oct 21, 2002 4:28 pm


Return to ABAP

Who is online

Users browsing this forum: Google [Bot] and 7 guests





This website is not affiliated with, sponsored by, or approved by SAP AG.