on 2024 May 15 2:24 PM
I have a requirement to update an external database via ODBC and found that I can native SQL for this.
I also found that I can try out native sql without connection to an external database. If I just use "EXEC SQL" without making a connection, the commands will run on the default connection - that is the SAP database.
Finally I found simple tutorial examples, but I can make none of the examples work.
If I for example run this below code I get this error:
DATA: BEGIN OF wa,
matnr TYPE matnr,
END OF wa.
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
PARAMETERS: p_matnr TYPE matnr.
TRY.
EXEC SQL.
open dbcur for
select matnr
from mara
where mandt = :sy-mandt
and matnr = :p_matnr
ENDEXEC.
DO.
exec sql.
FETCH NEXT dbcur into wa-matnr
ENDEXEC.
IF sy-subrc NE 0.
EXIT.
ELSE.
WRITE: / wa-matnr.
ENDIF.
ENDDO.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
Request clarification before answering.
So I found solution my self. If I write everything between EXEC SQL. and ENDSQL. in capital letters, then it works.
For example:
TRY.
EXEC SQL PERFORMING LOOP_OUTPUT.
SELECT MATNR
INTO :WA-MATNR
FROM MARA
WHERE MATNR = :P_MATNR
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sandre
I'm using SAP ERP - SAP_BASIS 7.50.
I did make the test samples works by writing all the native SQL in capital letters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.