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

Dynamic select statement

Former Member
0 Likes
3,458

I want to create dynamic select statement I have following scenario

I have a table with fields

Table name

Field name to select

Restriction

Consider I have following data in that which can change I mean users wish to enter data in it.

SELECT (Field name to select)

INTO temp

FROM table name

WHERE Field name to select = restriction.

My problem is how to build a select where I only have name of the field.

Please reply as soon as possible.

5 REPLIES 5
Read only

Former Member
0 Likes
626

You can have the name of the table in a variable.

Have the fields you want to select in a internal table with one field in it.

SELECT (ITAB) FROM (TABLE) INTO CORRESPONDING FIELDS OF TABLE.

However, I am not sure if you can have a where clause as the name of the table is determined at runtime, the system will not be able compile the where clause.

So, you can make that also dynamic. Add the WHERE clause in a internal table.

SELECT (ITAB) FROM (TABLE) INTO CORRESPONDING FIELDS OF TABLE ITAB1 where (COND_TAB).

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
626

This helped but one more point want to clear as your statement

SELECT (ITAB) FROM (TABLE) INTO CORRESPONDING FIELDS OF TABLE.

(ITAB) like you mentioned here I have minimum 2 field.

consider

SELECT MATERIAL PROD_HIER FROM ....

I want to make this dynamic

I mean

SELECT (ITAB1) (ITAB2) INTO (temp1,temp2)

FROM ...

but this dose not work....

Could you please provide me the format to do this

Thanks

Read only

0 Likes
626

Hi,

You can make it dynamic as follows:

 

concatenate V_SEL_FIELDS 'MATERIAL' 'PROD_HIER ' separated  by space.

       SELECT (V_SEL_FIELDS) FROM (V_SEL_FROM)
                             UP TO V_MAX_RECS ROWS
                              INTO CORRESPONDING FIELDS OF TABLE <FS_INTO>
                             WHERE (V_SEL_WHERE).

Raja T

Read only

0 Likes
626

ITAB is a table with one field, so you should append the name of the fields in one line each per field.

fieldname = 'MATERIAL'.

APPEND FIELDNAME TO ITAB.

fieldname = 'PROD_HIER'.

APPEND FIELDNAME TO ITAB.

SELECT (ITAB) INTO ....

Regards,

Ravi

note - Please mark all the helpful answers

Read only

Former Member
0 Likes
626

do you also want to create a dynamic fill in screen ? since when you select a different field the conditions on the restrictions must change according to the fieldname

That is not possible in standard ABAP. what you want is a lot of work while you can also make a standard selection screen which does the same quite easily.

Or you must do it in webbased applications but even then it's a lot of work