本文主要是介绍SAP接口编程-RFC系列08 : 获取SAP DDIC的数据字段,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
获取DDIC的数据字段
如果想获取数据表的字段,使用RFC_READ_TABLE,设置NO_DATA为"X"。也可以使用SAPFunctions.CreateStructure()方法。这个方法更具通用性,能够从DDIC的数据类型中获取相关信息。
以下是示例代码。注意返回的结构是一个复合型结构,每一列包含了诸如列名,数据类型,数据长度,小数位等信息。所以为了直观和调试,使用数组解析和输出。
logon()和logoff()的代码请参考以前博文。
Option ExplicitPublic Sub TestGetTableStructure()Call LogonCall GetTableStructure("SKA1")Call logoff
End SubPrivate Sub GetTableStructure(tableName As String)If sapConnection Is Nothing Or sapConnection.IsConnected <> tloRfcConnected ThenDebug.Print "Please connect."Exit SubEnd IfDim functions As New SAPFunctionsOCX.SAPFunctionsSet functions.Connection = sapConnectionDim ddicFields As SAPFunctionsOCX.Structure ' data dictionary fieldsSet ddicFields = functions.CreateStructure(tableName) ' get fields from tableNameDim arr() As Variantarr = StructToArray(ddicFields)' Print structureDim row As IntegerDim col As IntegerFor row = 1 To UBound(arr, 1)For col = 1 To UBound(arr, 2)Debug.Print arr(row, col),NextDebug.Print ' new lineNext
End SubPrivate Function StructToArray(struct As SAPFunctionsOCX.Structure) As VariantDim arr() As VariantDim cols As Integercols = struct.ColumnCountReDim arr(1 To cols, 1 To 3) As Variant ' rowcount is cols ,column count is 3' 可以把strcut理解为一个复合结构,每一个元素包括多项内容' 使用二维的array还原成行列格式Dim i As IntegerFor i = 1 To struct.ColumnCountarr(i, 1) = struct.ColumnName(i) '第一列为列名arr(i, 2) = Str(struct.ColumnSAPType(i)) ' 第二列为类型arr(i, 3) = struct.ColumnLength(i) '第三列为长度NextStructToArray = arr
End Function
这篇关于SAP接口编程-RFC系列08 : 获取SAP DDIC的数据字段的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!