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

Dynamic table in ABAP NATIVE SQL statement

alexandreourth
Active Participant
6,571

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
Read only

matt
Active Contributor
4,392

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

14 REPLIES 14
Read only

matt
Active Contributor
4,393

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

Read only

alexandreourth
Active Participant
0 Likes
4,392

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 🙂

Read only

roberto_forti
Contributor
0 Likes
4,392

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


Read only

Siddharth_Shah1
Explorer
4,392

Hi Alexandre,


Try with ADBC - ABAP Database Connectivity.

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

Regards,

Sid

Read only

4,392

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

Read only

0 Likes
4,392

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

Read only

4,392

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

Read only

0 Likes
4,392

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

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
4,392

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

Read only

0 Likes
4,392

Hi Horst,

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

Have a good day.

Read only

0 Likes
4,392

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.

Read only

0 Likes
4,392

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.

Read only

4,392

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

Read only

matt
Active Contributor
4,392

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.