Sapass

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



Index

Create Structure 2

Same as CreateStructure method, Structure can be created by the NewStructure method of TableFactory control. This utilize the ActiveX module in ...SAP/FrontEnd/Controls/WDTAOCX.OCX.


(A) Compare to CreateStructure command, it requires few more steps.
If you explicitly allocate the structure to as parameter of function module, you may be able to use this. But except for this kind of special situation, do with CreateStructure will be good enough.
Sub TempStructure2()

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
   Exit Sub
End If

Dim objTableFactory As Object
Set objTableFactory = CreateObject("Sap.TableFactory.1")

'Define objEdidc with SAP EDIDC structure and name it as IDOC_CONTROL
Dim objEdidc As Object
Dim lngTmp As Long
Set objEdidc = objTableFactory.NewStructure
lngTmp = objEdidc.CreateFromR3Repository(sapConn.Connection, "EDIDC", "IDOC_CONTROL")

Dim lngIdx As Long
objEdidc("DOCNR") = "1"
Debug.Print ""
For lngIdx = 1 To objEdidc.ColumnCount
   Debug.Print objEdidc.ColumnName(lngIdx) & " = " & _
   objEdidc(objEdidc.ColumnName(lngIdx)) & ", " & _
   objEdidc.ColumnLength(lngIdx)
Next

End Sub


(B) Properties for Structure object
Unlike the Structure created by CreateStructure method, some fields are visible but not all.
ColumnCount Number of columns.
ColumnDecimals(n) Number of decimals for this item (n).
ColumnLength(n) Number of byte length for this item (n).
ColumnName(n) Name for this item (n).
ColumnOffset(n) Distance from the structure start to this element (n).
ColumnSAPType(n) SAP Type number for this item (n).
Name Name of structure.
StructureHandle Structure handle.
Type Structure type.
Value (n or str). Value for this item (n or str).
Width Byte length of the structure.

(C) Methods for Structure object
Clear Initialize values set in the structure fields.
CreateFromR3Repository Create Structure as specified in the parameters.
IsStructure Return true if the object is Structure.

17-Sep-2005