Actually I am not quite sure what your requirement is exactly.
I highly recommend that you start to use proper variable and table names instead of table_1, 2, 3...
That made me read each sentence at least twice, wasting my time by that.
From what I understand this is the situation:
- you barely now databases, SQL or SAP HANA
- the solution requires dynamic structure evaluation and some kind of meta programming
- the application logic is not quite straight and very easy to get wrong
I don't see yet what the overall goal of this exercise is, so advice is difficult to provide.
It _looks_ like some data transformation/loading task and for that I'd usually say: don't reinvent the wheel. Take a ETL tool, e.g. SAP DataServices, and use that to implement the logic.
This would take away the burden of actual programming for a good part of the job and you could focus on the actual logic.
Other than that I can only recommend to get some good material (usually it's still books) on SQL and database programming and design.
- Lars