Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Playing around with Dynamic SQL's (for Starters)...!!!

$
0
0

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

 

 

 


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>