Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Select statement queries.

Former Member
0 Likes
317

Hi, I want to write code for the following two requirements:

1. I am accepting a value as parameter in p_param (say). I am then concatenating a few characters to this value in p_param and putting it back in p_param. Now I want perform a select statement with the value in p_param as the table name in the select statement. Although a table with the value in p_param exists, the system is not allowing me to use the parameter p_param in the select statement saying that p_param is not defined in DataBase Dictionary as Table or projection or database view. But I would still like to use it in select statement. How can I do it.

2. The user inputs the name of a field as a parameter in p_field. I want to first check if the database table contains any field with the name the User entered in p

_field. How do I write this logic?

Thanks in advance.

2 REPLIES 2
Read only

Former Member
0 Likes
289

Hi Kiran

I guess you should build logic similar to below:

parameters: p_table type tabname,
            p_field type fieldname.

concatenate p_table 'XXX'  into p_table.

select * into itab
  from (p_table)
  where <cond>.
  
  
select single fieldname into p_field
  from dd03l 
  where tabname = p_table
  and   fieldname = p_field.
  
If sy-subrc eq 0.
  write:/ 'Yes the field exists in table'.
Else.
  write:/ 'No the field doesnt exist'.
Endif.

Regards

Eswar

Read only

Former Member
0 Likes
289

Hi Kiran,

Adding to Eswar's reply, U can even check that whether the table with that name exists or not in table DD02L. Like this,

parameters: p_table type tabname,

p_field type fieldname.

concatenate p_table 'XXX' into p_table.

select single tabname from dd02l into tabname where tabname = p_table.

if sy-subrc eq 0.

Message 'Table Exists'.

else.

Message 'Table Does not exist'.

endif.

-SatyaPriya