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 "Table does not exist in database"

Former Member
0 Likes
915

Hi Developers,

I'm doing a database connection to an Oracle db and trying to read data using native SQL - I keep getting the runtime error "table does not exist in database" on the statement Fetch Next Cursor. The following is the code snippet (I've commented out the Exec SQL and Fetch Next to make sure I have a connection and I do). HR is a schema in the database and T_Donation is a table in HR.

Data: w1(3),

c1 type cursor.

************************************************************************

start-of-selection.

************************************************************************

if con_name is initial.

write: 'No connection specified'. "#EC NOTEXT

return.

endif.

  • try to open the connection and catch the errors (if any)

try.

con_ref = cl_sql_connection=>get_connection( con_name ).

catch cx_sql_exception into sqlerr_ref.

  • error occured

write:

'Could not open connection', con_name, '.'. "#EC NOTEXT

if sqlerr_ref->unknown_connection = 'X'.

write:

/ con_name, 'is not defined in DBCON'. "#EC NOTEXT

elseif sqlerr_ref->db_error = 'X'.

write:

/ 'sql error', sqlerr_ref->sql_code, 'occured:',

/ sqlerr_ref->sql_message. "#EC NOTEXT

else.

perform get_trace_file using dev_file.

write:

/ 'DBI error', sqlerr_ref->internal_error, 'occured.',

/ 'See trace file for further info:',

icon_read_file as icon hotspot, dev_file. "#EC NOTEXT

endif.

return.

endtry.

  • connection successfully opened

write:

/ 'Connection', con_name, 'successfully opened.'. "#EC NOTEXT

*- Get the data from MS-SQL Server

EXEC SQL.

open C1 for

SELECT HR.T_DONATION.DN_DONATIONYEAR

FROM HR.T_DONATION

ENDEXEC.

do.

EXEC SQL.

FETCH NEXT C1 into :w1

ENDEXEC.

if sy-subrc = 0.

perform loop_output.

else.

exit.

endif.

enddo.

EXEC SQL.

CLOSE C1

ENDEXEC.

  • close connection again

con_ref->close( ).

write:

/ 'Connection', con_name, 'closed'. "#EC NOTEXT

************************************************************************

end-of-selection.

&----


*& Form LOOP_OUTPUT

&----


  • Output

----


form loop_output .

write: /5 w1.

endform. " LOOP_OUTPUT

Thanks for your help.

Jim

Message was edited by:

James Barnes

3 REPLIES 3
Read only

Former Member
0 Likes
653

Found answer.

Read only

0 Likes
653

I know I'm a few years too late, but for future reference, feel free to share what the solution was.

Read only

Former Member
0 Likes
653

Well my advice is to check the question in the sql tutorial, it will be quicker then getting an answere.