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 Query-Odata

aditi_br
Advisor
Advisor
0 Likes
1,115

Hi

I would like to know which type of select statement to be used if the values(or the number of values) in the where clause is not fixed. I have three input fields, and from the UI( Fiori app) I might fill just two fields or I might fill up all the fields. Regarding this, my select statement should consider the values for filter and provide the result accordingly.

Thanks & Regards,

Aditi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
866

Hi Aditi,

To build dynamic select quiery you can use FM RH_DYNAMIC_WHERE_BUILD

4 REPLIES 4
Read only

Former Member
0 Likes
867

Hi Aditi,

To build dynamic select quiery you can use FM RH_DYNAMIC_WHERE_BUILD

Read only

Former Member
0 Likes
866

Hi Aditi,

you can check for the null values using IS NOT INITIAL and can combine it with IF-ELSE statement to provide the corresponding select statement.

for e.g.

SELECTION-SCREEN: BEGIN OF BLOCK SEL WITH FRAME TITLE TEXT-001.
PARAMETERS     : MAT   TYPE MARD-MATNR.
PARAMETERS     : PLANT TYPE MARD-WERKS.
PARAMETERS     : STLOC TYPE MARD-LGORT.
SELECTION-SCREEN: END OF BLOCK SEL.

START-OF-SELECTION.

IF STLOC IS NOT INITIAL.
SELECT * FROM MARD INTO TABLE ITAB WHERE MATNR = MAT AND WERKS = PLANT AND LGORT = STLOC.
ELSEIF PLANT IS NOT INITIAL.
SELECT * FROM MARD INTO TABLE ITAB WHERE MATNR = MAT AND WERKS = PLANT.
ELSEIF MAT IS NOT INITIAL.
SELECT * FROM MARD INTO TABLE ITAB WHERE MATNR = MAT.
ELSE.
SELECT * FROM MARD INTO TABLE ITAB.
ENDIF.

Read only

vinodkumar_thangavel
Participant
0 Likes
866

Hi,

If the input is dynamic in that case better u shall go for range tables to be filled up with values and pass the same to  select query.

Regards,

Vinodkumar.

Read only

aditi_br
Advisor
Advisor
0 Likes
866

Thanks all