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

How to create a dynamic selection clause?

Former Member
0 Likes
585

Hi,

I have to select data from mara using different selection parameters coming from TVARVC but I do not know how to do.

SELECT matnr
FROM mara
WHERE matnr in r_matnr
   AND mtart in r_mtart.

But the users must be able to add or to suppress fields from the where clause. The fields and there values will be in the table TVARVC.

LOOP AT TVARVC

Here must I create ranges from different types to put the values in... (How to do this?)

fieldname (eg MATNR)
fieldvalue (eg MATERIAL-0001)

=> where clause
ENDLOOP

SELECT matnr
FROM MARA
(where).

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
547

the only way is to create several select-options with the values of the clause WHERE fields, so the user can add o not data to those select options.

Hi,

I have to select data from mara using different selection parameters coming from TVARVC but I do not know how to do.

SELECT matnr
FROM mara
WHERE matnr in r_matnr
   AND mtart in r_mtart.

But the users must be able to add or to suppress fields from the where clause. The fields and there values will be in the table TVARVC.

LOOP AT TVARVC

Here must I create ranges from different types to put the values in... (How to do this?)

fieldname (eg MATNR)
fieldvalue (eg MATERIAL-0001)

=> where clause
ENDLOOP

SELECT matnr
FROM MARA
(where).

Thanks

3 REPLIES 3
Read only

Former Member
0 Likes
548

the only way is to create several select-options with the values of the clause WHERE fields, so the user can add o not data to those select options.

Read only

0 Likes
547

After a discussion, we decide to change the rules.

We decide to write the where clause in SQL It should be simplier but...


  DATA : w_where(60) TYPE c.
 
 LOOP AT tvarvc.
....
  CONCATENATE tvarvc-low
   INTO w_where.
...
 ENDLOOP.

(w_where: MTART = TEST; i tried MTART = "TEST")

   SELECT matnr
    INTO TABLE t_marx
    FROM mara
    WHERE (w_where).

This simple code dump... I try to have MTART = 'TEST' but same result.

Why?

Edited by: David31 on Apr 26, 2010 6:58 PM

Read only

0 Likes
547

Hi,

You should have tried with MTART = 'TEST' instead of "TEST". Observe the quotes!!!

Check below sample code.

DATA: i_mara  TYPE TABLE OF mara,
      w_where TYPE string.

CONCATENATE 'MTART =' '''TEST'''  INTO w_where SEPARATED BY space.  "Look at the quotes

SELECT * INTO TABLE i_mara
FROM mara
WHERE (w_where).
WRITE sy-subrc.

Check F1 help for more details.

Subject line confused me little bit. It is where clause instead of selection clause:-)

Thanks,

Vinod.