Simplify SAP R/3 development with Excel VBA/VB RFC  
Home> Sap_Active_X>Create Structure 1


Create Structure 1

It's simple to do with CreateStructure method. After you made logon as described in the Logon section, with reference to the object, you can create a structure as defined in the SAP repository. In case if you want to keep SAP data as in the SAP data structure, you can use this function.

(A) Sample snippet to get KNA1 structure from SAP and display field name, value (nothing is set) and length in immediate Window.
Sub TempStructure1()

Dim sapConn as Object 'Declare variant
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object

If sapConn.Connection.Logon(0, False) <> True Then 'Try Logon
  msgbox "Logged on to SAP - " & sapConn.Connection.Destination
end if

Dim objKna1 as Object
Set objKna1 = sapConn.CreateStructure("KNA1")

Dim lngIdx as Long
objKna1("KUNNR") = "123456"
Debug.Print ""
For lngIdx = 1 to objKna1.ColumnCount
   Debug.Print objKna1.ColumnName(lngIdx) & " = " & _
                       objKna1(objKna1.ColumnName(lngIdx)) & ", " & _

End Sub

(B) Properties for Structure object
Even though the these fields are not visible from Watches window in the Visual Basic Editor, you can read or sometimes write values on the fields below.
ColumnCount Number of columns in the structure object. (Read only)
Type Return name of the object. (Read only)
Function Function object name that owns the structure object. (If there is. Read only)
Name ABAP name of the structure. (Read only)
Width Structure width for the field. (Read only)
ColumnName(n) Get column name for the column at position (n).
Value(n or str) Read/Write value under the name (n or str).
ColumnOffset(n) First byte of the column at position (n). (Read only)
ColumnLength(n) Read length of the column in bytes  for the column at position (n). (Read only)
ColumnSAPType(n) Read SAP internal data type for the column at position (n).
RfcTypeChar = 0 = String
RfcTypeData = 1 = Date
RfcTypeBCD = 2 = BCD
RfcTypeTime = 3 = Time
RfcTypeHex = 4 = Binary
RfcTypeNum = 6 = Numeric
RfcTypeFloat = 7 = Float
RfcTypeLong = 8 = Long
RfcTypeShot = 9 = Short
RfcTypeByte = 10 = Byte
ColumnDecimals(n) Number of decimal places to the right of the decimal point for the column at position (n). (Read only)

(C) Methods for Structure object
These methds are available for the Structure object.
Clear Initialize values set in the structure fields.
Clone Copy the structure object and create new one.
IsStructure Return true if the object is Structure.