Application Development 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: 

LOOP command: construction 'IN' in WHERE clause

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

suresh_datti
Active Contributor
0 Kudos

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

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

Check this :

Loop at i_docinfo where belzart eq 'AA' or

belzart eq 'LH' or

belzart eq 'SQ'.

Endloop.

Regards

Appana

former_member186143
Active Contributor
0 Kudos

use data declaration ranges

Former Member
0 Kudos

try this

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

endloop.     

Former Member
0 Kudos

Try like this

LOOP AT i_table INTO w_table WHERE status = 'A'

OR status = 'B'

OR status = 'V'.

ENDLOOP.

Regards

Kathirvel

Former Member
0 Kudos

Hi,

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

Cheers.

0 Kudos

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

kishorekumar_vemula
Active Participant
0 Kudos

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

former_member188685
Active Contributor
0 Kudos

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