
'-Begin-----------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Constants-----------------------------------------------------------
Const RFC_OK = 0
'-Sub GetFMDocu-------------------------------------------------------
'-
'- This sub procedure detects in a first step all names from
'- remote-enabled function modules with a specific name pattern.
'- In a second step it gets the documentation of the function module
'- and writes this information to the Word document.
'-
'---------------------------------------------------------------------
Sub GetFMDocu()
'-Variables-------------------------------------------------------
#If Win64 Then
Dim SAP As Object
#Else
Dim SAP As CCo.COMNWRFC
#End If
Dim hRFC As Long
Dim rc As Integer
Dim hFunc As Long
Dim hFuncDesc As Long
Dim hTable As Long
Dim hRow As Long
Dim rowCount As Long
Dim FuncName As String
Dim i As Long
Dim j As Long
Dim FuncNames() As String
Dim Parameter As String
Dim Line As String
Dim FMPattern As String
FMPattern = "RFC%"
Set SAP = CreateObject("COMNWRFC")
If Not IsObject(SAP) Then
Exit Sub
End If
hRFC = SAP.RfcOpenConnection("ASHOST=NSP, SYSNR=00, " & _
"CLIENT=001, USER=BCUSER")
If hRFC = 0 Then
Set SAP = Nothing
Exit Sub
End If
'-Detect remote-enabled function modules--------------------------
hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_READ_TABLE")
If hFuncDesc = 0 Then
rc = SAP.RfcCloseConnection(hRFC)
Set SAP = Nothing
Exit Sub
End If
hFunc = SAP.RfcCreateFunction(hFuncDesc)
If hFunc = 0 Then
rc = SAP.RfcCloseConnection(hRFC)
Set SAP = Nothing
Exit Sub
End If
rc = SAP.RfcSetChars(hFunc, "QUERY_TABLE", "TFDIR")
rc = SAP.RfcSetChars(hFunc, "DELIMITER", "~")
If SAP.RfcGetTable(hFunc, "OPTIONS", hTable) = RFC_OK Then
hRow = SAP.RfcAppendNewRow(hTable)
rc = SAP.RfcSetChars(hRow, "TEXT", "FUNCNAME LIKE '" & _
FMPattern & "' AND FMODE = 'R'")
End If
If SAP.RfcGetTable(hFunc, "FIELDS", hTable) = RFC_OK Then
hRow = SAP.RfcAppendNewRow(hTable)
rc = SAP.RfcSetChars(hRow, "FIELDNAME", "FUNCNAME")
End If
If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
rc = SAP.RfcGetTable(hFunc, "DATA", hTable)
If SAP.RfcGetRowCount(hTable, rowCount) = RFC_OK Then
rc = SAP.RfcMoveToFirstRow(hTable)
For i = 1 To rowCount
hRow = SAP.RfcGetCurrentRow(hTable)
rc = SAP.RfcGetChars(hRow, "WA", FuncName, 512)
ReDim Preserve FuncNames(i)
FuncNames(i) = Trim(FuncName)
If i < rowCount Then
rc = SAP.RfcMoveToNextRow(hTable)
End If
Next
End If
End If
rc = SAP.RfcDestroyFunction(hFunc)
'-Get function module documentation-------------------------------
hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_FUNCTION_DOCU_GET")
If hFuncDesc = 0 Then
rc = SAP.RfcCloseConnection(hRFC)
Set SAP = Nothing
Exit Sub
End If
hFunc = SAP.RfcCreateFunction(hFuncDesc)
If hFunc = 0 Then
rc = SAP.RfcCloseConnection(hRFC)
Set SAP = Nothing
Exit Sub
End If
For i = 1 To UBound(FuncNames())
Selection.TypeText FuncNames(i)
Selection.InsertBreak wdLineBreak
rc = SAP.RfcSetChars(hFunc, "FUNCNAME", FuncNames(i))
rc = SAP.RfcSetChars(hFunc, "LANGUAGE", "D")
If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
rc = SAP.RfcGetTable(hFunc, "FUNCDOCU", hTable)
If SAP.RfcGetRowCount(hTable, rowCount) = RFC_OK Then
If rowCount > 0 Then
rc = SAP.RfcMoveToFirstRow(hTable)
For j = 1 To rowCount
hRow = SAP.RfcGetCurrentRow(hTable)
rc = SAP.RfcGetChars(hRow, "PARAMETER", Parameter, 30)
Parameter = Trim(Parameter)
If Parameter <> "" Then
Selection.TypeText Parameter & " - "
End If
rc = SAP.RfcGetChars(hRow, "TDLINE", Line, 132)
Selection.TypeText Trim(Line)
Selection.InsertBreak wdLineBreak
If j < rowCount Then
rc = SAP.RfcMoveToNextRow(hTable)
End If
Next
End If
End If
End If
Selection.InsertBreak wdPageBreak
Next
rc = SAP.RfcDestroyFunction(hFunc)
rc = SAP.RfcCloseConnection(hRFC)
Set SAP = Nothing
End Sub
'-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 |
---|---|
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |