04-24-2007 6:32 AM
hi All,
i tried to connect sap from vb as .
my vb code is ( i write this vb code on form load event)
Dim Funct, MyFunc As Object
Dim oTable, oRow As Object
Dim Result As Boolean
Set Funct = CreateObject("SAP.Functions")
Funct.Connection.System = "BSSLDEV"
Funct.Connection.client = "500"
Funct.Connection.user = "username"
Funct.Connection.Password = "pwd"
Funct.Connection.Language = "EN"
If Funct.Connection.logon(0, True) <> True Then
MsgBox "Login error"
Exit Sub
End If
Set MyFunc = Funct.Add("Z_TEST")
Set oTable = MyFunc.Tables("DATA")
Result = MyFunc.Call
now it gave login error.
can you gave me any more solution or tel where i'm wrong.
what should be in
Funct.Connection.System =
system name / it ip / or something else
thanks
mukesh
04-24-2007 6:34 AM
04-24-2007 6:36 AM
hi,
thanks
but i don't know RFC will u gave me any prog exp. by which i learn.
mukesh
04-24-2007 6:35 AM
IP address means u have to give ur Application server IP address .
provide IP = 10.10.10.10 like that, then only ur VB can identity SAP systems.
Regards
prabhu
04-24-2007 6:39 AM
hi,
by putting ip it gave the same
login error
is their any need / way to check sap connectivity like dsn ( as we do in sql server )
mukesh
04-24-2007 6:45 AM
Hi,
Try this code. this will show the login screen and u can give the client, useid and password there and login.
' Declaration for the necessary objects
Dim objBAPICortrol, objConnection, objABAP As Object
Dim objProgram, objWrites As Table
Dim objMode, objProgramName As Object
Dim v_count As Integer
Dim v_login As Boolean
-
Sub Execute_ABAP_Report_Click()
On Error Resume Next
' Setting the necessary variables for R/3 connection
Set objBAPICortrol = CreateObject("SAP.Functions")
Set objConnection = objBAPICortrol.Connection
' Establish a connection
If objConnection.Logon(0, False) Then
MsgBox "Connection Established"
End If
If objConnection <> Null Then
v_login = True
End If
End Sub
Regards,
Ajith V
04-24-2007 7:03 AM
thanks
connection has been established.
but by commnet this line Dim objProgram, objWrites As Table
now can u help me in
1. how can i access sap table data in resultset to make my own report
( how run sql statements and inner join statements)
2. how pass / call sap screen std. t-code
e.g i make my own screen in vb after user feed data i want that data to populated in std. t-code ot u can i want to call bdc to post data in sap
thanks,
mukesh
04-24-2007 7:35 AM
Hi,
You can use BAPI's for accessing the SAP tables, and inside the bapi's you can use your business logic to get the datas.
please look into the PDF BAPI ActiveX Controls, BAPI Programming guide and BAPI User Guide for more information on how to use a BAPI from VB to interact with the R/3 system.
http://www.easymarketplace.de/online-pdfs.php
Regards,
Ajith V
04-24-2007 6:39 AM
Hi Mukesh,
Try this sample code.
Option Explicit
Private Sub Command1_Click()
'Dim Foo As RFCSampObj ' Due to an acknowledged problem in MTS
Dim Foo As Object ' we Dim Foo as Object instead of as RFCSampObj
Dim searchterm As String
Dim custlist As Recordset
Set Foo = CreateObject("RFCSampObj.RFCSampObj.1")
Foo.Destination = "IDES"
'Foo.Client = "800"
'Foo.Language = "E"
'Foo.UserID = "test"
'Foo.Password = "pw"
If Not Foo Is Nothing Then
searchterm = Text1.Text
'Unfortunately RFC_CUSTOMER_GET does not convert
' a SPACE selction into a * so we do it here....
If IsEmpty(searchterm) Then searchterm = "*"
On Error Resume Next
Call Foo.GetCustList(searchterm, "", custlist)
If Err.Number = 0 Then
If Not custlist Is Nothing Then
custlist.MoveFirst
While Not custlist.EOF
Debug.Print "------------------"
Debug.Print "custlist.Fields(name1) " &
custlist.Fields("NAME1")
Debug.Print "custlist.Fields(stras) " &
custlist.Fields("STRAS")
Debug.Print "custlist.Fields(ort01) " &
custlist.Fields("ORT01")
Debug.Print "custlist.Fields(pstlz) " &
custlist.Fields("PSTLZ")
Debug.Print "custlist.Fields(telf1) " &
custlist.Fields("TELF1")
Debug.Print "custlist.Fields(telfx) " &
custlist.Fields("TELFX")
custlist.MoveNext
Wend
Else
Debug.Print "ERROR: custlist is Nothing"
End If
Else
Debug.Print "ERROR" & Err.Description
MsgBox Err.Description, vbCritical, "Error:"
End If
Else
Debug.Print "Foo is nothing"
MsgBox "Foo is nothing"
End If
End Sub
Private Sub Command2_Click()
'Dim Foo As RFCSampObj ' Due to an acknowledged problem in MTS
Dim Foo As Object ' we Dim Foo as Object instead of as RFCSampObj
Dim rs As Recordset
Dim HeaderIn As Recordset
Dim ItemsIn As Recordset
Dim Partners As Recordset
Dim OrderNumber As String
Dim BapiReturn As Recordset
Dim SoldTo As Recordset
Dim ShipTo As Recordset
Dim Payer As Recordset
Dim ItemsOut As Recordset
'Input tables can be crafted in two different ways:
' - either using the DimAsXXXX method which returns a fully
' described but empty Recordset.
' - or using the AdvancedDataFactory to craft up a disconnected
' Recordset.
' An example of the later is shown with the Partners Table
' the remaining input tables are crafted with the dim as.
Dim adf As Object
' Describe the shape of a disconnected recordset
Dim vrsShape(1)
Dim vrsParvw(3)
Dim vrsKunnr(3)
vrsParvw(0) = "PARTN_ROLE"
vrsParvw(1) = CInt(8)
vrsParvw(2) = CInt(2)
vrsParvw(3) = False
vrsKunnr(0) = "PARTN_NUMB"
vrsKunnr(1) = CInt(8)
vrsKunnr(2) = CInt(10)
vrsKunnr(3) = False
vrsShape(0) = vrsParvw
vrsShape(1) = vrsKunnr
' Create a disconnected recordset to pass as an input
Set adf = CreateObject("RDSServer.DataFactory")
If adf Is Nothing Then
MsgBox "ADF == NOTGHING"
End If
Set Partners = adf.CreateRecordSet(vrsShape)
Set Foo = CreateObject("RFCSampObj.RFCSampObj.1")
If Not Foo Is Nothing Then
' Get an empty recordset which will be used as input in
CreateOrder call
Call Foo.DimHeader(HeaderIn)
HeaderIn.AddNew
HeaderIn.Fields("DOC_TYPE") = "TA"
HeaderIn.Fields("SALES_ORG") = "1000"
HeaderIn.Fields("DISTR_CHAN") = "10"
HeaderIn.Fields("DIVISION") = "00"
HeaderIn.Fields("PURCH_NO") = "SM-1177-3"
HeaderIn.Fields("INCOTERMS1") = "CPT"
HeaderIn.Fields("INCOTERMS2") = "Hamburg"
HeaderIn.Fields("PMNTTRMS") = "ZB01"
HeaderIn.Update
Call Foo.DimItems(ItemsIn)
ItemsIn.AddNew
ItemsIn.Fields("MATERIAL") = "R-1120"
ItemsIn.Fields("PLANT") = "1200"
ItemsIn.Fields("REQ_QTY") = 2000
ItemsIn.Update
Partners.AddNew
Partners.Fields("PARTN_ROLE") = "AG"
Partners.Fields("PARTN_NUMB") = "0000001177"
Partners.Update
'set logon information
Foo.Destination = "IDES"
'Foo.Client = "800"
'Foo.Language = "E"
'Foo.UserID = "test"
'Foo.Password = "pw"
Call Foo.OrderCreate(HeaderIn, _
ItemsIn, _
Partners, _
OrderNumber, _
SoldTo, _
ShipTo, _
Payer, _
ItemsOut, _
BapiReturn)
Debug.Print "OrderNumber" & OrderNumber
If BapiReturn Is Nothing Then
MsgBox "BapiReturn is Nothing"
Else
BapiReturn.MoveFirst
Debug.Print "BapiReturn.Type...." & BapiReturn.Fields("TYPE")
Debug.Print "BapiReturn.Code...." & BapiReturn.Fields("CODE")
Debug.Print "BapiReturn.Message." & BapiReturn.Fields
("MESSAGE")
Debug.Print "BapiReturn.LogNo..." & BapiReturn.Fields
("LOG_NO")
Debug.Print "BapiReturn.LogMsgNo" & BapiReturn.Fields
("LOG_MSG_NO")
End If
Else
MsgBox "Foo is nothing"
End If
End Sub
Private Sub Command3_Click()
'Dim Foo As RFCSampObj ' Due to an acknowledged problem in MTS
Dim Foo As Object ' we Dim Foo as Object instead of as RFCSampObj
Dim SalesOrders As Recordset
Dim BapiReturn As Recordset
Set Foo = CreateObject("RFCSampObj.RFCSampObj.1")
If Not Foo Is Nothing Then
'set logon information
Foo.Destination = "IDES"
'Foo.Client = "800"
'Foo.Language = "E"
'Foo.UserID = "test"
'Foo.Password = "pw"
On Error Resume Next
Call Foo.GetCustomerOrders(CustomerNumber.Text, _
SalesOrg.Text, _
, , , , _
BapiReturn, _
SalesOrders)
If Err.Number = 0 Then
If Not SalesOrders Is Nothing Then
SalesOrders.MoveFirst
While Not SalesOrders.EOF
Debug.Print "------------------"
Debug.Print "SalesOrders.Fields(SD_DOC).... " &
SalesOrders.Fields("SD_DOC")
Debug.Print "SalesOrders.Fields(ITM_NUMBER) " &
SalesOrders.Fields("ITM_NUMBER")
Debug.Print "SalesOrders.Fields(MATERIAL).. " &
SalesOrders.Fields("MATERIAL")
Debug.Print "SalesOrders.Fields(REQ_QTY)... " &
SalesOrders.Fields("REQ_QTY")
Debug.Print "SalesOrders.Fields(NAME)...... " &
SalesOrders.Fields("NAME")
Debug.Print "SalesOrders.Fields(NET_VALUE). " &
SalesOrders.Fields("NET_VALUE")
Debug.Print "SalesOrders.Fields(PURCH_NO).. " &
SalesOrders.Fields("PURCH_NO")
SalesOrders.MoveNext
Wend
Else
Debug.Print "ERROR: SalesOrders is Nothing"
End If
If BapiReturn Is Nothing Then
MsgBox "BapiReturn is Nothing"
Else
BapiReturn.MoveFirst
Debug.Print "BapiReturn.Type...." & BapiReturn.Fields
("TYPE")
Debug.Print "BapiReturn.Code...." & BapiReturn.Fields
("CODE")
Debug.Print "BapiReturn.Message." & BapiReturn.Fields
("MESSAGE")
Debug.Print "BapiReturn.LogNo..." & BapiReturn.Fields
("LOG_NO")
Debug.Print "BapiReturn.LogMsgNo" & BapiReturn.Fields
("LOG_MSG_NO")
End If
Else
Debug.Print "ERROR"
MsgBox Err.Description, vbCritical, "Error:"
End If
Else
MsgBox "Foo is nothing"
End If
End Sub
04-24-2007 6:49 AM
helo,
i tried but still not connect.
now i see in run command i type
198.167.0.2 then it show network not found
but by using ping command it reply.
is it may be the prob.,now how i solved this prob.
mukesh