现在的位置: 首页 > 综合 > 正文

ABAP 三种操作数据库的方法 OPEN SQL, EXEC SQL, ADBC

2013年10月08日 ⁄ 综合 ⁄ 共 639字 ⁄ 字号 评论关闭

OPEN SQL这里就不多说了,可以执行大部分DML语句,但是却不支持DDL,DCL,UNIT,也没办法执行数据内嵌的函数。

EXEC SQL 和 ADBC 是所谓的Native SQL,这种方式直接进入指定数据库,不涉及到DBI,这样就没有table buffer。

相对EXEC SQL来说,更推荐ADBC的方式执行native sql,这种方式的好处是更加容易追踪错误。

以下是实例,

data: lo_sql type ref to cl_sql_statement,

          lx_sql type ref to cx_sql_exception,

         lo_result type ref to cl_sql_result_set,

         lr_mara type ref to data,

         lt_mara type standard table of mara.

 

 ceate object lo_sql exporting con_ref = cl_sql_connection=>getconnection( 'ORA' ).

 lo_result = lo_sql->execute_query( |select * from MARA where mandt = {sy-mandt}|).

get reference of lt_mara into lr_mara.

lo_result->set_param_table( lr_mara ).

lo_result->next_package().

lo_result->close().

 

抱歉!评论已关闭.