sap interface, how to learn sap, sap connection, process sap, sap process, sap application integration

Create Table

SAP Interfacing with VBA. In this blog you will get some informations about :
Best Information For Create Table | Create Table Articles

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)

We have been providing the best information about Create Table For you. If you liked this information, please tell your friends on Facebook, Twitter or Google plus using social buttons below.. ^_^. SAP Interfacing with VBA
Create Table Rating: 4.5 by: Abdul Rahman Nasution

0 comments:

Post a Comment