ABAP--原生SQL接口API(ADBC)的使用
2018-01-10 16:12
363 查看
ABAP--原生SQL接口API(ADBC)的使用
sap为大家提供原生SQL(Native SQL)接口API,该接口主要由四个类组成:
CL_SQL_STATEMENT - Execution of SQL Statements
CL_SQL_PREPARED_STATEMENT - Prepared SQL Statements
CL_SQL_CONNECTION - Administration of Database Connections
CX_SQL_EXCEPTION - Exception Class
原生SQL接口API可以在ABAP里执行动态的原生SQL操作,解决用户一些非常特殊的操作需求。
样例一:数据定义语言DDL(Create,Drop,Grant,Revoke) 和数据操纵语言DML(Update,Insert,Delete)操作
REPORT demo_adbc_ddl_dml.
PARAMETERS p_name TYPE c LENGTH 10 DEFAULT 'mytab'.
SELECTION-SCREEN SKIP.
PARAMETERS: p_create RADIOBUTTON GROUP grp,
p_insert RADIOBUTTON GROUP grp,
p_select RADIOBUTTON GROUP grp,
p_drop RADIOBUTTON GROUP grp.
SELECTION-SCREEN SKIP.
PARAMETERS p_key TYPE i DEFAULT 1.
CLASS adbc DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-DATA: dbname TYPE string,
sql TYPE REF TO cl_sql_statement,
wa1 TYPE c LENGTH 10,
wa2 TYPE c LENGTH 10,
err TYPE REF TO cx_sql_exception .
CLASS-METHODS: create RAISING cx_sql_exception,
insert RAISING cx_sql_exception,
select RAISING cx_sql_exception,
drop RAISING cx_sql_exception.
ENDCLASS.
CLASS adbc IMPLEMENTATION.
METHOD main.
dbname = 'ABAP_DOCU_DEMO_' && p_name.
TRY.
CREATE OBJECT sql.
IF p_create = 'X'.
create( ).
MESSAGE 'Create was successful' TYPE 'S'.
ELSEIF p_insert = 'X'.
insert( ).
MESSAGE 'Insert was successful' TYPE 'S'.
ELSEIF p_select = 'X'.
select( ).
MESSAGE 'Select was successful' TYPE 'S'.
ELSEIF p_drop = 'X'.
drop( ).
MESSAGE 'Drop was successful' TYPE 'S'.
ENDIF.
CATCH cx_sql_exception INTO err.
MESSAGE err TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
ENDMETHOD.
METHOD create.
sql->execute_ddl(
`CREATE TABLE ` && dbname &&
`( val1 char(10) NOT NULL,` &&
` val2 char(10) NOT NULL,` &&
` PRIMARY KEY (val1) )` ).
ENDMETHOD.
METHOD insert.
DO 100 TIMES.
wa1 = sy-index.
wa2 = sy-index ** 2.
sql->execute_update(
`INSERT INTO ` && dbname && ` ` &&
`VALUES ('` && wa1 && `','` && wa2 && `')` ).
ENDDO.
ENDMETHOD.
METHOD select.
DATA: result TYPE REF TO cl_sql_result_set,
msg TYPE c LENGTH 30,
key TYPE c LENGTH 10,
dref TYPE REF TO data,
rc
sap为大家提供原生SQL(Native SQL)接口API,该接口主要由四个类组成:
CL_SQL_STATEMENT - Execution of SQL Statements
CL_SQL_PREPARED_STATEMENT - Prepared SQL Statements
CL_SQL_CONNECTION - Administration of Database Connections
CX_SQL_EXCEPTION - Exception Class
原生SQL接口API可以在ABAP里执行动态的原生SQL操作,解决用户一些非常特殊的操作需求。
样例一:数据定义语言DDL(Create,Drop,Grant,Revoke) 和数据操纵语言DML(Update,Insert,Delete)操作
REPORT demo_adbc_ddl_dml.
PARAMETERS p_name TYPE c LENGTH 10 DEFAULT 'mytab'.
SELECTION-SCREEN SKIP.
PARAMETERS: p_create RADIOBUTTON GROUP grp,
p_insert RADIOBUTTON GROUP grp,
p_select RADIOBUTTON GROUP grp,
p_drop RADIOBUTTON GROUP grp.
SELECTION-SCREEN SKIP.
PARAMETERS p_key TYPE i DEFAULT 1.
CLASS adbc DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-DATA: dbname TYPE string,
sql TYPE REF TO cl_sql_statement,
wa1 TYPE c LENGTH 10,
wa2 TYPE c LENGTH 10,
err TYPE REF TO cx_sql_exception .
CLASS-METHODS: create RAISING cx_sql_exception,
insert RAISING cx_sql_exception,
select RAISING cx_sql_exception,
drop RAISING cx_sql_exception.
ENDCLASS.
CLASS adbc IMPLEMENTATION.
METHOD main.
dbname = 'ABAP_DOCU_DEMO_' && p_name.
TRY.
CREATE OBJECT sql.
IF p_create = 'X'.
create( ).
MESSAGE 'Create was successful' TYPE 'S'.
ELSEIF p_insert = 'X'.
insert( ).
MESSAGE 'Insert was successful' TYPE 'S'.
ELSEIF p_select = 'X'.
select( ).
MESSAGE 'Select was successful' TYPE 'S'.
ELSEIF p_drop = 'X'.
drop( ).
MESSAGE 'Drop was successful' TYPE 'S'.
ENDIF.
CATCH cx_sql_exception INTO err.
MESSAGE err TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
ENDMETHOD.
METHOD create.
sql->execute_ddl(
`CREATE TABLE ` && dbname &&
`( val1 char(10) NOT NULL,` &&
` val2 char(10) NOT NULL,` &&
` PRIMARY KEY (val1) )` ).
ENDMETHOD.
METHOD insert.
DO 100 TIMES.
wa1 = sy-index.
wa2 = sy-index ** 2.
sql->execute_update(
`INSERT INTO ` && dbname && ` ` &&
`VALUES ('` && wa1 && `','` && wa2 && `')` ).
ENDDO.
ENDMETHOD.
METHOD select.
DATA: result TYPE REF TO cl_sql_result_set,
msg TYPE c LENGTH 30,
key TYPE c LENGTH 10,
dref TYPE REF TO data,
rc
相关文章推荐
- ABAP--原生SQL接口API(ADBC)的使用
- ABAP--原生SQL接口API(ADBC)的使用
- ABAP--原生SQL接口API(ADBC)的使用
- ABAP--原生SQL接口API(ADBC)的使用
- 使用ABAP(ADBC)和Java(JDBC)连接SAP HANA数据库
- 原生ajax和jquery ajax的使用
- Android使用原生组件WebView加载网页和数据的方法
- ABAP CHECKBOX 和LISTBOX使用指南
- 使用原生Js实现打印单组乘法表
- MongoDB学习笔记~使用原生语句实现三层集合关系的更新
- [置顶] Unity打包exe后去除原生窗口,使用自己的窗口控制UI,修改了网上的很多bug
- 深入浅出 React Native:使用 JavaScript 构建原生应用
- 在vue页面当中使用原生视频显示
- ABAP--如何在join查询中使用动态表名(其实这样是没有必要的)
- Web Dynpro ABAP---ALV控件的使用
- Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
- 转: windows 10使用原生linux bash命令行
- 关于polymer原生组件paper-input的部分属性的使用心得
- 组合框里添加复选框的方法(使用勾选的假象,用图片代替而已,并非QT原生支持)
- 使用原生js写的一个简单slider