Skip to Content

Hello community,

SAP offers an RFC enabled FM to get information about the RFC context, it is RFC_GET_ATTRIBUTES. It delivers interesting information which can be used to analyze error situations. To call this function module I use CCo. Below two examples, the first in PowerShell the second in VBScript, how to use this FM.

Enjoy it.

Cheers
Stefan

 

PowerShell Example

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

  #-Variables-----------------------------------------------------------
    $RFC_OK = 0
    $VarByRef = -1

  #-Includes------------------------------------------------------------
    ."C:\Dummy\COM.ps1"

  #-Function Get-RFCAttributes------------------------------------------
    Function Get-RFCAttributes {
      param([String] $FMName)

      $SAP = $null
      $SAP = Create-Object "COMNWRFC"
      if ($SAP -eq $null) {
        Break
      }

      $Argument = @("ASHOST=ABAP, SYSNR=00, CLIENT=001, USER=BCUSER")
      $hRFC = Invoke-Method $SAP "RfcOpenConnection" $Argument
      if ($hRFC -eq 0) {
        Free-Object $SAP
        Remove-Variable SAP
        Break
      }

      $Argument = @($hRFC, "RFC_GET_ATTRIBUTES")
      $hFuncDesc = Invoke-Method $SAP "RfcGetFunctionDesc" $Argument
      if ($hFuncDesc -eq 0) {
        Invoke-Method $SAP "RfcCloseConnection" $hRFC > $Null
        Free-Object $SAP
        Remove-Variable SAP
        Break
      }

      $hFunc = Invoke-Method $SAP "RfcCreateFunction" $hFuncDesc
      if ($hFunc -eq 0) {
        Invoke-Method $SAP "RfcCloseConnection" $hRFC > $Null
        Free-Object $SAP
        Remove-Variable SAP
        Break
      }

      $rc = Invoke-Method $SAP "RfcInvoke" @($hRFC, $hFunc)
      if ($rc -eq $RFC_OK) {
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_DESTINATION",
          $VarByRef, 32) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_IP",
          $VarByRef, 32) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_RFC_TYPE",
          $VarByRef, 1) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_START_INFO",
          $VarByRef, 32) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_PROGRAM",
          $VarByRef, 20) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_SYSTEM_RELEASE",
          $VarByRef, 4) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_KERNEL_RELEASE",
          $VarByRef, 4) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_ASYNC_TYPE",
          $VarByRef, 1) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_TRANS_TYPE",
          $VarByRef, 1) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_PCS",
          $VarByRef, 1) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_CODEPAGE",
          $VarByRef, 4) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
        Invoke-Method $SAP "RfcGetChars" @($hFunc, "CALLER_MDMP",
          $VarByRef, 1) > $Null
        $charBuffer = Get-Property $SAP "strByRef"
        Write-Host $charBuffer
      }
      Invoke-Method $SAP "RfcDestroyFunction" $hFunc > $Null

      Invoke-Method $SAP "RfcCloseConnection" $hRFC > $Null
      Free-Object $SAP
      Remove-Variable SAP
    }

  #-Sub Main------------------------------------------------------------
    Function Main {
      Get-RFCAttributes
    }

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

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

 

VBScript Example

'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit

  '-Constants-----------------------------------------------------------
    Const RFC_OK = 0

  '-Function RfcGetAttributes-------------------------------------------
    Function RfcGetAttributes()

      '-Variables-------------------------------------------------------
        Dim SAP, hRFC, rc, hFuncDesc, hFunc, hTable, RowCount, i, Row
        Dim charBuffer, strText

      Set SAP = CreateObject("COMNWRFC")
      If Not IsObject(SAP) Then
        Exit Function
      End If

      hRFC = SAP.RfcOpenConnection("ASHOST=ABAP, SYSNR=00, " & _
        "CLIENT=001, USER=BCUSER")
      If hRFC = 0 Then
        Set SAP = Nothing
        Exit Function
      End If

      hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_GET_ATTRIBUTES")
      If hFuncDesc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Function
      End If

      hFunc = SAP.RfcCreateFunction(hFuncDesc)
      If hFunc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Function
      End If

      If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
        rc = SAP.RfcGetChars(hFunc, "CALLER_DESTINATION", charBuffer, 32)
        strText = Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_IP", charBuffer, 32)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_RFC_TYPE", charBuffer, 1)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_START_INFO", charBuffer, 32)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_PROGRAM", charBuffer, 20)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_SYSTEM_RELEASE", charBuffer, 4)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_KERNEL_RELEASE", charBuffer, 4)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_ASYNC_TYPE", charBuffer, 1)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_TRANS_TYPE", charBuffer, 1)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_PCS", charBuffer, 1)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_CODEPAGE", charBuffer, 4)
        strText = strText & Trim(charBuffer) & vbCrLf
        rc = SAP.RfcGetChars(hFunc, "CALLER_MDMP", charBuffer, 1)
        strText = strText & Trim(charBuffer) & vbCrLf
      End If

      rc = SAP.RfcDestroyFunction(hFunc)
      rc = SAP.RfcCloseConnection(hRFC)
      Set SAP = Nothing

      RfcGetAttributes = strText
    End Function

  '-Sub Main------------------------------------------------------------
    Sub Main()
      MsgBox RfcGetAttributes()
    End Sub

  '-Main----------------------------------------------------------------
    Main

'-End-------------------------------------------------------------------

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply