Skip to Content
0
Former Member
Oct 10, 2012 at 07:03 AM

Connections between tables

417 Views

Hi,

I need to find a way to dynamically include the connections between several tables into a SELECT command. The scenario is:

- A user enters a nr of tables and a fieldlist for each of them.

- I process these in several loops and I build an internal table made up of all these fields (from n different DB tables)

using the method create_dynamic_table of ABAP class cl_alv_table_create.

- I then have one fieldlist with all fields written in the proper OpenSQL syntax like >KNA1~KUNNR< and so forth.

- I can plug this list into the SELECT command so this part of it is independent of how many fields from how many (and which) tables are in the list.

The catch is: The SELECT command also includes a FROM part which currently reads

FROM KNC1

JOIN KNB1 ON KNB1~KUNNR = KNC1~KUNNR AND KNB1~BUKRS = KNC1~BUKRS

JOIN KNA1 ON KNA1~KUNNR = KNC1~KUNNR

JOIN T001 ON T001~BUKRS = KNB1~BUKRS

I have chosen this example because I knew by heart how to join these tables. I know I can view the

connection between two arbitrary tables (if there is any) via SE11, so i deduce the information must be somewhere.

The task now is finding out where I can get this information.

In the long run then, the user will throw a bunch of tables at me and I have to dynamically implement the connections between them. As an alternative, I can still provide the necessary fields in the dialog and have the user enter the connection details, but I would like to take that hazzle off the user.

Can anybody help me in any way to achieve this?

Thanks a lot!

Best regards,

Sapperdapper