03-26-2009 7:05 AM
Dear All,
I would like to ask if it is possible to use variable inside WHERE-IN clause.
Say:
SELECT id name INTO TABLE itab FROM table WHERE id IN ('A','B','C').
I would like 'A','B','C' to be in a variable e.g. mytext so that it would be:
SELECT id name INTO TABLE itab FROM table WHERE id IN (mytext).
Thank you very much.
Points will be awarded.
Regards,
Rayel
03-26-2009 7:10 AM
Hi Rayel,
Yes of course. Try this way:
data:
w_var(10) type c.
Ranges:
r_var1 for w_var.
r_var1-sign = 'I'.
r_var1-option = 'EQ'.
r_var1-low = 'A'.
append r_var1.
r_var1-sign = 'I'.
r_var1-option = 'EQ'.
r_var1-low = 'B'.
append r_var1.
r_var1-sign = 'I'.
r_var1-option = 'EQ'.
r_var1-low = 'C'.
append r_var1.
SELECT id name INTO TABLE itab FROM table WHERE id IN r_var1.
This will solve.
Regards,
Swapna.
03-26-2009 7:10 AM
Hi Rayel,
Yes of course. Try this way:
data:
w_var(10) type c.
Ranges:
r_var1 for w_var.
r_var1-sign = 'I'.
r_var1-option = 'EQ'.
r_var1-low = 'A'.
append r_var1.
r_var1-sign = 'I'.
r_var1-option = 'EQ'.
r_var1-low = 'B'.
append r_var1.
r_var1-sign = 'I'.
r_var1-option = 'EQ'.
r_var1-low = 'C'.
append r_var1.
SELECT id name INTO TABLE itab FROM table WHERE id IN r_var1.
This will solve.
Regards,
Swapna.
03-26-2009 7:55 AM
Hi Swapna,
Thanks. This is exactly what I needed and it worked!
Thanks to everyone who responded.
Points awarded.
Regards,
Rayel
03-26-2009 7:10 AM
Hi,
Instead you can create range and pass to select query.
Sample Code:
DATA: l_count_bsid TYPE tbmaxsel,
l_bal_count TYPE tbmaxsel,
lt_blart TYPE lvc_t_rngs,
ls_blart TYPE lvc_s_rngs.
Creating the Value Range for Document type
ls_blart-sign = 'I'.
ls_blart-option = 'EQ'.
ls_blart-low = 'Value1'.
APPEND ls_blart TO lt_blart.
CLEAR ls_blart.
ls_blart-sign = 'I'.
ls_blart-option = 'EQ'.
ls_blart-low = 'Value2'.
APPEND ls_blart TO lt_blart.
CLEAR ls_blart.
Get Accounting: Secondary Index for Customers data(BKPF table)
SELECT * FROM bsid
UP TO p_no_re ROWS
INTO TABLE it_bsid
WHERE bukrs IN s_bukrs AND
gjahr IN s_gjahr AND
belnr IN s_belnr AND
blart IN lt_blart.
You can add as many as you want.
Regards,
Prashant.
03-26-2009 7:10 AM
absolutely yes. in that case u have to declare the variable as SELECT-OPTIONS in the SELECTION-SCREEN event,
Eg.
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1.
SELECT-OPTIONS: v_input_var FOR VBAP-VBELN.
SELECTION-SCREEN END OF BLOCK BLOCK1.
START-OF-SELECTION.
SELECT VBELN
POSNR
FROM VBAP INTO TABLE IT_TAB
WHERE VBELN IN v_input_var.
Regards,
Anirban.
03-26-2009 7:11 AM
03-26-2009 7:18 AM
Hi,
You can create a range of these three values like:
data: r_value for table name-field name(which of character type length 1).
In Initialization Event you can fill this range like:
r_value-low = 'A'.
r_value-sign = BT.
r_value-high = 'C'.
Append r_value.
And Then in your Select Query,
Select Field from Table name into Internal Table name
where id IN R_value(Range name).
Hope it helps
Regards
Mansi
03-26-2009 8:08 AM
Hi,
You can use select-options if that is feasible, or else you have to use ranges or tables.
03-26-2009 8:12 AM
Hi Rayel
Going by the basic definition of IN clause it hold the result true for rows where the value matches with them.However to specify vaiable instead of actual values may not work as it evaluates values.
An alternative solution to this is in declaration of a macro instead of a variable before the select query is
written.one can use macros to replace any set of repetitive statements that check or modify values of variables.the value of a macro definition is substituted at run time of program.
Take alook at this to understand macros in abap -http://www.builderau.com.au/news/soa/Unleash-the-power-of-macros-in-ABAP/0,339028227,320276178,00.htm
Regards
Amarjot