×

[PR]この広告は3ヶ月以上更新がないため表示されています。
ホームページを更新後24時間以内に表示されなくなります。




Sapass

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



Index

Create Table

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


(A) Declaration of table
After logon, by following statements, you can create Table object. In below case we create EDIDD table as defined in SAP and name it as IDOC_DATA.
Dim objTableFactory As Object
Set objTableFactory = CreateObject("Sap.TableFactory.1")

'Define objEdidc with SAP EDIDD structure and name it as IDOC_DATA
Dim objEdidd As Object
Dim lngTmp As Long
Set objEdidd = objTableFactory.NewTable
lngTmp = objEdidd.CreateFromR3Repository(sapConn.Connection, "EDIDD", "IDOC_DATA")


(B) Append table entry
In order to add data entry on the table with values, we have to first append an entry to table. This is something different from what we do in ABAP programming.
objEdidd.Rows.Add 'Add Row
objEdidd(1, "SEGNAM") = "E1MARAM" 'Set SEGNAM field in 1st row


(C) Accessing to table contents
We can read Table row and column data by accessing to the properties on the table. Here we use these properties in samplesnippet. ColumnName - Contains field name. Rows property of Table - Contains row of table. Columns property of Row - Contains field of row
For Each objEdiddRec In objEdidd.Rows
   For lngIdx = 1 To objEdidd.ColumnCount
      Debug.Print objEdidd.ColumnName(lngIdx) & " = " & _
      objEdiddRec(objEdidd.ColumnName(lngIdx)) & ", " & _
      objEdidd.Columns(lngIdx).IntLength
   Next
Next


(D) Sample code
Here we have complete set of example code.
Sub Temp()
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 "Cannot log on to SAP - " & sapConn.Connection.Destination
   Exit Sub
End If

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

'Define objEdidc with SAP EDIDD structure and name it as IDOC_DATA
Dim objEdidd As Object
Dim lngTmp As Long
Set objEdidd = objTableFactory.NewTable
lngTmp = objEdidd.CreateFromR3Repository(sapConn.Connection, "EDIDD", "IDOC_DATA")

Dim lngIdx As Long
Dim objEdiddRec As Object
objEdidd.Rows.Add 'Add Row
objEdidd(1, "SEGNAM") = "E1MARAM" 'Set SEGNAM field in 1st row

For Each objEdiddRec In objEdidd.Rows
   For lngIdx = 1 To objEdidd.ColumnCount
      Debug.Print objEdidd.ColumnName(lngIdx) & " = " & _
      objEdiddRec(objEdidd.ColumnName(lngIdx)) & ", " & _
      objEdidd.Columns(lngIdx).IntLength
   Next
Next
End Sub


(E) Properties of Table object
Rowcount Returns the number of rows contained in the table. (Read only)
ColumnCount Returns the number of columns contained in the table's column collection. (Read only)
RfcParameter Returns a RfcTableParameter object. (Read only)
Rows Returns a Row object. (Read only)
Columns Returns a Column object. (Read only)
Ranges Returns an object of type Ranges (Read only)
Views Returns an object of type Views (Read only)
Data Returns the Table object in the form of an array.
Value Access a single value in the table.

(F) Properties of Row object
Cell Cell data with (Row and Column)
Data Data (Object)
Index Index (Long)
Parent Parent object (Table Object)
Value(str) Value (Specify by name - str)

(G) Properties of Column object
Cell Cell data with (Row and Column)
ColumnInfo Data (Object)
Data Data (Object)
Decimals Integer
Index Long
IntLength Integer
Name String
Offset Integer
Type RfcTypeChar = 0
RfcTypeDate = 1
RfcTypeBCD = 2
RfcTypeTime = 3
RfcTypeHex = 4
RfcTypeNum = 6
RfcTypeFloat = 7
RfcTypeLong = 8
RfcTypeShort = 9
RfcTypeByte = 10
TypeName Type name
Value(n) Value (Specify by index - n)

17-Sep-2005