Application Development 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: 

Dynamic table in ABAP NATIVE SQL statement

alexandreourth
Active Participant

Hello experts,

I'm in SAP ECC6 system and I'm working with an external Database. I use Native SQL statement to dialog with it ( CONNECT TO db ...) EXEC SQL.

     EXEC SQL
             OPEN C FOR SELECT * FROM :gv_table
        ENDEXEC.

      DO.
        EXEC SQL.
          FETCH NEXT C INTO :<fs_line>
        ENDEXEC.
         ......

The gv_table is a data from my ABAP program which is well filled. When i execute, i have an oracle error which says : "Invalid table name". Or when i check the debugger the data is good.

Does someone know how to perform an Native SQL query with a dynamic FROM clause please?

Kind regards,

Alexandre

1 ACCEPTED SOLUTION

matt
Active Contributor

Use the CL_SQL_STATEMENT and related classes. Then it's a doddle to dynamicly generate native SQL.

14 REPLIES 14

matt
Active Contributor

Use the CL_SQL_STATEMENT and related classes. Then it's a doddle to dynamicly generate native SQL.

alexandreourth
Active Participant
0 Kudos

Hi Matthew,

I did it! Thanks a lot for the tip really helpful!

It was a combination of this class and another one and it did the work!!!!

Have a good day 🙂

roberto_forti
Contributor
0 Kudos

Native SQL error is occurring because table statement from external database is missing. So, it is required (example: ... FROM xptotab).


Siddharth_Shah
Explorer

Hi Alexandre,


Try with ADBC - ABAP Database Connectivity.

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491920170

Regards,

Sid

Hi Siddharth,

Thanks for your answer. It was something like that yes. I don't know why people downvoted your answer because it is the same lead as matthew's and it's the correct one.

Have a good day

matt
Active Contributor
0 Kudos

Could be because it's the same as mine, but posted 6 hours later... ,-)

Or people are salty...don't know 🙂

0 Kudos

Thats fine. It's good that what I thought and answered is correct.

horst_keller
Product and Topic Expert
Product and Topic Expert

You use Native SQL to select from an internal table. Simply Impossible! This is only available for Open SQL.

0 Kudos

Hi Horst,

There is a workaround to do that. Check Matthew's answer.

Have a good day.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

No, it isn't.

ADBC enables dynamic Native SQL, yes.

But your Syntax for selecting data from an internal table

SELECT * FROM :gv_table

is not possible in EXEC SQL and not in ADBC.

Since 7.52 it is possible in ABAP SQL:

SELECT * FROM @gv_table

Your example simply didn't fit to the question.

0 Kudos

Yeah but Matthew and Siddarth understood what i was trying to achieve so they gave me useful hints to look for.

You sir just said "Simply Impossible" => Not helpful. It's a community here, so yeah sometimes we have to understand what the person is trying to do and not be narrow minded in our answers.

Maybe you should think about that for your next posts.

horst_keller
Product and Topic Expert
Product and Topic Expert

In fact, the help was already there ....

matt
Active Contributor

If you wish to continue to get help on this site, it's probably not a good idea to be snarky with someone who happens to be the foremost expert on ABAP. Your question as stated was unclear - I read it one way, Horst another.

If you feel a response was rude, the correct action is to notify moderator. However, in this instance I do not think Horst's answer was in any way inappropriate.

Matt - SAP Community Moderator.