2018 Aug 02 8:03 PM
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
2018 Aug 02 9:47 PM
Use the CL_SQL_STATEMENT and related classes. Then it's a doddle to dynamicly generate native SQL.
2018 Aug 02 9:47 PM
Use the CL_SQL_STATEMENT and related classes. Then it's a doddle to dynamicly generate native SQL.
2018 Aug 03 8:47 AM
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 🙂
2018 Aug 03 1:48 AM
Native SQL error is occurring because table statement from external database is missing. So, it is required (example: ... FROM xptotab).
2018 Aug 03 4:44 AM
Hi Alexandre,
Try with ADBC - ABAP Database Connectivity.
https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491920170
Regards,
Sid
2018 Aug 03 9:31 AM
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
2018 Aug 03 11:43 AM
Could be because it's the same as mine, but posted 6 hours later... ,-)
2018 Aug 03 11:54 AM
2018 Aug 04 9:53 AM
Thats fine. It's good that what I thought and answered is correct.
2018 Aug 03 7:46 AM
You use Native SQL to select from an internal table. Simply Impossible! This is only available for Open SQL.
2018 Aug 03 8:52 AM
Hi Horst,
There is a workaround to do that. Check Matthew's answer.
Have a good day.
2018 Aug 03 6:08 PM
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.
2018 Aug 04 2:16 PM
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.
2018 Aug 04 3:32 PM
2018 Aug 05 9:53 AM
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.