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

LOOP command: construction 'IN' in WHERE clause

Former Member
0 Likes
1,430

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,380

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 REPLIES 11
Read only

Former Member
0 Likes
1,380

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

Read only

Former Member
0 Likes
1,381

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

Read only

suresh_datti
Active Contributor
0 Likes
1,380

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

Read only

Laxmana_Appana_
Active Contributor
0 Likes
1,380

Hi,

Check this :

Loop at i_docinfo where belzart eq 'AA' or

belzart eq 'LH' or

belzart eq 'SQ'.

Endloop.

Regards

Appana

Read only

Former Member
0 Likes
1,380

use data declaration ranges

Read only

Former Member
0 Likes
1,380

try this

loop at itab where matnr = 'AA' or 
                   matnr = 'LH' or
                   matnr = 'SQ'.

endloop.     

Read only

Former Member
0 Likes
1,380

Try like this

LOOP AT i_table INTO w_table WHERE status = 'A'

OR status = 'B'

OR status = 'V'.

ENDLOOP.

Regards

Kathirvel

Read only

Former Member
0 Likes
1,380

Hi,

U have to use range then only u can use IN Operator other wise it will not work.

Cheers.

Read only

0 Likes
1,380

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

Read only

kishorekumar_vemula
Active Participant
0 Likes
1,380

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

Read only

Former Member
0 Likes
1,380

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