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

reading a table until i find a value

Former Member
0 Likes
1,616

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

Former Member
0 Likes
1,505
loop at itab.
  if itab-price eq CURRENT_PRICE.
     *do some thing
     EXIT.
  endif.
endif.

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

10 REPLIES 10
Read only

Former Member
0 Likes
1,506
loop at itab.
  if itab-price eq CURRENT_PRICE.
     *do some thing
     EXIT.
  endif.
endif.
Read only

0 Likes
1,505

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

Read only

Former Member
0 Likes
1,505

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.

Read only

0 Likes
1,505

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

Read only

0 Likes
1,505

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

Read only

0 Likes
1,505

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

Read only

Former Member
0 Likes
1,505

loop at itab where <YOur condition>.

exit.

endloop.

Read only

Former Member
0 Likes
1,505

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.

Read only

0 Likes
1,505

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

Read only

0 Likes
1,505

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?