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 at itab where..

Former Member
0 Likes
1,756

Hi all,

Can I restrict for more than one value in my where condition for looping at internal table?

For ex. I have an internal table(ITAB) for purchase order details of different document types.I'ld like to call the data of only document type(BSART) = 'XXXX','YYYY','ZZZZ' only. How can write the loop statement . I have tried with LOOP AT ITAB WHERE BSART CS ( 'XXXX' , 'YYYY' , 'ZZZZ' ).But it's showing syntax error.please help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,661

You can use Ranges and use IN in Where condition.

data: r_basrt type range of bsart.

"populate the range values.


loop at itab where bsart in r_bsart.

endloop.

Hi all,

Can I restrict for more than one value in my where condition for looping at internal table?

For ex. I have an internal table(ITAB) for purchase order details of different document types.I'ld like to call the data of only document type(BSART) = 'XXXX','YYYY','ZZZZ' only. How can write the loop statement . I have tried with LOOP AT ITAB WHERE BSART CS ( 'XXXX' , 'YYYY' , 'ZZZZ' ).But it's showing syntax error.please help.

13 REPLIES 13
Read only

Former Member
0 Likes
1,661

Hi,

Try this

LOOP AT ITAB WHERE BSART IN ( 'XXXX' , 'YYYY' , 'ZZZZ' )

Regards,

Surinder

Read only

0 Likes
1,661

>

> Try this

>

> LOOP AT ITAB WHERE BSART IN ( 'XXXX' , 'YYYY' , 'ZZZZ' )

> Surinder

STNTAX ERROR

Read only

Former Member
0 Likes
1,661

Hi,

Loop at itab where doctype = 'XXX' or
                           doctype = 'YYY' or
                           doctype = 'ZZZ'.




Endloop.

Best regards,

Prashant

Read only

Former Member
0 Likes
1,661

Hi Jayasree,

U can try this...

LOOP AT ITAB WHERE BSART IN ( 'XXXX' , 'YYYY' , 'ZZZZ' ).

This should work...

Regards,

Navin

Read only

0 Likes
1,661

>

> Hi Jayasree,

>

> U can try this...

>

> LOOP AT ITAB WHERE BSART IN ( 'XXXX' , 'YYYY' , 'ZZZZ' ).

> This should work...

>

> Regards,

> Navin

Sorry It will not work!!

Read only

0 Likes
1,661

Yes,I have already tried that and got syntax error.

Of course, we can write conditions using OR if the doc. type values are two or three. Is there any other solution if there are no. of such particular values to be mentioned in WHERE condition?

Read only

Former Member
0 Likes
1,661

Hi

I think you can try the following

Loop at itab where bsart = 'XXXX' or

bsart = 'YYYY' or

bsart = 'ZZZZ'.

endloop.

or

Loop at itab.

if itab-bsart = 'XXXX' or

itab-bsart = 'YYYY' or

itab-bsart = 'ZZZZ'.

endif.

endloop.

Regards

MD

Read only

naveen_inuganti2
Active Contributor
0 Likes
1,661

Hi...

You cantry like this..,

loop at itab Field1 = A or Field1 = B or Field1 = C

Thanks,

Naveen.I

Read only

Former Member
0 Likes
1,661

Hi Jayasri,

Use :

Loop at itab where BSART = 'XXX' or BSART = 'YYY' or

BSART = 'ZZZ'.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,662

You can use Ranges and use IN in Where condition.

data: r_basrt type range of bsart.

"populate the range values.


loop at itab where bsart in r_bsart.

endloop.

Read only

0 Likes
1,661

Hi vijay,

I am new to this syntax.Let me try once.Thank u.

Read only

0 Likes
1,661

Thank u Vijay,

my problem is solved. It's working fine.

Read only

Former Member
0 Likes
1,661

hi,

Try this below code. it will work.

loop at i_po_data into wa_po_data where bsart eq 'XYZ' or bsart eq 'ABC' or basrt eq 'PQR'.

endloop.

Regards,

Siva.