共计 1605 个字符,预计需要花费 5 分钟才能阅读完成。
*&---------------------------------------------------------------------*
*& Report ztest_adbc_demo
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_adbc_demo.
TYPES:
*”设定内表和工作区构造体的类型
BEGIN OF ty_airline,
airline_id TYPE scarr-carrid,
airline_name TYPE scarr-carrname,
airline_currency TYPE scarr-currcode,
url TYPE scarr-url,
url2 TYPE string,
END OF ty_airline.
*”设定承载 SQL 语句的变量,返回后果变量、条件变量
DATA:
lv_statement TYPE string,
lt_airline TYPE TABLE OF ty_airline,
lr_result TYPE REF TO data,
lv_currency TYPE scarr-currcode,
**”设定 ADBC 相干类的连贯对象、SQL 对象、后果对象、异样对象的变量
lo_conn TYPE REF TO cl_sql_connection,
lo_statement TYPE REF TO cl_sql_statement,
lo_result_set TYPE REF TO cl_sql_result_set,
lx_sql TYPE REF TO cx_sql_exception.
*”关联内表到后果对象变量中
GET REFERENCE OF lt_airline INTO lr_result.
*”设定条件变量的值
lv_currency = 'EUR'.
*”拼接 HANA Native SQL, 该语法是 HANA 的 SQL Script 所反对的语法
*”也能够调用 SQL Script 的函数如 SUBSTRING
lv_statement = | SELECT CARRID, CARRNAME, CURRCODE, URL, |
&& | SUBSTRING (URL,8,LENGTH(URL)) AS URL2 |
&& | FROM scarr WHERE currcode = '{lv_currency}' and |
&& | CARRID <> 'CA' | .
TRY.
** n 调用 SQL-Connection 办法,连贯到数据库
lo_conn = cl_sql_connection=>get_connection( ).
** n 調用 SQL-Statement 办法,创立 SQL 对毎
lo_statement = lo_conn->create_statement( ).
*" 調用 SQL-query 方还,执行 SQL 语句
lo_result_set = lo_statement->execute_query(lv_statement).
" 调用 SQL-set_param_table 办法,指定用哪个内表来记录返回后果
lo_result_set->set_param_table(lr_result).
* 往取数据集的下一组薮龍到内表
lo_result_set->next_package( ).
*”褥到后果后,敞开数据棄
lo_result_set->close( ).
*”打印内表
cl_demo_output=>display_data(lt_airline).
*”错误处理,如 SQL 有误,则在此处报出 log, 而不会导致系统解体 (short dump)
CATCH cx_sql_exception INTO lx_sql.
WRITE: lx_sql->get_text( ).
ENDTRY.
正文完