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. ) Image may be NSFW.
Clik here to view.
In such situations we simply start writing multiple select queries covering all the scenarios.Image may be NSFW.
Clik here to view.
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 Image may be NSFW.
Clik here to view.
Now the question is how do we do it. Image may be NSFW.
Clik here to view. .
Well... I'll take a very basic example .....Image may be NSFW.
Clik here to view.
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 Image may be NSFW.
Clik here to view....Our code is ready Image may be NSFW.
Clik here to view. !!!!!
Regards,
Faiz