Hi Anuja,
Good evening.
Following are the steps to get the structure to an excel file using VBScript:
a. Define all the variables that are needed for this script.
- and one of the main variable is 'Long Index Variable' that you can define as follows:
Dim lngIdx 'Needed to loop thru SAP table structure & retrieve table column field names.
&
Dim ExcelApp 'Excel App
Dim ExcelWorkbook 'Excel workbook
Dim ExcelSheet 'Excel worksheet
b. Instantiate the structures and functions for SAP access - which are:
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject") 'Instantiation of filesystem object
Set ctlLogon = CreateObject("SAP.LogonControl.1") 'Instantiation of SAP Logon Control Object
Set funcControl = CreateObject("SAP.Functions") 'Instantiation of SAP Functions - NOTE SAP should be installed
Set ctlTableFactory = CreateObject("SAP.TableFactory.1") 'Setting & instantiation of SAP Table Factory
Set RFC_READ_TABLE = funcControl.Add("RFC_READ_TABLE") 'Function control for RFC READ TABLE, following 4 are needed in that sequence
Set strExport1 = RFC_READ_TABLE.Exports("QUERY_TABLE") 'SAP Query Table instantiation
Set strExport2 = RFC_READ_TABLE.Exports("DELIMITER") 'Delimiter as needed, and part of RFC READ TABLE in SAP
Set tblOptions = RFC_READ_TABLE.Tables("OPTIONS") 'This is for writing the actual SQL Query
Set tblData = RFC_READ_TABLE.Tables("DATA") 'Please refer to actual RFC READ TABLE FM (SE37) shown above
Set tblFields = RFC_READ_TABLE.Tables("FIELDS")
Set tblStructure = funcControl.CreateStructure(sapTables(m)) 'Where sapTables(m) is the array containing the list of tables for which you want to retrieve the structure.
c. Following is the function that you need to retrieve the table structure along with their positions
that SE16 shows you OR ZSE16 shows you.
For lngIdx = 1 To tblStructure.ColumnCount 'Loop thru entire table structure and get the table column field names. This is ideal.
if tblStructure.ColumnCount > 10 Then
actCounter = 10 'This is needed since RFC_READ_TABLE which the main function that i use has an output field that is TAB512 - implying the total length of output cannot be > 512 bytes.
else
actCounter = tblStructure.ColumnCount
End if
For lngIdx = 1 to actCounter
'.ColumnName contains field name
'.ColumnLength contains field length
'.ColumnOffset contains field offset
tblFields.AppendRow
tblFields(tblFields.RowCount, "FIELDNAME") = tblStructure.ColumnName(lngIdx)
ExcelSheet.Cells(row, n).Value = tblStructure.ColumnName(lngIdx) '10 fields from the input table will be copied over along with their domain, size, offset and length.
' If tblStructure.ColumnOffset(lngIdx) + tblStructure.ColumnLength(lngIdx) > 1024 Then Exit For
'WshShell.Popup tblFields(tblFields.RowCount, "FIELDNAME") & " column retrieved", 1, "Progress" ' show message box with table fieldname for a second & disappears.
Next
'---- not including full code.here.
Additional FYI - i am currently researching on using the following functions that will help to
increase the size of the output buffer, so that i can extract entire tables and not be limited to
512 bytes:
a. RPY_TABLE_READ OR
b. BBP_RFC_READ_TABLE
Hope it helps. Let me know if you need any more help?.
Thanks
Ram.S