Please also have a look in our OnlineHelp for further information.

n this Article ERPConnect is used in a Powerhell Environment to connect to SAP, extract Data from a table (MAKT) and print it directly to the console in Powershell.

First the librfc32.dll has to be registered. That’s an additional step to the “regular” usage of ERPConnect, where this step is not necessary.

regsvr32 c:\windows\system32\librfc32.dll

Then the following Code is needed with the extension *** .PS1

# --------------------------------------------------------------------------------
# If ERPConnect is registered in the GAC then use the following line
# [Reflection.Assembly]::LoadWithPartialName("ERPConnect20")
# If no is it also possible to load ERPConnect directly
[Reflection.Assembly]::LoadFile("C:\Program Files\ERPConnect\ERPConnect20.dll")

# Set the license key

# Set the connection parameters 
$hostname = "ptmalg"
$systemid = 5
$username = "Babi"
$password = "xxx"
$lang     = "EN"
$client   = "800"

$r3conn = new-object ERPConnect.R3Connection($hostname,$systemid,$username,$password,$lang,$client)
# Open the connection

# Check if the connection is available.

# Read the table MAKT
$ReadTable = new-object ERPConnect.Utils.ReadTable($r3conn)
$ReadTable.RowCount = 100
$ReadTable.AddCriteria("SPRAS = 'EN'")
$ReadTable.TableName = "MAKT"


[System.Data.DataTable]$result = $ReadTable.Result
# Show the RowsCount
# Print out the result on the screen

The call is made directly in Powershell or within Powershell ISE.