nested looping with select stmt
I need to create an abap program that takes i/p a database table(dbtable contains list of table names).The expected o/p is a DB table with tablename,co_code,total amt in local curr,amount in doc curr.
the following is my logic:
Select * from zmatlist into table it_tablist where zmatlist~tflag like ''. "condition to get list of table names from DB table
Loop at it_tablist into wa_tablist.
Select [distinct]co_code from (wa_tablist-tabname) into table it_cocode.
Loop at it_cocode into wa_cocode.
select amount curtype from (wa_tablist-tabname) into table it_amount where co_code = wa_cocode-cocode.
loop at it_amount into wa_amount.
if curtype eq '00'.
sum = sum + wa_amount-amount.
total = total + wa_amount-amount.
wa_result-tabname = wa_tablist-tabname.
wa_result-cocode = wa_cocode-cocode.
wa_result-AMTLC = sum.
wa_result-AMTDC = total.
Append wa_result to it_result.
when i am executing it,it is not able to recognise amount field.How to refer amount ,cocode here?
Am i writing it so complex?Is there any easy way to do it.Plz let me know if there is any.