
#-Begin-----------------------------------------------------------------
$ABAPCode = @"
"-Begin-----------------------------------------------------------------
Report zTest Line-Size 256.
Write: 'Hello World from'.
Write: sy-sysid.
"-End-------------------------------------------------------------------
"@
#-Sub Load-NCo--------------------------------------------------------
Function Load-NCo {
[String]$ScriptDir = $PSScriptRoot
If ([Environment]::Is64BitProcess) {
[String]$Path = $ScriptDir + "\x64\"
} Else {
[String]$Path = $ScriptDir + "\x86\"
}
[String]$File = $Path + "sapnco.dll"; Add-Type -Path $File
$File = $Path + "sapnco_utils.dll"; Add-Type -Path $File
}
#-Function Get-Destination--------------------------------------------
Function Get-Destination {
#-Connection parameters---------------------------------------------
$cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add("NAME", "Test")
$cfgParams.Add("ASHOST", "NSP")
$cfgParams.Add("SYSNR", "00")
$cfgParams.Add("CLIENT", "001")
$cfgParams.Add("USER", "BCUSER")
$cfgParams.Add("PASSWD", "minisap")
Return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Sub Run-ABAP--------------------------------------------------------
Function Run-ABAP () {
$destination = Get-Destination
#-Metadata----------------------------------------------------------
$rfcFunction = `
$destination.Repository.CreateFunction("RFC_ABAP_INSTALL_AND_RUN")
#-Call function module----------------------------------------------
Try {
[SAP.Middleware.Connector.IRfcTable]$Table = `
$rfcFunction.GetTable("PROGRAM")
$ABAPLines = $ABAPCode -Split [System.Environment]::NewLine
ForEach($ABAPLine In $ABAPLines){
$Table.Append()
$Table.SetValue("LINE", $ABAPLine)
}
$rfcFunction.Invoke($destination)
[SAP.Middleware.Connector.IRfcTable]$Table = `
$rfcFunction.GetTable("WRITES")
ForEach ($Line In $Table) {
Write-Host $Line.GetValue("ZEILE")
}
} Catch {
Write-Host "Exception occured:`r`n" $_.Exception.Message
}
}
#-Sub Main------------------------------------------------------------
Function Main () {
If ($PSVersionTable.PSVersion.Major -ge 5) {
Load-NCo
Run-ABAP
}
}
#-Main----------------------------------------------------------------
Main
#-Error routine-------------------------------------------------------
Trap {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > $Null
[Void] [System.Windows.Forms.MessageBox]::Show( `
$_.Exception.GetType().FullName + `
[System.Environment]::NewLine + [System.Environment]::NewLine + `
$_.Exception.Message, "An Error Occurred", 0)
Exit
}
#-End-------------------------------------------------------------------
#-Begin-----------------------------------------------------------------
$ABAPCode = @"
"-Begin-----------------------------------------------------------------
"
" Important hint: Line-Size of the Report statement must be less or
" equal 256.
"
" Important hint: The length of a code line may not exceed 72
" characters.
"
"-----------------------------------------------------------------------
Report zTest Line-Size 256.
Data:
lt_SFlight Type Standard Table Of SFLIGHT,
lv_Price Type String
.
Field-Symbols:
Type SFLIGHT
.
Select *
Into Table lt_SFlight
From SFLIGHT
Where CARRID = 'LH'
.
Loop At lt_SFlight Assigning .
lv_Price = <ls_SFlight>-Price. Condense lv_Price.
Write: /
<ls_SFlight>-CarrID, ';', <ls_SFlight>-ConnID, ';',
<ls_SFlight>-FLDate, ';', lv_Price, ';',
<ls_SFlight>-PlaneType.
EndLoop.
"-End-------------------------------------------------------------------
"@
#-Sub LoadNCo-----------------------------------------------------------
Function LoadNCo {
[String]$ScriptDir = $PSScriptRoot
If ([Environment]::Is64BitProcess) {
[String]$Path = $ScriptDir + "\x64\"
} Else {
[String]$Path = $ScriptDir + "\x86\"
}
[String]$File = $Path + "sapnco.dll"; Add-Type -Path $File
$File = $Path + "sapnco_utils.dll"; Add-Type -Path $File
}
#-Function Get-Destination----------------------------------------------
Function Get-Destination {
#-Connection parameters-----------------------------------------------
$cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add("NAME", "TEST")
$cfgParams.Add("ASHOST", "NSP")
$cfgParams.Add("SYSNR", "00")
$cfgParams.Add("CLIENT", "001")
$cfgParams.Add("USER", "BCUSER")
$cfgParams.Add("PASSWD", "minisap")
Return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Sub RunABAP-----------------------------------------------------------
Function RunABAP {
$destination = Get-Destination
#-Metadata------------------------------------------------------------
$rfcFunction = `
$destination.Repository.CreateFunction("RFC_ABAP_INSTALL_AND_RUN")
#-Call function module------------------------------------------------
[SAP.Middleware.Connector.IRfcTable]$Table = `
$rfcFunction.GetTable("PROGRAM")
$ABAPLines = $ABAPCode -Split [System.Environment]::NewLine
ForEach($ABAPLine In $ABAPLines){
$Table.Append()
$Table.SetValue("LINE", $ABAPLine)
}
$rfcFunction.Invoke($destination)
[SAP.Middleware.Connector.IRfcTable]$Table = `
$rfcFunction.GetTable("WRITES")
$arrSFlight = New-Object System.Collections.Generic.List[Object]
ForEach ($Row In $Table) {
[String]$Line = $Row
$Elements = $Line.Replace("FIELD ZEILE=", "").Split(";")
$SFlight = New-Object PSObject -Property @{
CARRID = $Elements[0].Trim()
CONNID = $Elements[1].Trim()
FLDATE = $Elements[2].Trim()
PRICE = $Elements[3].Trim()
PLANETYPE = $Elements[4].Trim()
}
$arrSFlight.Add($SFlight)
}
$arrSFlight | Out-GridView -Title "SFLIGHT"
}
#-Sub Main--------------------------------------------------------------
Function Main {
If ($PSVersionTable.PSVersion.Major -ge 5) {
LoadNCo
RunABAP
}
}
#-Main------------------------------------------------------------------
Main
#-Error routine---------------------------------------------------------
Trap {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > $Null
[Void] [System.Windows.Forms.MessageBox]::Show( `
$_.Exception.GetType().FullName + `
[System.Environment]::NewLine + [System.Environment]::NewLine + `
$_.Exception.Message, "An Error Occurred", 0)
Exit
}
#-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |