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

select options and loop statement

Former Member
0 Likes
1,076

Dear forum,

I have the scenario where i need to restrict the loop from the select-options.

in the select-options, user enter currency.

then in the loop i need to loop base on the currency user enter.

may i know what steps should i use for the loop as loop cannot support where.

thanks

4 REPLIES 4
Read only

Former Member
0 Likes
641

HI Gengis

I have the scenario where i need to restrict the loop from the select-options.

in the select-options, user enter currency.

then in the loop i need to loop base on the currency user enter.

may i know what steps should i use for the loop as loop cannot support where.

as per your requirement.

you have some data in your internal table also you have a select-options to input values.

on the basis of the values in your select option you want to fetch the values from your internal table. right???

then there should be a field like your select option in your internal table.

select-option: s_matnr for mara-matnr.

let assume you have an internal table with matnr and other fields also and your select-options is for mara-matnr.

then you need to select the values in your internal table according to the values in your select-options like below.

SELECT MATNR field1 field2........ from dbtable into table itab where matnr = s_matnr.

the above code will give you the values matching the values in your select-options.

you need not to apply loop becasue you already have only those values for which yo u have found records in the DBTABLE.

in case you want to apply loop on an internal table on the basis of s_matnr's values, then you can write.

in this scenario you need to define 2 internal table one with already fethced values and another in which we will fetch the values according to select-options.

loop at itab into wa_itab.

read table itab1 into wa_itab1 where matnr = wa_itab-matnr.

write statement........

endloop.

before that youwill have to fetch values in itab according to s_matnr.

I hope this will clear your query.

Thanks

Lalit Gupta.

Read only

Former Member
0 Likes
641

Hi Gengis,

Firstly please be informed that LOOP does support where condition.

Lets say your a) internal table is it_tab,

b) work area is wa_tab and

c) select option is s_currency.

and Currency is a field in the internal table.

The syntax would be:

Loop at it_tab into wa_tab where currency in s_currency[].

XXXX

YYYYYY

Endloop.

Regards,

Abhijeet

Read only

Former Member
0 Likes
641

Hi...!

With loop where condition apply....!

See abap documentation for help for the condition with loop...!

Regards,

Fawad

Read only

Former Member
0 Likes
641

Hi,

You can do in the below way.

option 1 :

loop at you select -option as it is internal table with header line you can loop it and then

read your internal table in which you have values.

ie

loop at select-option.

read table itab ino wa_itab with key feild = select-option

if sy-subrc = 0 .

do your required processing.

endif.

endloop.

option 2

loop your itab with where condition on select-option

Let me know if you need further information

Regards

Satish Boguda