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: 

reading a table until i find a value

Former Member
0 Kudos

I need to read a talbe to find material price for the current price. if it isn't found i need to basically loop until i do find a price. do you have some sample code to acheive this?

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
loop at itab.
  if itab-price eq CURRENT_PRICE.
     *do some thing
     EXIT.
  endif.
endif.
10 REPLIES 10

Former Member
0 Kudos
loop at itab.
  if itab-price eq CURRENT_PRICE.
     *do some thing
     EXIT.
  endif.
endif.

0 Kudos

I need to get the price for the current month and if it is blank then I need to go to the previous month.

Former Member
0 Kudos

First read the database table in an internal table using where Select and WHERE clause to identify the records.

Then loop at itab where price eq CURRENT_PRICE.

  • process further - for ex copy to another internal table

append itab to current_price_table.

endloop.

Please reward points if useful.

0 Kudos

so would you 1st select all records for that material and put into a table. I then need to see if there is a price fo the current and if not i need to loop until I find a price. Is there anyway to limit what come back in my select becuase if I have the current price fo rth emonth I don't need to get all the records but maybe this is faster than reading 1 record at a time

0 Kudos

how about selecting all the current month prices then checking if the ones you want are there, any that aren't save to a separate table then for all those do a second select to the database to get all previous month prices.

Are you using full keys for your DB selects? If you can use select single then loop/select single is not much different from selectfor all entries

0 Kudos

I am doing a select for all entries and putting into an internal table.

former_member181962
Active Contributor
0 Kudos

loop at itab where <YOur condition>.

exit.

endloop.

Former Member
0 Kudos

Hi MICK,

See if this can be useful.

data: variable like currentprice.

move current price into variable.

select keyfield materialprice values from dbtable into table internaltable

where filteringcondition1(column name of the dbtable) = value of

filteringcondition1.

loop at internaltable where key field = keyfield value and

material price = current price.

perform actions need

to be done when material price

is equal to current price.

endloop.

Award points if useful.

Regds,

Ravi Sankara Kumar.

0 Kudos

Same as Ravi's except you dont need the exit in the loop. If the where condition is not satisfied it wont even go inside the loop.

loop at itab where <YOur condition>.

Record is found, process your code here.

endloop.

hith

Sunil Achyut

0 Kudos

I think I exlained incorectly. I don't know my material price and need to loop until I find a value so i fiest need to look at the current month and if not found keep going back. would i just subtract 1 from the month and do a nested loop?