Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / Visual Basic
Article

Open Table Access to SAP R/3 with .NET

Rate me:
Please Sign up or sign in to vote.
4.20/5 (5 votes)
24 Aug 2003 109.4K   555   39   7
Retrieve R/3 Table Contents or ABAP functionality

Sample Image - SAPLogonNet.jpg

Introduction

Using the SAP.Connector is very hard to retrieve real table contents of a R/3 Database and logon to a SAP-System. 

SAPLink provides an easy way to get SAP-Data from any System with RFC-functionality.

Using the code

Download and install SapLink_Trial_Setup.msi 
Open the SAPLink Demo Project from the Desktop 

It is necessary to have a SAPLogon.ini, which describes the available SAP-Servers

VB.NET
Private Sub btnStart_Click(ByVal sender As System.Object, _<BR>                           ByVal e As System.EventArgs) _
                Handles btnStart.Click

  Dim sOut As String
  Dim oSAP As New SAPLink.Login.Component()

  'Show LogonScreen
  If Not oSAP.Connected Then oSAP.Login()

  If oSAP.Connected Then

    'Get Tablenames with "Finanzkreise" in description
    sOut = oSAP.ABAP_ReadTables(, "Finanzkreise")
    MsgBox(sOut, MsgBoxStyle.Information, _
           "Get Tablenames with 'Finanzkreise' in description")

    'Executing existing ABAP and write Output to File
    Try
      Dim oStreamWriter As StreamWriter = New StreamWriter("c:\temp.txt", True)
      oStreamWriter.Write(oSAP.ExecuteABAPfromFile("<A href="file:///c:/abap.txt">c:\abap.txt</A>"))
      oStreamWriter.Close()
      If oSAP.ABAPError <> "" Then MsgBox(oSAP.ABAPError)
    Catch ex As Exception
    End Try
   
    MsgBox("c:\temp.txt written", MsgBoxStyle.Information, _
           "Executing existing ABAP and write Output to File")

    'SQL-Select on a SAP-Table with XML-Output
    oSAP.MaxReturnRows = 5
    oSAP.SkipRows = 0
    sOut = oSAP.ExecuteToXML("SELECT * FROM MARA WHERE ERSDA < SY-DATUM")
    MsgBox(sOut, MsgBoxStyle.Information, _
           "SQL-Select on a SAP-Table with XML-Output")

    'SQL-Select on a SAP-Table with Dataset-Output
    sOut = ""
    Dim a As Integer

    Dim dt As New DataTable()
    dt = oSAP.Execute("SELECT * FROM T000 WHERE MTEXT <> 'EarlyWatch'")
    For a = 0 To dt.Rows.Count - 1
      sOut += dt.Rows(a).Item("MANDT") & "-" & dt.Rows(a).Item("MTEXT") & vbCrLf
    Next
    MsgBox(sOut, MsgBoxStyle.Information, _
           "SQL-Select on a SAP-Table with Dataset-Output")

    'Execute ABAP on the fly
    Dim sb As New System.Text.StringBuilder()

    sb.Append("report ZSAPCON no standard page heading line-size 255." & vbCrLf)
    sb.Append("TABLES: DD02T." & vbCrLf)
    sb.Append("DATA: COUNT TYPE I." & vbCrLf)
    sb.Append("SELECT * FROM DD02T WHERE DDLANGUAGE = SY-LANGU AND " & vbCrLf)
    sb.Append("         DDTEXT LIKE '%PLANT%'." & vbCrLf)
    sb.Append("  WRITE: /  DD02T-TABNAME, ',' , DD02T-DDTEXT." & vbCrLf)
    sb.Append("ENDSELECT." & vbCrLf)

    sOut = oSAP.ExecuteABAP(sb.ToString)
    MsgBox(sOut, MsgBoxStyle.Information, "Execute ABAP on the fly")

  Else
    MsgBox(oSAP.ABAPError)
  End If
End Sub

Points of Interest

Here you see a message box output from the code above:

Sample Image - maximum width is 600 pixels


Download more SAP-Developer OCX for VB 6 and ADO/DAO from http://www.sap-web.de

Notes

The Saplink.dll is in Version 1.0.0 only for testing.  DO NOT de-comment:

VB.NET
'For Test purposes only to avoid the Trial-Messagebox
'oSAP.I_use_this_control_without_Legal_Copyright = True        

in any other case visit http://www.ibis-thome.com or mailto: frede@ibisness.de

History

25 Aug 2003 - updated demo app.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCall RFC Pin
João da Costa from Brazil20-Jul-07 8:51
João da Costa from Brazil20-Jul-07 8:51 
NewsSAP Connector for Visual Studio 2005 Is Available! Pin
Pablo Telmo29-Jun-06 11:33
Pablo Telmo29-Jun-06 11:33 
GeneralDownload Link changed to http://link4sap.inetconnector.com/ Pin
dfrede18-Aug-05 22:50
dfrede18-Aug-05 22:50 
GeneralServerSAP Pin
James Vago18-Aug-05 5:12
James Vago18-Aug-05 5:12 
Generaldownload Pin
James Vago18-Aug-05 4:40
James Vago18-Aug-05 4:40 
Generaldownload Pin
James Vago18-Aug-05 4:40
James Vago18-Aug-05 4:40 
GeneralSaplogon.ini Pin
rmuthiahsamy5-Feb-04 20:43
rmuthiahsamy5-Feb-04 20:43 
Hi
There is no configuration detail for saplogon.ini

Please can someone explain the configuration.

[Configuration]
SessManNewKey=2
[MSWinPos]
NormX=519
NormY=246
[Router]
Item1=
[Router2]
Item1=
[RouterChoice]
Item1=0
[Server]
Item1=PUBLIC
[Database]
Item1=00
[System]
Item1=3
[Description]
Item1=PRD [PUBLIC]
[Address]
Item1=129.132.122.198
[MSSysName]
Item1=PRD
[MSSrvName]
Item1=sap-dbs.ethz.ch
[MSSrvPort]
Item1=sapmsPRD
[SessManKey]
Item1=1
[SncName]
Item1=
[SncChoice]
Item1=-1
[Codepage]
Item1=1100
[CodepageIndex]
Item1=-1
[Origin]
Item1=MS_SEL_GROUPS
[LowSpeedConnection]
Item1=0
[Utf8Off]
Item1=0

Thanks
R. Muthiah Samy

Muthiah Samy

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.