To read the column names of an internal table
Hi ,
I want to read the column/field names of an internal table into another internal table.
How can this be done?
Kind Regards,
hgarsht Rungta
Hi ,
you can get the attributes of any internal table into another ..
check the following code ..
DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
DATA : it_detail TYPE abap_compdescr_tab,
wa_comp TYPE abap_compdescr.
DATA : ref_descr TYPE REF TO cl_abap_structdescr.
ref_descr ?= cl_abap_typedescr=>describe_by_data( it_mara ).
it_detail[] = ref_descr->components .
loop at it_detail into wa_comp.
write:/ wa_comp-name .
endloop.
Regards,
Rajesh Kumar
Similar Messages
-
How to read the column name of a table from sap system using C#?
Hi!!
I am using SAP .NET connector and creating a windows application.
Now I wanna read the column name when a table name is given....
Connection is done, but I don't know the code to read the column names alone...
Can anyone help me with the code??fine!!
So if i give the table name, which the RFC_READ_TABLE function module have, will it run properly? or i wanna change all the codes in order to support RFC_READ_TABLE function module?
Because from the beginning I was using BAPI_CUSTOMER_GETLIST function, but my client requirement is to use ERP function module RFC_READ_TABLE, he didn't give any table name also..
This is my code: What I have to change in this???
ECCDestinationConfig ECCDestination = new ECCDestinationConfig();
RfcDestinationManager.RegisterDestinationConfiguration(ECCDestination);
RfcDestination rfcDest = null;
rfcDest = RfcDestinationManager.GetDestination(a);
RfcRepository repo = rfcDest.Repository;
IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_GETLIST");
IRfcTable addressData = customerList.GetTable("AddressTable"));
int j = addressData.Metadata.LineType.FieldCount;
for (int i = 0; i < j; i++)
RfcElementMetadata metadata = addressData.GetElementMetadata(i);
listallcolumn.Items.Add(metadata.Name);
Message was edited by: Jeswin Rebil -
Hello,
Can anyone help me out to write a vb.net script.
I need to read the column names from excel and based on that column names I need to create a table in database(I have more than one sheet in excel).
For each sheet columns will be changing and should create a table dynamically for each sheet.
Any help would be appreciated.Refer the below script to read columns in each sheet.
Dim excelfile As String = Dts.Variables("ExcelPath").Value.ToString
Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + excelfile + ";Extended Properties=Excel 8.0"
Dim oledbcon As New OleDb.OleDbConnection(connectionstring)
oledbcon.Open()
Dim dt As DataTable
Dim schemaTable As DataTable
Dim OLEDBCMD As New OleDb.OleDbCommand
Dim oledbdatareader As OleDb.OleDbDataReader
Dim columns As String = ""
dt = oledbcon.GetSchema("Tables")
Dim TABCOMMAND(20) As String
Dim TABCOUNT As Integer = 0
For Each row As DataRow In dt.Rows
TABCOMMAND(TABCOUNT) = "SELECT * FROM [" & row.Item("TABLE_NAME").ToString & "]"
OLEDBCMD.CommandText = TABCOMMAND(TABCOUNT)
OLEDBCMD.Connection = oledbcon
oledbdatareader = OLEDBCMD.ExecuteReader(CommandBehavior.KeyInfo)
schemaTable = oledbdatareader.GetSchemaTable()
For Each myfield As DataRow In schemaTable.Rows
For Each myproperty As DataColumn In schemaTable.Columns
If myproperty.ColumnName = "ColumnName" Then
columns = columns & myfield(myproperty).ToString & ","
MsgBox(myfield(myproperty).ToString)
End If
Next
Next
oledbdatareader.Close()
OLEDBCMD.Dispose()
Next
oledbcon.Close()
Regards, RSingh -
How to get the field name of an internal table during runtime?
How to get the field name of an internal table during runtime?
Hi Sudhir,
Declare and Use Get Cursor Field in Your Prm to get the field Name of the Intenal Table
Example Code:
<b> DATA: v_field(60). " Insert this code.
GET CURSOR FIELD v_field. " Insert this code.</b>
<b>CHECK v_field = 'ITAB-KUNNR'. " Insert this code. (or)
Write: v_field.</b>
Regards,
Ramganesan K. -
How to read the column name of the Table.
hi
I have applied sort functionality to the Table columns. It is working fine but I need to read the table column name before sorting ( On which column user trying to sort ).
Thank you all,
Rama...Hi Alex
Thank you very much for your valid input.
But I am facing one problem here. To get sort functionality I added following logic in WDDOMODIFYVIEW method.
DATA wd_table TYPE REF TO cl_wd_table.
CHECK first_time = abap_true.
wd_table ?= view->get_element( 'TABLE_NAME' ).
wd_this->table_control ?= wd_table->_method_handler.
wd_this->table_control->set_key_attribute_name( 'COL_NAME1' ).
here I hard coded first column name(i.e. COL_NAME1). Is it correct?
and added following code in SORT ACTION of table i.e.
wd_this->table_control->apply_sorting( ).
To get column name I am using the method in SORT ACTION of table which you mentioned but always I am getting COL_NAME1 only....
Please help me how can I rectify this...
Thank you
Rama -
Debugging ECC6: how to see the fields name when download internal table?
When we debug a reprot in ECC6 and save to a local file an internal table, the fields are not appearing only the data,
Is there a way to download also the table fields name?From the new debugger switch to the classic debugger using menu path Debugger->Switch to Classic Debugger. Form the classic debugger you can download internal table data with column name(s).
Regards,
Joy. -
Reading the data from field symbol internal table //
Hi,
There are 2 internal tables defined as Fieldsymbols (type any) and I need to retrive data from second internal table based on a field value in first internal table.
Let's assue the name internal table 1 is <it_itab1>, 2nd internal table name is <it_itab2> and the work areas are <wa_itab1> and <wa_itab2>.
The existing logic :
LOOP at <it_itab1> ASSIGNING <wa_itab1>.
ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab1> TO l_field6.
LOOP AT <it_itab2> ASSIGNING <wa_itab2>.
ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab2> TO <p_field7>.
IF <p_field7> = l_field6.
do the required business.
ELSE.
* do the required business.
ENDIF.
ENDLOOP.
ENDLOOP.
The requirement of reading second internal table was achieved by putting loop on the internal table but its giving considerable effect on performance !!
Is there any way to use READ statement in my case OR any way of putting WHERE condition on loop statement of second internal table ??
Thank you !!Use the below Logic.
Loop at Itab1 into wa_itab1.
Loop at itab2 into wa_itab2 where p_field7 = wa_itab1-xyz or I_field6.
do the required business.
endloop.
Loop at itab2 into wa_itab2 where p_field7 <> wa_itab1-xyz or I_field6.
do the required business.
endloop.
endloop.
Hope it is useful... -
Read the last record of an internal table
Hello All,
I need to read the last entry of the internal table? Is it possible to achieve this without using loop - endloop?
In the following example, I need to get the Batch '110776' and store it in a variable.
ITAB:
MATNR|CHARG
010780|110770
010780|110772
010780|110773
010780|110774
010780|110775
010780|110776
Thanks.Use DESCRIBE to get the number of entires in variable last_entry
and then use read table ....index last_entry -
Make the column to row.(internal table)
hi
i have an internal table ITAB
data:begin of itab
quarters(2),
end of itab.
that has contents
Q1
Q2
Q3
Q4
I would like to have a ITAB2 like this
data:begin of itab
Q1(2),
Q2(2),
Q3(2),
Q4(2)
end of itab.
Q1 Q2 Q3 Q4 Q5
any ideas guys..........
thanks
raghu.REPORT z_test.
Transpose itab1 to itab2.
TYPES: BEGIN OF ty_1,
first,
second,
third,
fourth,
END OF ty_1.
TYPES: BEGIN OF ty_2,
first,
second,
third,
END OF ty_2.
FIELD-SYMBOLS: <fs> TYPE ANY,
<fs2> TYPE ANY.
DATA: itab1 TYPE TABLE OF ty_1 WITH HEADER LINE,
itab2 TYPE TABLE OF ty_1 WITH HEADER LINE,
curr_line TYPE sy-tabix.
itab1-first = '1'.
itab1-second = '2'.
itab1-third = '3'.
itab1-fourth = '4'.
APPEND itab1.
itab1-first = '1'.
itab1-second = '2'.
itab1-third = '3'.
itab1-fourth = '4'.
APPEND itab1.
itab1-first = '1'.
itab1-second = '2'.
itab1-third = '3'.
itab1-fourth = '4'.
APPEND itab1.
LOOP AT itab1.
CLEAR itab2.
ASSIGN COMPONENT sy-tabix OF STRUCTURE itab2 TO <fs>.
curr_line = sy-tabix.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE itab1 TO <fs2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF curr_line = 1.
<fs> = <fs2>.
APPEND itab2.
ELSE.
READ TABLE itab2 INDEX sy-index.
<fs> = <fs2>.
MODIFY itab2 INDEX sy-index.
ENDIF.
ENDDO.
ENDLOOP.
LOOP AT itab2.
WRITE:/ itab2.
ENDLOOP.
Please find the above code for the same.
Regards
Ramesh. -
Just new to this and unable to find answers
My solution
Public Function GetTableColumnNames() As Boolean
Form1.ListBox1.Items.Clear()
_MDFFileName = String.Format("{0}.mdf", _DatabaseName)
_sqlConnectionString = String.Format("Data Source=(LocalDB)\v11.0;AttachDBFileName={1};Initial Catalog={0};Integrated Security=True;", _DatabaseName, Path.Combine(_DatabaseDirectory, _MDFFileName))
Dim cn As New SqlConnection(_sqlConnectionString)
'put the table name in brackets in case it has spaces in it
Dim SQLString As String = "SELECT * FROM [" & _TableName & "]"
Try
cn.Open()
Dim cmd As New SqlCommand(SQLString, cn)
Dim rdr As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.KeyInfo)
Dim tbl As DataTable = rdr.GetSchemaTable
'This shows all of the information you can access about each column.
For Each col As DataColumn In tbl.Columns
Form1.ListBox1.Items.Add(col.ColumnName)
Debug.Print("col name = " & col.ColumnName & ", type = " & col.DataType.ToString)
Next
'Get each column.
For Each row As DataRow In tbl.Rows
Form1.ListBox1.Items.Add(row("ColumnName"))
Next
rdr.Close()
Catch
MessageBox.Show("Error opening the connection to the database.")
Finally
cn.Close()
End Try
Return _Success
End Function -
Need help on getting the column names of Tabletype
I have a table Mapping with the following values: This Mapping table contains the table names (in Tabname) and the column names(colname) of various tables and values(ValuesTobeFilled) for the columns.
I have to insert into the tables present in the Tabname field with the values present in the ValuesTobeFilled in the columns present in the Colname field.
Note: The Mapping table need not contain all the columns of the base table. The columns that are not present can be filled with null. And this mapping table is not fixed i.e. rows can be inserted/deleted frequently.
Sample values in mapping table:
Tabname Colname ValuesTobeFilled
sample_items Eno Corresponding Expression to get the values from XML input
sample_items Ename Corresponding Expression to get the values from XML input
XXX YYY Corresponding Expression to get the values from XML input
Before filling in the actual tables, I have to store the entire data temporarily and I have used a tabletype declared as follows:
TYPE T_sample_items IS TABLE OF sample_items%ROWTYPE INDEX BY BINARY_INTEGER;
l_sample_items T_sample_items;
Where the table sample_items have the following columns:
• Eno
• Ename
• Eaddress
• Eemail
So, the tabletype should be filled as:
Eno Ename Eaddress EEmail
1 XXX - -
I have declared a cursor to select the values from mapping table and I need to fill in the ValuesTobeFilled values to the corresponding table.
CURSOR c_xpath (c_tname mapping.TABNAME%type)
IS
select * from mapping where tabname = c_tname;
CURSOR c_tables
IS
SELECT DISTINCT TABNAME FROM mapping;
FOR crsr IN c_tables
LOOP
p_tname := CRSR.TABNAME;
FOR csr IN c_xpath(p_tname)
LOOP
IF l_xml_doc.EXISTSNODE(CSR.XPATH_EXP) = 1
THEN
l_node_value := l_xml_doc.extract(CSR.XPATH_EXP).getStringVal(); -- This is the value to be stored in the corresponding column
ELSE
l_node_value := NULL;
END IF;
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).name := l_node_value;
END IF;
END LOOP;
END LOOP;
And I need to eliminate hard coding while comparing the column names (in the following piece of code) as the Mapping table values are subject to insertion/deletion:
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).ename := l_node_value;
END IF;
I need to insert the values directly into the tabletype without this hardcoding. Please suggest me ways to compare the mapping table values with the field (column) names of the tabletype. If it is not possible using tabletype, please suggest any other ways of fixing the problem.
Many thanks,
GopiI take it this isn't going to be a serious production system at the end of the day?
Storing metadata in tables for extraction and insertion of data is just wrong in so many ways. It smells heavily of Entity Attribute Value modelling, which is the most wrong way to use a relational database and is known to have major performance implications and be liable to bugs and issues. The idea that EAV modelling allows for 'generic' databases where new data items can be added flexibly later on without having to change code is usually justified with an excuse of "it means we don't have to update all our tables when we want a new column" which is easily countered with "if you're adding a single column a good relational design wouldn't require you to add it to more than one table anyway in most cases".
Just what exactly are you trying to do and why? There has to be a better way. -
Getting field names of an internal table
Hi all,
Does anyone know if exists a statement, function module or method that gets the field names of an internal table ?
Thanks in advance,
DavidHi,
See this
REPORT typedescr_test.
TYPES:
BEGIN OF my_struct,
comp_a type i,
comp_b type f,
END OF my_struct.
DATA:
my_data TYPE my_struct,
descr_ref TYPE ref to cl_abap_structdescr.
FIELD-SYMBOLS:
<comp_wa> TYPE abap_compdescr.
START-OF-SELECTION.
descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).
WRITE: / 'Typename :', descr_ref->absolute_name.
WRITE: / 'Kind :', descr_ref->type_kind.
WRITE: / 'Length :', descr_ref->length.
WRITE: / 'Decimals :', descr_ref->decimals.
WRITE: / 'Struct Kind :', descr_ref->struct_kind.
WRITE: / 'Components'.
WRITE: / 'Name Kind Length Decimals'.
LOOP AT descr_ref->components ASSIGNING <comp_wa>.
WRITE: / <comp_wa>-name, <comp_wa>-type_kind,
<comp_wa>-length, <comp_wa>-decimals.
ENDLOOP. -
Getting Column names (header) of a table dynamically
Dear Experts,
Greetings.
I have a requirement in which I need to get the column name (header) of a table when the user clicks on a column.
Kindly suggest me the possible ways.
Thanks in advance.
Regards
SathyaHi,
use one of the following based on your requirement
Bind the header text to a context attribute and access this attribute from code when clicked on the column.
Or use parameter mapping.
Regards
Ayyapparaj -
How To Know The Column Name Of The Internal Table
HI ,
i have an internal table .
f1 f2 f 3 f4 f5
matnr mbrsh mtart meins minbe
i want to know the column name which depending on the value i.e . if it is matnr then f1 , if mbrsh it is f2 ..so on
Thanks.Hi ,
thanks for your replies . i am elaborating my query .
I have an internal table with 80 fields i.e.f1,f2,f3......f80 . In the first index i will be having the fieldnames
i.e.matnr , mbrsh , meins , mtart ..... . From second index onwards i will be having the corresponding data for the field name. i need to display a particular field in a table control . Here i will be knowing the fieldname. If i can get to know the column name i.e whether f1 or f2 or ... .i Can populate the data into the table control.
Wht i have done is taken a field symbol and used the following code.
read table i_upload index 1 assigning <lv_upload>.
here i will get the initial first record i.e
F1 MATNR
F2 MBRSH
F3 MTART
F4 WERKS
F5 LGORT
F6 VKORG
F7 VTWEG
F8 MAKTX
F9 MEINS
F10 MATKL
F11 BISMT
F12 BRGEW
F13 GEWEI
F14 NTGEW
F15 GROES
F16 KLART
F17 CLASS
F18 SPART
F19 VRKME
F20 UMREN
now i want to the field name .
Hope it is clear this time .
Thanks. -
Reading csv file how to get the Column name
Hi,
I am trying to read a csv file and then save the data to Oracle.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:;Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=.;Extensions=csv,txn");
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select * from filename.csv");
while(rs.next())
System.out.println(rs.getString("Num"));
My csv file looks like this:
"CHAM-23","COMPANY NAME","Test","12",20031213,15,16
Number,Environ,Envel,Date,Time
"1","2",3,"4",5
"6","7",8,"9",9
Now is there anyway using the above code I start processing the file from the second row that holds the names of the columns and skip the first row. And also can I get the name of the column using ResultSet something like:
if columnName.equals("Number")
Because I may have a csv file that could have more columns:
"CHAM-24","COMPANY NAME","Test","12",20031213,16,76
Number,Environ,Envel,Date,Time,Total,Count
"1","2","3","4","5",3,9
"6","7","8","9",9",,2
So I want to get the column name and then based on that column I do some other processing.
Once I read the value of each row I want to save the data to an Oracle Table. How do I connect to Oracle from my Application. As the database is on the server. Any help is really appreciated. ThanksThe only thing I could think of (and this is a cluj) would be to attempt to parse the first element of each row as a number. If it fails, you do not have a column name row. You are counting on the fact that you will never have a column name that is a number in the first position.
However, I agree that not always placing the headers in the same location is asking for trouble. If you have control over the file, format it how you want. If someone else has control over the file, find out why they are doing it that way. Maybe there is a "magic" number in the first row telling you where to jump.
Also, I would not use ODBC to simply parse a CSV file. If the file is formatted identically to Microsoft's format (headers in first row, all subsequent rows have same number of columns), then it's fine to take a shortcut and not write your own parser. But if the file is not adhering to that format, don't both using the M$ ODBC driver.
- Saish
"My karma ran over your dogma." - Anon
Maybe you are looking for
-
Problem in conditions pricing updation using BAPI_PO_CREATE1
hi, I am creating PO using BAPI_PO_CREATE1 however when i am passing the data to the bapi for conditions at item level the price value is not changing and throwing error as ( NET PRICE FOR ITEM 00010 adopted from last document ) so for all the it
-
Hi Everyone, I have an issue regarding the table PAYR, when run in transaction se16 and after entering the vendor numbers it shows only the payments made by check till 2004 and not after that since the payment to that vendor was changed to wire. It i
-
SQL for a report in Reports Builder
I have a long query that is for all the variables for a report I am building in Reports Builder. So far everything is correct except one column in behaving pretty strangely. For some reason the value in each row is showing up as the same as the value
-
How can I build a sum of two rows in a CNiReal64Matrix?
How can I build a sum of two rows in a CNiReal64Matrix?
-
Deleted my os x lion by accident how can i reinstall without paying for it
need to reinstall os x lion