Current location: Hot Scripts Forums » Programming Languages » Visual Basic » SAP RFC Calling in VB


SAP RFC Calling in VB

Reply
  #1 (permalink)  
Old 08-10-05, 10:18 PM
kido kido is offline
New Member
 
Join Date: Apr 2005
Location: Cebu , Philippines
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question SAP RFC Calling in VB

Hi all!

As my subject says...we are developing a system in VB that is capable of calling function in SAP through RFC. I'm kinda new with VB.

For those who already tried this, just would like to ask what are the requirements for VB to be able to do RFC Calling. Do we need things such as SDK , OCx, DLL, etc...

If yes! May i ask what are these files.


Thanks!

Kido
Reply With Quote
  #2 (permalink)  
Old 08-30-05, 08:54 AM
mas_detokyo mas_detokyo is offline
Newbie Coder
 
Join Date: Aug 2005
Location: Tokyo
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Basically, you need to install saplogon with RFCSDK.
(which includes librfc32.dll and other requried .ocx modules.)

Then, can write a code like below which does login to SAP.
vb Code:
  1. Dim sapConn as object 'Declare variant
  2. Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
  3.  
  4. sapConn.Connection.user = "USER"
  5. sapConn.Connection.password = "PASSWORD"
  6. sapConn.Connection.client = "001"
  7. sapConn.Connection.ApplicationServer = "127.0.0.1"
  8. sapConn.Connection.Language = "EN"
  9.  
  10. If sapConn.Connection.Logon(0, True) <> True Then 'Try Logon
  11. msgbox "Logged on to SAP"
  12. end if
After logging on to SAP, you can call function module in SAP.

R,
mas
__________________
Visitez: VBA & SAP RFC Function site - http://sapass.metro.client.jp/index.htm

Last edited by digioz; 05-31-08 at 08:41 AM. Reason: Use Code Highlighter
Reply With Quote
  #3 (permalink)  
Old 09-02-05, 09:33 AM
mas_detokyo mas_detokyo is offline
Newbie Coder
 
Join Date: Aug 2005
Location: Tokyo
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Code should be corrected as below.
vb Code:
  1. If sapConn.Connection.Logon(0, True) <> True Then 'Try Logon
  2. msgbox "CANNOT Log on to SAP"
  3. end if
mas
__________________
Visitez: VBA & SAP RFC Function site - http://sapass.metro.client.jp/index.htm

Last edited by digioz; 05-31-08 at 08:41 AM. Reason: Please use VB code highlighter
Reply With Quote
  #4 (permalink)  
Old 09-29-05, 04:18 PM
Pindento Pindento is offline
New Member
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pindento

There are several reasons that a logon would be unsuccessful - do you guys know if there is a way to get return messages from the Connection attempt to determine if the failed logon was due to:

Client unavailable
user or password not in client
user locked
etc.

Thanks,
Pindento
Reply With Quote
  #5 (permalink)  
Old 10-04-05, 06:42 AM
mas_detokyo mas_detokyo is offline
Newbie Coder
 
Join Date: Aug 2005
Location: Tokyo
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
That's good advice but I don't know if someone has any issues logging on to SAP.
mas
__________________
Visitez: VBA & SAP RFC Function site - http://sapass.metro.client.jp/index.htm
Reply With Quote
  #6 (permalink)  
Old 11-07-05, 06:45 PM
Pindento Pindento is offline
New Member
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
When this line of code is executed:
sapConn.Connection.Logon(0, True) <> True

The SAP logon prompt is displayed:
I want to be able to have the code behave differently if:
1) The user hits "Cancel"
2) The system and/or client is not available
3) The user entered an incorrect password
etc.

I'm not going to be able to do that unless I'm able to capture a message, error, something being returned from the failed Connection - does anyone know a property of Connection or Logon that will provide this info.

Thank you,
Pindento
Reply With Quote
  #7 (permalink)  
Old 11-17-05, 06:23 AM
mas_detokyo mas_detokyo is offline
Newbie Coder
 
Join Date: Aug 2005
Location: Tokyo
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
How about this? You may execute this method just after the SAP connection failure.
Code:
sapConn.Connection.SystemMessages
This calls up error message.
But I don't understand the case - "user hit 'cancel'". Are you going to have your own SAP logon dialog or use standard logon provided by SAP RFC SDK?
If it is latter, I believe server information etc.. will not be given in case the cancel button hit, so you can handle it separately.

Cheers,
mas
__________________
Visitez: VBA & SAP RFC Function site - http://sapass.metro.client.jp/index.htm
Reply With Quote
  #8 (permalink)  
Old 05-31-08, 04:05 AM
komila.it's Avatar
komila.it komila.it is offline
New Member
 
Join Date: May 2008
Location: Gujarat- India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Callin function gives error.

I have successfully login in SAP but while calling RFC function it gives me error " unable to call RFC function"
I have written below code :
vb Code:
  1. Set theFunc = sapObj.Add("ZPOMDRREP")
  2.  
  3. theFunc.Exports("MATNR") = "2000034862"
  4. theFunc.Exports("WERKS") = "5005"
  5. returnFunc = theFunc.Call
  6. die_exception = theFunc.exception
  7.  
  8. If returnFunc = True Then
  9. MsgBox "SAP Data found."
  10. Else
  11. MsgBox "SAP Data NOT found."
  12. End If
pl help me i m after this from a month....
I have registered all ocx file like wdtfuncs, wdobapi etc.. but all in vain.

Thanks in advance
Komila Kalia

Last edited by digioz; 05-31-08 at 08:42 AM. Reason: Please use VB Code Highlighter
Reply With Quote
  #9 (permalink)  
Old 06-25-08, 12:53 AM
kumar.ashok05 kumar.ashok05 is offline
New Member
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes unable to call RFC function

Quote:
Originally Posted by komila.it View Post
I have successfully login in SAP but while calling RFC function it gives me error " unable to call RFC function"
I have written below code :
vb Code:
  1. Set theFunc = sapObj.Add("ZPOMDRREP")
  2.  
  3. theFunc.Exports("MATNR") = "2000034862"
  4. theFunc.Exports("WERKS") = "5005"
  5. returnFunc = theFunc.Call
  6. die_exception = theFunc.exception
  7.  
  8. If returnFunc = True Then
  9. MsgBox "SAP Data found."
  10. Else
  11. MsgBox "SAP Data NOT found."
  12. End If
pl help me i m after this from a month....
I have registered all ocx file like wdtfuncs, wdobapi etc.. but all in vain.

Thanks in advance
Komila Kalia

At first check it that you are login on sap or not
if u do not longin sap the write a code for login from sap

vb Code:
  1. With SAP_Logon
  2. .Client = Client_Name
  3. .Language = EN
  4. .User = User_Name
  5. .Password = User_password
  6. .ApplicationServer =Application_Sever_IP
  7. .SystemNumber = system_number
  8. .TraceLevel = 0
  9. End With
  10.  
  11. With SAP_Functions
  12. .Connection = SAP_Logon.NewConnection
  13. .Connection.Logon 0, True
  14. End With
  15.  
  16. after that export data in SAP RFC Table
  17.  
  18.  
  19. Dim SAP_FunctionBatch As Object
  20.  
  21. Dim SAP_BatchNo As Object, SAP_TblBatchDetail As Object
  22.  
  23.  
  24. Set SAP_FunctionBatch = SAP_Functions.Add("RFC_Name")
  25.  
  26. 'Now SAP_FunctionBatch points to SAP Function Module RFC_Name
  27.  
  28. Set SAP_BatchNo = SAP_FunctionBatch.Exports("Export_Parameter_Field") ' Name of Export parameter field
  29. Set SAP_TblBatchDetail = SAP_FunctionBatch.Tables("ITAB") ' Give table name
  30.  
  31.  
  32. SAP_FunctionBatch.Call

Last edited by digioz; 06-25-08 at 08:54 AM. Reason: Please use Code TAGS!
Reply With Quote
  #10 (permalink)  
Old 04-14-09, 09:00 PM
ohda19 ohda19 is offline
New Member
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
No .connection property

Please help!
I have added in my references the librfc32.dll. Then i declared a variable with Object datatype but when i used that variable why i do not have a .connection property. What am i going to add to have a .connection property. pls help. Thanks!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB 6.0 and VB .NET OMID SOFT Visual Basic 2 05-25-04 02:30 PM
SQL infinite loop problem with VB application Syed Visual Basic 2 05-07-04 10:19 AM
A long-cherished desire of programmers to have the best of visual basic (VB), C and C ebirbals Windows .NET Programming 0 04-12-04 12:09 PM
Post URL Using VB xkenshin Visual Basic 2 01-25-04 11:37 AM
Using C DLL in VB. Function has argument with pointer to array stmoong Visual Basic 0 12-26-03 02:21 AM


All times are GMT -5. The time now is 01:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.