Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

Tip: How to Get a Function Module Interface and Documentation

Today I want to present the possibility to get the interface and the documentation of a function module (FM). My example uses CCo, the COM Connector for the RFC library, but you can use also other ways to call a RFC function module (FM). I use the RFC FMs RFC_GET_FUNCTION_INTERFACE and RFC_FUNCTION_DOCU_GET. The first example in Visual Basic Script uses only RFC_GET_FUNCTION_INTERFACE. It opens a box to input the name of the FM and shows as result a part of the interface in a message box.

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

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

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

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

  '-Main----------------------------------------------------------------
    Set SAP = CreateObject("COMNWRFC")
    If IsObject(SAP) Then

      hRFC = SAP.RfcOpenConnection("ASHOST=ABAP, SYSNR=00, " & _
        "CLIENT=001, USER=BCUSER")
      If hRFC Then

        FuncName = UCase(InputBox("Name of the Function Module"))

        hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_GET_FUNCTION_INTERFACE")
        If hFuncDesc Then
          hFunc = SAP.RfcCreateFunction(hFuncDesc)
          If hFunc Then
            rc = SAP.RfcSetChars(hFunc, "FUNCNAME", FuncName)
            If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
              If SAP.RfcGetTable(hFunc, "PARAMS", hTable) = RFC_OK Then
                rc = SAP.RfcGetRowCount(hTable, RowCount)
                rc = SAP.RfcMoveToFirstRow(hTable)
                For i = 1 To RowCount
                  Row = SAP.RfcGetCurrentRow(hTable)
                  rc = SAP.RfcGetChars(Row, "PARAMCLASS", charBuffer, 1)
                  strText = strText & Trim(charBuffer) & " "
                  rc = SAP.RfcGetChars(Row, "PARAMETER", charBuffer, 30)
                  strText = strText & Trim(charBuffer) & " "
                  rc = SAP.RfcGetChars(Row, "PARAMTEXT", charBuffer, 79)
                  strText = strText & Trim(charBuffer) & " "
                  rc = SAP.RfcGetChars(Row, "OPTIONAL", charBuffer, 1)
                  strText = strText & Trim(charBuffer) & vbCrLf
                  If i < RowCount Then
                    rc = SAP.RfcMoveToNextRow(hTable)
                  End If
                Next
                MsgBox strText, vbOkOnly, FuncName & " Interface"
              End If
            End If
            rc = SAP.RfcDestroyFunction(hFunc)
          End If
        End If

        rc = SAP.RfcCloseConnection(hRFC)
      End If

      Set SAP = Nothing
    End If

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

 

The next example in AutoIt uses both FMs. Also I programmed a tiny GUI.

0116_GetFMDocuInterface.jpg

 

In the Main function I define the GUI and the event loop. The function GetFMInterface delivers the interface of a FM, as the example above, and the function GetFMDocu delivers the documentation of the FM. With the button Copy to Clipboard you can transfer the generated content into other applications.

;-Begin-----------------------------------------------------------------

  ;-Directives----------------------------------------------------------
    AutoItSetOption("MustDeclareVars", 1)

  ;-Includes------------------------------------------------------------
    #Include <MsgBoxConstants.au3>
    #Include <StringConstants.au3>
    #Include <GUIConstantsEx.au3>
    #Include <FontConstants.au3>
    #Include <StaticConstants.au3>
    #Include <EditConstants.au3>

  ;-Constants-----------------------------------------------------------
    Const $RFC_OK = 0

  ;-Function GetFMDocu--------------------------------------------------
    Func GetFMDocu($Conn, $FuncName)

      ;-Variables-------------------------------------------------------
        Local $SAP, $hRFC, $hFuncDesc, $hFunc, $txt = "", $i
        Local $hTable = 0, $RowCount = 0, $Row, $charBuffer = ""

      $SAP = ObjCreate("COMNWRFC")
      If IsObj($SAP) Then

        $hRFC = $SAP.RfcOpenConnection($Conn)
        If $hRFC Then

          $hFuncDesc = $SAP.RfcGetFunctionDesc($hRFC, _
            "RFC_FUNCTION_DOCU_GET")
          If $hFuncDesc Then
            $hFunc = $SAP.RfcCreateFunction($hFuncDesc)
            If $hFunc Then
              $SAP.RfcSetChars($hFunc, "FUNCNAME", $FuncName)
              If $SAP.RfcInvoke($hRFC, $hFunc) = $RFC_OK Then
                If $SAP.RfcGetTable($hFunc, "FUNCDOCU", $hTable) = _
                  $RFC_OK Then
                  $SAP.RfcGetRowCount($hTable, $RowCount)
                  $SAP.RfcMoveToFirstRow($hTable)
                  For $i = 1 To $RowCount
                    $Row = $SAP.RfcGetCurrentRow($hTable)
                    $SAP.RfcGetChars($Row, "PARAMETER", $charBuffer, 30)
                    $txt = $txt & $charBuffer & " "
                    $SAP.RfcGetChars($Row, "TDLINE", $charBuffer, 132)
                    $txt = $txt & StringStripWS($charBuffer, _
                      $STR_STRIPTRAILING) & @CRLF
                    If $i < $RowCount Then
                      $SAP.RfcMoveToNextRow($hTable)
                    EndIf
                  Next
                EndIf
              EndIf
              $SAP.RfcDestroyFunction($hFunc)
            EndIf
          EndIf

          $SAP.RfcCloseConnection($hRFC)
        EndIf
        $SAP = 0
      EndIf

      Return $txt

    EndFunc

  ;-Function GetFMInterface---------------------------------------------
    Func GetFMInterface($Conn, $FuncName)

      ;-Variables-------------------------------------------------------
        Local $SAP, $hRFC, $hFuncDesc, $hFunc, $hTable = 0, $i
        Local $RowCount = 0, $charBuffer = "", $txt = "", $Row
        Local $intBuffer = 0

      $SAP = ObjCreate("COMNWRFC")
      If IsObj($SAP) Then

        $hRFC = $SAP.RfcOpenConnection($Conn)
        If $hRFC Then

          $hFuncDesc = $SAP.RfcGetFunctionDesc($hRFC, _
            "RFC_GET_FUNCTION_INTERFACE")
          If $hFuncDesc Then
            $hFunc = $SAP.RfcCreateFunction($hFuncDesc)
            If $hFunc Then
              $SAP.RfcSetChars($hFunc, "FUNCNAME", $FuncName)
              If $SAP.RfcInvoke($hRFC, $hFunc) = $RFC_OK Then
                If $SAP.RfcGetTable($hFunc, "PARAMS", $hTable) = _
                  $RFC_OK Then
                  $SAP.RfcGetRowCount($hTable, $RowCount)
                  $SAP.RfcMoveToFirstRow($hTable)
                  For $i = 1 To $RowCount
                    $Row = $SAP.RfcGetCurrentRow($hTable)
                    $SAP.RfcGetChars($Row, "PARAMCLASS", $charBuffer, 1)
                    $txt = $txt & $charBuffer & " "
                    $SAP.RfcGetChars($Row, "PARAMETER", $charBuffer, 30)
                    $txt = $txt & $charBuffer & " "
                    $SAP.RfcGetChars($Row, "OPTIONAL", $charBuffer, 1)
                    $txt = $txt & $charBuffer & " "
                    $SAP.RfcGetChars($Row, "EXID", $charBuffer, 1)
                    $txt = $txt & $charBuffer & " "
                    $SAP.RfcGetInt($Row, "INTLENGTH", $intBuffer)
                    $txt = $txt & StringFormat("%04i", $intBuffer) & " "
                    $SAP.RfcGetChars($Row, "PARAMTEXT", $charBuffer, 79)
                    $txt = $txt & StringStripWS($charBuffer, _
                      $STR_STRIPTRAILING) & @CRLF
                    If $i < $RowCount Then
                      $SAP.RfcMoveToNextRow($hTable)
                    EndIf
                  Next
                EndIf
              EndIf
              $SAP.RfcDestroyFunction($hFunc)
            EndIf
          EndIf

          $SAP.RfcCloseConnection($hRFC)
        EndIf
        $SAP = 0
      EndIf

      Return $txt

    EndFunc

  ;-Sub Main------------------------------------------------------------
    Func Main()

      ;-Variables-------------------------------------------------------
        Local $hGUI, $Quit = False, $IDGenerate, $Conn, $IDCopy
        Local $FuncName, $IDFuncName, $Interface, $IDInterface, $Docu
        Local $IDASHOST, $IDSYSNR, $IDCLIENT, $IDUSER, $IDPASSWD

      $hGUI = GUICreate("Function Module Documentation and " & _
        "Interface Viewer", 800, 800)

      ;-GUI-------------------------------------------------------------
        GUICtrlCreateLabel("ASHOST:", 10, 15, 60, 24, $SS_RIGHT)
        $IDASHOST = GUICtrlCreateInput("ABAP", 80, 10, 70, 24)
        GUICtrlCreateLabel("SYSNR:", 160, 15, 60, 24, $SS_RIGHT)
        $IDSYSNR = GUICtrlCreateInput("00", 230, 10, 70, 24)
        GUICtrlCreateLabel("CLIENT:", 310, 15, 60, 24, $SS_RIGHT)
        $IDCLIENT = GUICtrlCreateInput("001", 380, 10, 70, 24)
        GUICtrlCreateLabel("USER:", 460, 15, 60, 24, $SS_RIGHT)
        $IDUSER = GUICtrlCreateInput("BCUSER", 530, 10, 70, 24)
        GUICtrlCreateLabel("PASSWORD:", 640, 15, 70, 24, $SS_RIGHT)
        $IDPASSWD = GUICtrlCreateInput("minisap", 720, 10, 70, 24, _
          $ES_PASSWORD)
        GUICtrlCreateLabel("Function Module", 10, 49, 100, 24)
        $IDFuncName = GUICtrlCreateInput("BAPI_USER_CREATE", 100, 44, _
          580, 24)
        $IDGenerate = GUICtrlCreateButton("Generate", 690, 44, 100, 24)
        $IDInterface = GUICtrlCreateEdit("", 10, 78, 780, 678)
        GUICtrlSetFont($IDInterface, 10, $FW_NORMAL, 0, "Courier New")
        $IDCopy = GUICtrlCreateButton("Copy to Clipboard", _
          640, 766, 150, 24)

      ;-Show GUI--------------------------------------------------------
        GUISetState(@SW_SHOW, $hGUI)

      ;-GUI Event Loop--------------------------------------------------
        Do
          Switch GUIGetMsg()
            Case $IDGenerate
              $FuncName = StringUpper(GUICtrlRead($IDFuncName))
              If $FuncName <> "" Then
                $Conn = "ASHOST=" & GUICtrlRead($IDASHOST) & ", " & _
                        "SYSNR=" & GUICtrlRead($IDSYSNR) & ", " & _
                        "CLIENT=" & GUICtrlRead($IDCLIENT) & ", " & _
                        "USER=" & GUICtrlRead($IDUSER) & ", " & _
                        "PASSWD=" & GUICtrlRead($IDPASSWD)
                $Docu = "Documentation" & @CRLF & _
                  GetFMDocu($Conn, $FuncName) & @CRLF
                $Interface = "Interface" & @CRLF & _
                  GetFMInterface($Conn, $FuncName)
                GUICtrlSetData($IDInterface, $Docu & $Interface, "")
              EndIf
            Case $IDCopy
              ClipPut(GUICtrlRead($IDInterface))
            Case $GUI_EVENT_CLOSE
              $Quit = True
          EndSwitch
        Until $Quit = True

      ;-Destroy GUI-----------------------------------------------------
        GUIDelete($hGUI)

    EndFunc

  ;-Main----------------------------------------------------------------
    Main()

;-End-------------------------------------------------------------------

 

Enjoy it.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.