In short, that's not how ABAP and function modules work.
You have to define exactly what your input is and what your output structure/table looks like. You can return one structure that holds multiple deep nested tables, to have only one return structure, but not dynamically!
Making this all dynamic makes things a lot more complex. Mostly unnecessarily.
One possible way:
- you have to anaylize the input and build dynamic structures and tables for each input table result
- build a wrapping structure that consists of all the nested tables
- return a DATA reference object, because you cannot return generic datatypes
- your receiving program needs to have the same data structures defined, this means it must exactly know what it is getting back, to defer the data.
Another way:
Use Function Module RFC_READ_TABLE in a loop in the caller program
Reading multiple single tables dynamically in a loop without a join does not sound like ABAP programming, more like "I need data from SAP in a third party tool".