Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Native SQL in SAP ABAP

kanwardeepsingh_gill
Product and Topic Expert
Product and Topic Expert
0 Likes
1,587

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
998

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.

3 REPLIES 3
Read only

Former Member
0 Likes
999

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.

Read only

0 Likes
998

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.

Read only

0 Likes
998

Thanks Manish. I implemented your logic and it is working fine. You are my saviour