‎2013 Jul 19 10:25 AM
I have a requirement where I need to use NATIVE SQL to fetch data from ORACLE database tables. I need to use an inner join on these tables to read data in my program. Kindly help me with the syntax to be used for the NATIVE SQL JOIN query.
‎2013 Jul 19 10:31 AM
Why is Open SQL not used for your requirement?
Here is one code sample for native sql join.
EXEC SQL PERFORMING subroutine_name.
SELECT
aa.field1
, aa.field2
, bb.field1
, bb.field3
INTO
:wa-f1
, :wa-f2
, :wa-f3
, :wa-f4
FROM
table1 aa
, table2 bb
where aa.mandt = :sy-mandt
and aa.field1 = 'A'
and bb.mandt = :sy-mandt
and bb.field2 = :lv_field1
ENDEXEC.
FORM subroutine_name.
* wa-f1 , wa-f2, wa-f3, wa-f4 will have values from above query.
* for every record found, the subroutine will be called
APPEND wa TO it.
ENDFORM.
‎2013 Jul 19 10:31 AM
Why is Open SQL not used for your requirement?
Here is one code sample for native sql join.
EXEC SQL PERFORMING subroutine_name.
SELECT
aa.field1
, aa.field2
, bb.field1
, bb.field3
INTO
:wa-f1
, :wa-f2
, :wa-f3
, :wa-f4
FROM
table1 aa
, table2 bb
where aa.mandt = :sy-mandt
and aa.field1 = 'A'
and bb.mandt = :sy-mandt
and bb.field2 = :lv_field1
ENDEXEC.
FORM subroutine_name.
* wa-f1 , wa-f2, wa-f3, wa-f4 will have values from above query.
* for every record found, the subroutine will be called
APPEND wa TO it.
ENDFORM.
‎2013 Jul 19 11:16 AM
Because the tables are created in the ORACLE DB and not created via SAP ABAP Dictionary.
We have to read data from the external ORACLE database.
Since the tables don't exist in the ABAP data dictinary, we cannot use OPEN SQL.
‎2013 Jul 19 12:10 PM
Thanks Manish. I implemented your logic and it is working fine. You are my saviour