Once in a while there comes a situation where we have to write Several Select queries to achieve similar functionality(with minor
change in the where condition. )
In such situations we simply start writing multiple select queries covering all the scenarios.
For Eg:query1 :-
SELECT * FROM vbap into table t_vbap
where VBELN eq p_vbeln.
For Eg:query2 :-
SELECT * FROM vbap into table t_vbap
where VBELN eq p_vbeln and posnr eq p_posnr.
What, We don't realise is that by making our select queries dynamic, we can minimize the effort as well as the number of code lines
Now the question is how do we do it. .
Well... I'll take a very basic example .....
PARAMETERS: p_vbeln type vbap-vbeln obligatory,
p_posnr type vbap-posnr.
DATA: lv_where TYPE string "Declaring a string variable to manipulate our WHERE clause
INITIALIAZATION.
lv_where = ' VBELN EQ P_VBELN '.
START-OF-SELECTION.
if p_posnr is not initial.
CONCATENATE lv_where 'AND POSNR EQ P_POSNR' into lv_where.
endif.
SELECT * FROM VBAP into t_vbap WHERE (lv_where).
Yipeeeee ...Our code is ready !!!!!
Regards,
Faiz