Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

nested looping with select stmt

Hi Gurus,

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.

else.

total = total + wa_amount-amount.

endloop.

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.

Clear: sum,

total.

refresh: it_amount.

endloop.

refresh it_cocode.

Endloop.

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.

Thanks,

Vijay.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question