Application Development 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: 

Select query as input in PARAMETERS.

Former Member
0 Kudos

Hi Expert,

We need to give input as Select query. Like below are examples.

1) Select * from ekko into table it_data where bukrs = 3000. or

2) select fld1 fld2 fld3 from tablename into it_data up to 10 rows where fld4 = XXXXX.

We want to pass only such query as input and want result according to them. User can put any table name, can chose any table fields, also he can use inner join group by statements also.

Remember we want to pass only select query by user in PARAMETERS as below.

parameters: option type string.

In Option we need to wright that select query.

Please provide some coding samples.

Thanks And Regards

Ranjeet Singh

5 REPLIES 5

Former Member
0 Kudos

Rather strange requirement. Sounds like now the users should know ABAP programming.

Jokes apart, you can use the INSERT REPORT and GENERATE SUB-ROUTINE syntaxes to generate the program based on the query given by the user.

Simple idea would be to have a sub-routine pool with commented code, the code will be generate using GENERATE SUB-ROUTINE based on the syntax given by user. But again, you need to also create data structures and internal table for result at runtime, for which you can use RTTI constructs.

Regards

Ranganath

0 Kudos

Hi Ranganath,

Yes this is strange requirement and i already told to client for such feasibilities. Actually before this i was passing a table name and where condition in input parameter, based on this report fetches the data from database for particular table. But now they want this in different manner like i mentioned in my actual requirement. Can you write the sample code for this. As i am not sure about such coding and no idea for RTTI.

Thanks And Regards

Ranjeet Singh

0 Kudos

For RTTI constructs you can refer to following wiki and thread which in turn describes many possibilities. This is useful for creating run time data structures and internal tables.

http://wiki.sdn.sap.com/wiki/display/ABAP/RuntimeTypeServices+(RTTS)

http://help.sap.com/abapdocu_70/en/ABENNEWS-640-RTTI.htm

And for using subroutine pool, check the thread

Regards

Ranganath

0 Kudos

I think you should stay in strong oposition to customer requirement like that. This is like dynamic SQL, which if not authenticated properly would give a user to insight very sensitive data (like salaries, payments etc). Actually in SAP there is some sophisticated tool like that, called SAP Query. The user who have proper authorization can create any query he likes with no ABAP knowledge at all. I would really stick to what SAP provides by standard.

If your custmer, is however persistent in his decision (he pays, he decides), you should developed such tool with dynamic program generation, which as mentioned above can be achieved with [GENERATE SUBROUTINE POOL|http://help.sap.com/abapdocu_70/en/ABAPGENERATE_SHORTREF.htm]. RTTS will not help here as they can be used only for dynamic structure/tables generation, not queries themselves.

Regards

Marcin

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi,

You can have a look at class CL_SQL_STATEMENT , method EXECUTE_QUERY.

For more details search for CLSQL in se24.

Be sure and make note of the comment by Marcin.