Quantcast
Channel: Jive Syndication Feed
Viewing all articles
Browse latest Browse all 10881

How to use PowerShell Script Language via dotNET Connector (NCo) in SAP Context

$
0
0

Hello community,

 

PowerShell is in standard available on any Windows 7 and higher and it bases on dotNET. You can find a lot of information here. PowerShell offers a good integrated scripting environment (ISE), so it is very easy to code and test scripts.

 

SAP offers with the dotNET Connector (NCo) an easy way to use the SAP backend in this environment. You can find NCo here. The NCo is primarly used with C# language and you can find a lot of examples.

 

I combine the possibilities of PowerShell and NCo, to show how easy and fast you can create a communication between your presentation server and the application server. The first example shows only the version number of the NCo:

 

#-Begin-----------------------------------------------------------------

 

  #-Function Get-NCoVersion---------------------------------------------

    Function Get-NCoVersion {

 

      #-Loads NCo libraries---------------------------------------------

        $rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco.dll")

        $rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco_utils.dll")

 

 

      #-Gets the version of NCo-----------------------------------------

        $Version =

          [SAP.Middleware.Connector.SAPConnectorInfo]::get_Version()

        $PatchLevel =

          [SAP.Middleware.Connector.SAPConnectorInfo]::get_KernelPatchLevel()

        $SAPRelease =

          [SAP.Middleware.Connector.SAPConnectorInfo]::get_SAPRelease()

 

      #-Shows the result------------------------------------------------

        Write-Host "`r`nNCo verion:" $Version

        Write-Host "Patch Level:" $PatchLevel

        Write-Host "SAP Release:" $SAPRelease

 

    }

 

  #-Main----------------------------------------------------------------

    Get-NCoVersion

 

#-End-------------------------------------------------------------------

 

001.JPG

The second example shows how to call a function module, with import and export parameters:

 

#-Begin-----------------------------------------------------------------

 

  #-Function Invoke-SAPFunctionModule-----------------------------------

    Function Invoke-SAPFunctionModule {

 

      #-Loads NCo libraries---------------------------------------------

        $rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco.dll")

        $rc = [Reflection.Assembly]::LoadFile("C:\NCo\sapnco_utils.dll")

 

 

      #-Sets connection parameters--------------------------------------

        $cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters

        $cfgParams.Add("NAME", "TEST")

        $cfgParams.Add("ASHOST", "ABAP")

        $cfgParams.Add("SYSNR", "00")

        $cfgParams.Add("CLIENT", "001")

        $cfgParams.Add("USER", "BCUSER")

        $cfgParams.Add("PASSWD", "minisap")

 

      #-Destination-----------------------------------------------------

        $destination =

          [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)

 

      #-Metadata--------------------------------------------------------

      [SAP.Middleware.Connector.IRfcFunction]$rfcFunction =

        $destination.Repository.CreateFunction("STFC_CONNECTION")

 

      #-Sets import parameter-------------------------------------------

        $rfcFunction.SetValue("REQUTEXT", "Hello World from PowerShell")

 

      #-Calls function module-------------------------------------------

        $rfcFunction.Invoke($destination)

 

      #-Shows export parameters-----------------------------------------

        Write-Host $rfcFunction.GetValue("ECHOTEXT")

        Write-Host $rfcFunction.GetValue("RESPTEXT")

 

    }

 

  #-Main----------------------------------------------------------------

    Invoke-SAPFunctionModule

      

#-End-------------------------------------------------------------------

 

002.JPG

The PowerShell ISE offers a lot of additional things, e.g. like code completion.

 

003.jpg

 

With PowerShell and NCo you can easily create client functions. All you have to do is to copy the necessary NCo libraries on your presentation server. PowerShell is on Windows available and so you can start up quickly.

 

Enjoy it.

 

Cheers

Stefan


Viewing all articles
Browse latest Browse all 10881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>