cancel
Showing results for 
Search instead for 
Did you mean: 

Connection to Oracle DB from ABAP

Former Member
0 Kudos

Hello,

I am trying to connect to Oracle DB from ABAP by using the following

select single dbms from dbcon into dbtype
  where con_name = 'CON1'.

if sy-subrc = 0.

   TRY.
       IF sy-host EQ 'sapxxxxxx'.
         EXEC SQL.
          connect to      'CON1' as 'CON'
         ENDEXEC.
       ENDIF.

       IF sy-subrc <> 0.

         RAISE EXCEPTION TYPE cx_sy_native_sql_error.
       ENDIF.

       EXEC SQL.
         set connection 'CON'
       ENDEXEC.
      CATCH cx_sy_native_sql_error INTO exc_ref.

       LEAVE PROGRAM.
   ENDTRY.
endif.

This is resulting in SQL error ORA-00900.

invalid SQL statement.

I am not sure what is wrong as the connection in DBCON is working fine.

Any idea.

Can some one give me any hint.

thanks,

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member45419
Active Contributor
0 Kudos

Hi Hasnain,

Follow the command what ever deepak mention & for more clarification pls check this link

http://www.dba-oracle.com/sf_ora_00900_invalid_sql_statement.htm

Regards

Nayeem

former_member188883
Active Contributor
0 Kudos

Hi Hasnain,

Refer the sample below

First define connection to your Oracle database using transaction DBCO the you can use in your ABAP program something like this:

DATA: CONNECTION LIKE DBCON-CON_NAME VALUE 'TEST_DW'.

  EXEC SQL.

    CONNECT TO :CONNECTION

  ENDEXEC.

  IF SY-SUBRC = 0.

    EXEC SQL.

      SET CONNECTION :CONNECTION

    ENDEXEC.

        EXEC SQL.

         INSERT INTO ORA_TAB(FIELD1, FIELD2)

           VALUES (:VALUE1, :VALUE2)

        ENDEXEC.

    EXEC SQL.

      SET CONNECTION DEFAULT

    ENDEXEC.

    EXEC SQL.

      DISCONNECT :CONNECTION

    ENDEXE

  ENDIF.

where ORA_TAB s Oracle table name, FIELD1, FIELD2 are table fields, VALUE1, VALUE2 are ABAP variables...

Hope this helps.

Regards,

Deepak Kori