Tip

Open table access to SAP R/3 with .NET

Retrieving table content with the SAP .NET connector is very difficult. Not so with this handy little dll!
'  SAPLink.NET / SAPLink.ocx / ASPSaplink.dll    
 
 
2002-2003 SAPLink - Solutions for your systems  
 
 

.NET Example 


Imports System.IO
Imports System.Data.SqlClient 
Imports SAPLINK 
Public Class Form2 

Inherits System.Windows.Forms.Form 
Private oSAP As New SAPLINK.Component 


Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 
btnStart.Click  
Dim sOut As String 
'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()  
    I    f oSAP.ABAPError <> "" Then MsgBox(oSAP.ABAPError)  
    Catch ex As Exception  
    End Try  
    MsgBox("c:temp.txt written", MsgBoxStyle.Information, "Executing existing ABAP and write 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,

    Requires Free Membership to View

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 Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click If oSAP.Connected Then oSAP.CloseConnection() End End Sub

This was first published in June 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.