Cmdlets for SAP ERP

Build 24.0.9060

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our SAPERP Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module SAPERPCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module SAPERPCmdlets;

You can then use the Connect-SAPERP cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-SAPERP -Host 'sap.mydomain.com' -User 'EXT90033' -Password 'xxx' -Client '800' -SystemNumber '09' -ConnectionType 'Classic'

Connecting with the RFC APIs

The CData Cmdlets PowerShell Module for SAP ERP uses the SAP RFC interface to connect to an SAP system. The ConnectionType specifies the RFC API you want to use to connect.

You must obtain the SAP libraries corresponding to your RFC API to connect.

Required RFCs

The RFCs used by the CData Cmdlets PowerShell Module for SAP ERP are listed as follows. If any listed below are not available, some or all functionality may not work. T-Code SE37 may be used to view available function modules in SAP.

  • DDIF_FIELDINFO_GET
  • RFC_GET_FUNCTION_INTERFACE
  • RFC_GET_STRUCTURE_DEFINITION
  • RFC_GET_SYSTEM_INFO
  • RFC_GET_UNICODE_STRUCTURE
  • RFC_READ_TABLE
  • SLDAG_CHECK_FOR_UNICODE

Connecting to SAP ERP

Set the following to connect:

  • Host: The host name of the target system. Host names can be regular host names defined in a hosts file, an IP address like 123.123.123.123, or an SAProuter address such as "/H/hostname/S/port/H/host/S/port/ ..."
  • User: The user that is authenticating to the SAP system.
  • Password: The password used to authenticate to the SAP system.
  • Client: The client authenticating to the SAP system.
  • SystemNumber: The number by which the target system is defined.
  • Language: The ISO 639-1 language code you use to log into SAP ERP. The default is "EN".

To connect to a machine different from the Host machine, substitute Host with the following:

  • GatewayHost: The gateway host you wish to connect to. If not specified, the provider will attempt to connect to the SAP system specified by Host.
  • GatewayService: The gateway service you wish to connect to. If not specified, the SAP system will use the default "sapgw##" where the "##" is the SystemNumber.

To connect to a distributed system or systems with other configurations, see Fine-Tuning Data Access.

Certificates

In addition to User and Password, the CData Cmdlets PowerShell Module for SAP ERP also supports certificate authentication. To use certificate authentication, set the X509Certificate connection property to either point to a file that contains an X509 certificate in PEM format, or the PEM blob directly used for authentication during SAP Logon. In addition to setting X509Certificate, you will need to specify the appropriate SNC connection properties. The SNC connection properties are described under Fine-Tuning Data Access.

Retrieving Data

The Select-SAPERP cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-SAPERP -Connection $conn -Table "MARA" -Columns @("MANDT, MATNR") -Where "ERNAM='BEHRMANN'"
The Invoke-SAPERP cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-SAPERP -Connection $conn -Table MARA -Where "ERNAM = 'BEHRMANN'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myMARAData.csv -NoTypeInformation

You will notice that we piped the results from Select-SAPERP into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-SAPERP -Host 'sap.mydomain.com' -User 'EXT90033' -Password 'xxx' -Client '800' -SystemNumber '09' -ConnectionType 'Classic'
PS C:\> $row = Select-SAPERP -Connection $conn -Table "MARA" -Columns (MANDT, MATNR) -Where "ERNAM = 'BEHRMANN'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "MARA",
  "Columns":  [

  ],
  "MANDT":  "MyMANDT",
  "MATNR":  "MyMATNR"
} 

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060