Skip to Content
0
Former Member
Mar 09, 2005 at 01:01 PM

How To call RFC by VB Net

56 Views

hi folks,

I have a little problen to call RFC by Vb.Net program.

I using this code:

Public Sub New()

'----

-


'Cria conexão com o SAP

'----

-


'--- Inicio 03/03/2005

Try

If AppSettings("SEAL") = "0" Then

oLogonCtrl = CreateObject("SAP.Logoncontrol.1")

g_oConnection = oLogonCtrl.NewConnection

g_oConnection.System = AppSettings("SYSTEM")

g_oConnection.ApplicationServer = AppSettings("APPSERVER")

g_oConnection.SystemNumber = AppSettings("SYSNUMBER")

g_oConnection.Client = AppSettings("CLIENT")

g_oConnection.Language = AppSettings("LANGUAGE")

g_oConnection.User = AppSettings("USUARIO")

g_oConnection.Password = AppSettings("SENHA")

Else

'Versao debug sem sap, nao carrega objeto SAP

End If

Catch ex As Exception

MessageBox.Show("Erro na inicialização com o SAP::" & ex.Message, "ERRO 01", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

Exit Sub

End Try

'--- fim 03/03/2005

'----

-


End Sub

Public Function Login(ByVal Usuario As String, ByVal Senha As String, ByRef Responsavel As String, ByRef Centro As String) As Boolean

Try

If AppSettings("SEAL") = "0" Then

If g_oConnection.Logon(HWND, True) = True Then

'Conexão feita com sucesso

Dim funcaoSAP As Object

Dim osap2 As Object

osap2 = CreateObject("SAP.Functions")

osap2.Connection = g_oConnection

funcaoSAP = osap2.add("Z_RFC_LOGIN")

funcaoSAP.Exports("I_COD") = Usuario

If funcaoSAP.call Then

Dim ativo As Integer

Dim strativo As Object

strativo = funcaoSAP.Imports("E_RESULT")

ativo = strativo.value

If ativo > 0 Then

MessageBox.Show("Usuario não esta ativado!", "Erro 04", MessageBoxButtons.OK, _

MessageBoxIcon.Error)

Return False

End If

Responsavel = funcaoSAP.imports("E_NOME").value

Centro = funcaoSAP.imports("E_CENTRO").value

Else

MessageBox.Show("Erro durante login da aplicação", "Erro 03", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

Return False

End If

osap2.Connection.Logoff()

osap2 = Nothing

g_oConnection = Nothing

Return True

Else

'Erro na conexão e na validação de dados com o SAP

MessageBox.Show("Usuário ou senha inválidos para acesso ao sistema", "ERRO 02", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

Return False

End If

Else

'Debug sem SAP

Responsavel = "SEAL"

Centro = "SEAL"

Return True

End If

Catch ex As Exception

MessageBox.Show("Erro Login", "ERRO LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Error)

Return False

End Try

End Function

Public Function BuscaTransporte(ByVal Centro As String, ByVal Transporte As Integer) As Boolean

Try

Dim funcaoSAp2 As Object

Dim osap As Object

If AppSettings("SEAL") = "0" Then

If Conecta() Then

osap = CreateObject("SAP.Functions")

osap.Connection = g_oConnection

funcaoSAp2 = osap.add("Z_RFC_OBTEM_DADOS_FORNEC")

funcaoSAp2.Exports("I_CENTRO") = Centro

funcaoSAp2.Exports("I_NRSEQUENCIAL") = 1

Dim tabH As Object

Dim tabi As Object

tabH = funcaoSAp2.tables.Item("IT_DADOS_HEADER")

tabH.freetable()

tabH.refresh()

tabi = funcaoSAp2.tables.Item("IT_DADOS_ITEM")

tabi.freetable()

tabi.refresh()

If funcaoSAp2.call Then

Dim msg As String

Dim res As Integer

res = funcaoSAp2.imports("E_RESULT").value

If res > 0 Then

msg = funcaoSAp2.imports("E_MESSAGE_ERROR")

MessageBox.Show(msg, "RESULT 1", MessageBoxButtons.OK, _

MessageBoxIcon.Exclamation)

Exit Function

End If

Dim linhas As Integer

For linhas = 1 To tabH.RowCount

transpor.BUTXT = tabH(linhas, "BUTXT")

transpor.STCD1 = tabH(linhas, "STCD1")

transpor.NAME1 = tabH(linhas, "NAME1")

transpor.NFTOT = tabH(linhas, "NFTOT")

transpor.STRAS = tabH(linhas, "STRAS")

Next

ReDim Itens(tabi.RowCount)

For linhas = 1 To tabi.RowCount

Itens(linhas).IT_DADOS_ITEM = tabi(linhas, "IT_DADOS_ITEM")

Itens(linhas).VBELN = tabi(linhas, "VBELN")

Itens(linhas).NAME1 = tabi(linhas, "NAME1")

Itens(linhas).STRAS = tabi(linhas, "STRAS")

Itens(linhas).ORT01 = tabi(linhas, "ORT01")

Itens(linhas).ORT02 = tabi(linhas, "ORT02")

Itens(linhas).REGIO = tabi(linhas, "REGIO")

Next

'transpor = funcaoSAp.imports("IT_DADOS_HEADER")

'Itens = funcaoSAp.imports("IT_DADOS_ITEM")

'transpor.BUTXT = funcaoSAp.imports("BUTXT")

'transpor.STCD1 = funcaoSAp.imports("STCD1")

'transpor.NAME1 = funcaoSAp.imports("NAME1")

'transpor.NFTOT = funcaoSAp.imports("NFTOT")

'transpor.STRAS = funcaoSAp.imports("STRAS")

End If

End If

End If

osap.Connection.Logoff()

Catch ex As Exception

MessageBox.Show("Erro na Busca de carga! ( " & ex.Message & " )", "ERRO RFC", MessageBoxButtons.OK, _

MessageBoxIcon.Error)

Return False

End Try

End Function

The proccess running Ok in Loggin Function for my program but in the function BuscaTransporte when I call it in the mmoment witch I send parameters to RFC by exports metod the error is show to me "it´s not member of the structure "EC01".

Can you help me to fix it