一种获取SAP HANA数据库表条目数的另类方法
发布日期:2021-06-30 14:29:16
浏览次数:2
分类:技术文章
本文共 1988 字,大约阅读时间需要 6 分钟。
Still used the old way SELECT COUNT(*) to get total number of records stored in a table?
If you are using HANA database, there is another approach to achieve the same. In HANA there is a metadata table m_tables which stores the related information:You can find its definition in .
You can use the following ABAP code to access this HANA table from ABAP server:
class CL_CRM_HOME_TABLE_SIZE_TOOL definition public final create public .public section. TYPES: BEGIN OF ty_size, table_name TYPE char256, record_count TYPE int4, table_size TYPE int4, END OF ty_size.TYPES: tt_size TYPE TABLE OF ty_size with key table_name. class-methods GET_SIZE importing !IT_INPUT type STRING_TABLE returning value(RT_RESULT) type tt_size .protected section.private section.ENDCLASS.CLASS CL_CRM_HOME_TABLE_SIZE_TOOL IMPLEMENTATION. METHOD get_size. DATA(lv_in) = REDUCE string( INIT x TYPE string FOR IN it_input NEXT x = SWITCH #( x WHEN space THEN |'{ }'| ELSE x && ',' && |'{ }'| ) ). TRY. DATA(lo_sql_con) = cl_sql_connection=>get_connection( ). DATA(lo_stmt) = lo_sql_con->create_statement( ). DATA: lv_stmt TYPE string. lv_stmt = |select table_name, record_count, table_size from m_tables where table_name in ({ lv_in })|. DATA(lo_res) = lo_stmt->execute_query( lv_stmt ). GET REFERENCE OF rt_result INTO DATA(lr_data). lo_res->set_param_table( lr_data ). lo_res->next_package( ). lo_res->close( ). CATCH cx_sql_exception INTO DATA(cx_root). WRITE:/ 'Error:', cx_root->get_text( ). RETURN. ENDTRY. ENDMETHOD.ENDCLASS.
Consumer report:
REPORT zsize.DATA: lt_input TYPE String_table.lt_input = VALUE #( ( CONV string( 'TADIR' ) ) ( CONV string( 'TFDIR' ) ) ).DATA(lt_size) = cl_crm_home_table_size_tool=>get_size( lt_input ).cl_demo_output=>display_data( lt_size ).
Result:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
转载地址:https://jerry.blog.csdn.net/article/details/108293972 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年05月06日 02时55分41秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
小程序动态获取组件高度(自定义Tabbar的高度)
2019-05-01
如何是实现微信会员开卡组件中一个手机号绑定一个微信号(思路篇)
2019-05-01
小程序实现sku商品规格
2019-05-01
js对象的属性用变量值代替
2019-05-01
小程序图片转Base64,方法总结
2019-05-01
element中路由跳转以后激活当前菜单高亮
2019-05-01
VUE中同级页面传参的方式
2019-05-01
微信小程序setData复杂数组的更新、删除、添加、拼接
2019-05-01
has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check 报错
2019-05-01
微信小程序 分享的图片使用canvas生成
2019-05-01
JS算法之累加
2019-05-01
从四川电视台播放事故论AI智能审核的重要性
2019-05-01
List集合排序Comparable与Comparator实现
2019-05-01
你为什么要写这样的代码?你知不知道填这个坑有多难
2019-05-01
查看生产环境日记常用的几个linux命令
2019-05-01
spring+quartz.2.3.0数据库持久化实现
2019-05-01
Malformed \uxxxx encoding.异常
2021-07-04
使用aspose.words 18.6实现pdf文档转换
2021-07-04