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