11-22-2006 1:43 PM
Hello,
Can somebody give me an example how to use construction 'IN' in WHERE clause in LOOP command. Construction 'IN' means restriction to values in list.
For example in SELECT command:
SELECT * FROM zdocinfo INTO ls_doc_info
WHERE
belzart IN ('AA', 'LH', 'SQ').
Similar construction in LOOP command generates syntax error.
Best regards,
Josef Motl
11-22-2006 1:48 PM
Hi
U should use a range.
RANGES: R_BELZART FOR ZDOCINFO-BELZART.
R_BELZART(3) = 'IEQ'.
R_BELZART-LOW = 'AA'.
APPEND R_BELZART.
R_BELZART-LOW = 'LH'.
APPEND R_BELZART.
R_BELZART-LOW = 'SQ'.
APPEND R_BELZART.
LOOP AT T_ZDOCINFO WHERE BELZART IN R_BELZART.
ENDLOOP.
Max
11-22-2006 1:47 PM
Hi,
use below example
ranges r_matnr or mara-matnr.
r_matnr-sign = 'I'.
r_matnr-option = 'EQ' .
r_matnr-low = 'AA'.
append r_matnr.
r_matnr-low = 'LH'.
append r_matnr.
r_matnr-low = 'SQ'.
append r_matnr.
loop at itab where matnr in s_matnr.
endloop.
Regards
Amole
11-22-2006 1:48 PM
Hi
U should use a range.
RANGES: R_BELZART FOR ZDOCINFO-BELZART.
R_BELZART(3) = 'IEQ'.
R_BELZART-LOW = 'AA'.
APPEND R_BELZART.
R_BELZART-LOW = 'LH'.
APPEND R_BELZART.
R_BELZART-LOW = 'SQ'.
APPEND R_BELZART.
LOOP AT T_ZDOCINFO WHERE BELZART IN R_BELZART.
ENDLOOP.
Max
11-22-2006 1:48 PM
I don't think you can use the IN operator in a Loop at Where statement..
You will ahve to do use the OR ie
Loop at itab where ( belzart eq 'AA' or
belzart eq 'LH' or
belzart eq 'SQ' ).
...
endloop.
~Suresh
11-22-2006 1:49 PM
Hi,
Check this :
Loop at i_docinfo where belzart eq 'AA' or
belzart eq 'LH' or
belzart eq 'SQ'.
Endloop.
Regards
Appana
11-22-2006 1:49 PM
11-22-2006 1:50 PM
try this
loop at itab where matnr = 'AA' or
matnr = 'LH' or
matnr = 'SQ'.
endloop.
11-22-2006 1:50 PM
Try like this
LOOP AT i_table INTO w_table WHERE status = 'A'
OR status = 'B'
OR status = 'V'.
ENDLOOP.
Regards
Kathirvel
11-22-2006 1:50 PM
Hi,
U have to use range then only u can use IN Operator other wise it will not work.
Cheers.
11-22-2006 1:57 PM
use amoles code to make the range
with select you have 2 options
SELECT * FROM zdocinfo
INTO CORRESPONDING FIELDS OF TABLE ls_doc_info
WHERE belzart IN r_matnr.
(above puts everything directly in ls_doc_info)
LOOP AT ?????
SELECT single * FROM zdocinfo
INTO CORRESPONDING FIELDS ls_doc_info
WHERE belzart IN yourrangevar.
ENDSELECT.
ENDLOOP.
or you do it for each line and have to use endselect
Message was edited by:
A. de Smidt
11-22-2006 2:00 PM
hay,
take care that " ls_doc_info " an internal table & if you want to put more conditions just use "AND" / "OR" like below.
SELECT & FROM ZDOCINFO INTO LS_DOC_INFO
where
belzart = 'AA'
OR belzart = 'LH'
OR belzart = 'SQ'.
****************************
for example, if you are selecting the belzart values from selection screen, where the selection option is s_belzart then you can try it below
s_belzart-sign = 'I'.
s_belzart-option= 'EQ'.
s_belzart-low = 'AA'.
append s_belzart.
s_belzart-sign = 'I'.
s_belzart-option= 'EQ'.
s_belzart-low = 'LH'.
append s_belzart.
s_belzart-sign = 'I'.
s_belzart-option= 'EQ'.
s_belzart-low = 'SQ'.
append s_belzart.
then write a select query like below
select * from zdocinfo into ls_doc_info
where
belzart in s_belzart.
regards,
Kish
11-22-2006 2:06 PM
Hi Josef,
you need to populate the ranges and use the range in where clause,.
loop at itab where belzart in r_belzart.
endloop.
Regards
Vijay