In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article to share with you is about the ABAP to obtain a database table records in the two methods are what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.
Method 1: Use EM_GET_NUMBER_OF_ENTRIES
This function is very simple to use, just need to query the database table name maintained in the input parameter IT_TABLES:
The above figure shows that this function supports batch operations. The two tables I queried were named TADIR and PROGDIR.
Execute the function to get the number of entries in the table:
Method 2: Using ADBC
There is nothing magical about the implementation of method 1, which is to use Open SQL SELECT COUNT(*) to get the number of data in a table.
If we are using SAP HANA as the ABAP Netweaver underlying database, there is a metadata table M_TABLES that holds metadata for all tables.
Here's an example:
The following SQL statement can easily obtain the number of entries in the tables COMM_PRODUCT and TADIR:
SELECT * FROM M_TABLES WHERE TABLE_NAME IN ('COMM_PRODUCT', 'TADIR')
Details of the M_TABLES table can be found in SAP Help: https://help.sap.com/doc/4fe29514fd584807ac9f2a04f6754767/2.0.01/en-US/20c7689a75191014ad52c1beb40ce2d2.html
I wrote a simple ABAP tool that encapsulates operations on table M_TABLES:
class CL_CRM_HOME_TABLE_SIZE_TOOL definitionpublicfinalcreate 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_SIZEimporting! IT_INPUT type STRING_TABLEreturningvalue(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 #( xWHEN 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.
Consumption of the above classes:
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 ).
Executing the above report displays the following results:
The above is what are the two methods of obtaining a database table record number in ABAP. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.