3

I entered a new database connection in transaction DBCO to another sap system. and testet it successfully with the report ADBC_TEST_CONNECTION.

How do I make use of this connection in a CDS view? Is it even possible? I thought it would work with table functions but didn't get it to work.

Alternatively I tried to use it within an abap programm with no success:

  data: lt_vbak(20).

  exec sql.
    CONNECT TO 'SECOND_DB'
  endexec.
  exec sql.
    SELECT vbeln into :lt_vbak FROM vbak where mandt = 500
  endexec.
  exec sql.
    DISCONNECT :'SECOND_DB'
  endexec.

It says that the table vbak does not exist.

We are currently on SAP ECC with ABAP 7.50.

Any suggestions? Thanks

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Tommehh
  • 872
  • 1
  • 17
  • 44

2 Answers2

1

Not sure about CDS views but in an ABAP program you can do it via Open SQL by using the CONNECTION option and specifying the name of your secondary database connection:

SELECT vbeln INTO TABLE lt_vbak FROM vbak WHERE mandt = 500 CONNECTION ('SECOND_DB').

However, this requires that you have table VBAK with the same structure as the VBAK that you are querying also defined in the DDIC of your ECC system.

See also the documentation for the CONNECTION parameter here: SELECT additional options

gaussd
  • 899
  • 6
  • 15
  • 28
0

This is a broad question and the information provided don't allow to tell what did not work correctly in your example.
It might just be that the logon user for the secondary connection does not connect to the correct schema or does not have the privileges to access the table VBAK.

As you basically ask for a how-to I recommend checking the extensive ABAP documentation on the topic and/or the well written and informative blog post from one of the ABAP core developers.

Lars Br.
  • 9,949
  • 2
  • 15
  • 29
  • I think the problem is that the user is connecting to the wrong schema. I haven't found a solution to connect to the right one. Is there a way to connect to a secondary database with CDS View? I have checked those links previously but they weren't really helpful at all. – Tommehh Feb 04 '19 at 08:18