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!!!

Former Member
0 Likes
569

Hello Frnds,

Can we construct a select statement with dynamic WHERE condition??? If yes then how?

For Ex:

.

.

DATA: G_VAR(20) TYPE C.

.

.

MOVE FLD2 TO G_VAR.

SELECT FLD1 FROM TAB1

WHERE G_VAR = '20'.

.

.

REGARDS,

ARPIT

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
524

Hi,

check this below code for dynamic where in select

tables : pa0001, pa0002.

ranges : s_pernr for pa0001-pernr.

data : begin of i_pernr occurs 0,

pernr like pa0001-pernr,

end of i_pernr.

data : v_pernr like pa0001-pernr,

v_pernr1 like pa0001-pernr,

v_tab like DD02D-TABNAME.

data : v_field(72) type c.

data : i_source(72) occurs 0 with header line.

v_field = 'PERNR'.

v_pernr = '00000100'.

v_tab = 'PA0000'.

concatenate v_field '=' v_pernr into i_source

separated by space.

select pernr from PA0000

into corresponding fields of table i_pernr

WHERE (i_source) .

if sy-subrc <> 0.

write : / sy-subrc.

else.

delete adjacent duplicates from i_pernr comparing pernr.

loop at i_pernr.

write : / i_pernr-pernr.

endloop.

endif.

Thanks

Rajeev

4 REPLIES 4
Read only

Former Member
0 Likes
525

Hi,

check this below code for dynamic where in select

tables : pa0001, pa0002.

ranges : s_pernr for pa0001-pernr.

data : begin of i_pernr occurs 0,

pernr like pa0001-pernr,

end of i_pernr.

data : v_pernr like pa0001-pernr,

v_pernr1 like pa0001-pernr,

v_tab like DD02D-TABNAME.

data : v_field(72) type c.

data : i_source(72) occurs 0 with header line.

v_field = 'PERNR'.

v_pernr = '00000100'.

v_tab = 'PA0000'.

concatenate v_field '=' v_pernr into i_source

separated by space.

select pernr from PA0000

into corresponding fields of table i_pernr

WHERE (i_source) .

if sy-subrc <> 0.

write : / sy-subrc.

else.

delete adjacent duplicates from i_pernr comparing pernr.

loop at i_pernr.

write : / i_pernr-pernr.

endloop.

endif.

Thanks

Rajeev

Read only

Former Member
0 Likes
524

check this thread , this is recent one...

regards

vijay

Read only

0 Likes
524

THANKS RAJEEV AND VIJAY,

UR ANSWERS WERE VERY USEFUL. BUT I HAVE A PROBLEM...ALL MY FIELDS AND THERE VALUES FOR WHERE COMES DYNAMICALLY. So there are some values which are char and need to be put as string ('). But how to concatenate (') to the value as it is not allowing me to use ' ' ' to concatenate it to value.

For Ex:

Data: g_val(72).

move 'ABC' to g_val.

concatenate {here i want '} g_val {here i want '} into g_val.

how to do this???????

regards,

Arpit

Read only

0 Likes
524

Here ya go. Use 4 quotes.



report zrich_0002.

Data: g_val(72).
move 'ABC' to g_val.

concatenate '''' g_val '''' into g_val.

write:/ g_val.

Regards,

Rich Heilman