‎2009 Jan 16 5:35 AM
HI,
I have a variable,program dynmically stores the database table name in that variable,
i want to fetch key fields of variable and also i need to fetch key fiedl values from the same variable.
and finally move into main internal table.
2. is there any select syntax to fetch only key fields of any table without mention seperately fields in select query.
‎2009 Jan 16 6:43 AM
Hi,
yes, it is possibel to pick up the key-fields of the table, see the below query.
data: begin of keytab occurs 0,
fieldname like dd03l-fieldname,
end of keytab.
parameters: table like dd03l-tabname.
select fieldname into table keytab
from dd03l
where tabname = table
and keyflag = 'X'.
loop at keytab.
write:/ keytab-fieldname.
endloop.thanks\
Mahesh
‎2009 Jan 16 6:43 AM
Hi,
yes, it is possibel to pick up the key-fields of the table, see the below query.
data: begin of keytab occurs 0,
fieldname like dd03l-fieldname,
end of keytab.
parameters: table like dd03l-tabname.
select fieldname into table keytab
from dd03l
where tabname = table
and keyflag = 'X'.
loop at keytab.
write:/ keytab-fieldname.
endloop.thanks\
Mahesh
‎2009 Jan 16 11:30 AM
Mahesh,Thanks for ur suggestion,
as per ur logic,now in that internal table all the key fields are there.
My requirement is i need to fetch values of those key fields from the same variable(acts as table).
‎2009 Jan 16 11:42 AM
Hi Satya,
Now you have your fields in the int table key tab.
SELECT (keytab)
FROM (tab_name) INTO TABLE itab WHERE...here tab_name contains data base table name.
Regards,
Manoj Kumar P
Edited by: Manoj Kumar on Jan 16, 2009 1:15 PM
‎2009 Jan 16 11:46 AM
Hi satya,
yes, we can do that too, execute this.
tables: dd03l.
*data: begin of keytab occurs 0,
* fieldname like dd03l-fieldname,
* end of keytab.
parameters: table like dd03l-tabname.
select single fieldname into (dd03l-fieldname)
from dd03l
where tabname = table
and keyflag = 'X'.
select (dd03l-fieldname) into (dd03l-fieldname) from (table).
write: dd03l-fieldname.
endselect.thanks\
Mahesh
‎2009 Jan 16 12:33 PM
Hi Manoj/Mahesh,
As per ur code,select query throws syntax check,.
select (key_tab) into itab from (table-name)
where = .
error is key_tab is not an internal table.system reads as internal table.
what to do.
‎2009 Jan 16 12:55 PM
Satya,
My query returns data for the single key-filed of the selected table.
And I think u can't get the data for all the key-fields of the table at a time as structure of the 'itab' can't be defined at the run-time.
If u want to execute query like this
select (keytab) into table itab from (table).u've to build the dynamic internal table for the selected key-fields.
And for more info, search with 'dynamic internal table' in the forums
hope u got me.
regards\
Mahesh