65.9K
CodeProject is changing. Read more.
Home

Open Table Access to SAP R/3 with .NET

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.20/5 (5 votes)

May 1, 2003

viewsIcon

109751

downloadIcon

555

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

Private Sub btnStart_Click(ByVal sender As System.Object, _
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("c:\abap.txt")) 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:

'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.