2014 Oct 15 6:50 AM
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
2014 Oct 15 7:18 AM
Hi Aditi,
To build dynamic select quiery you can use FM RH_DYNAMIC_WHERE_BUILD
2014 Oct 15 7:18 AM
Hi Aditi,
To build dynamic select quiery you can use FM RH_DYNAMIC_WHERE_BUILD
2014 Oct 15 7:48 AM
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.
2014 Oct 15 7:53 AM
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.
2014 Oct 15 9:28 AM