‎2006 Dec 12 1:52 PM
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.
‎2006 Dec 12 1:56 PM
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
‎2006 Dec 12 2:19 PM
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
‎2006 Dec 12 2:24 PM
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
‎2006 Dec 12 2:25 PM
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
‎2006 Dec 12 1:56 PM
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