cancel
Showing results for 
Search instead for 
Did you mean: 

RFC function module to count rows

Former Member
0 Kudos

Hello,

Does anybody know, if there is a function module which can count the rows of a table without returning the rows? the rows should be selectable by conditions (where-clause).

RFC_READ_TABLE returns the whole result table and may be slow for big tables.

thank you,

alex

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Alexander,

you can use the function module + rfc_get_table_entries+.

Hint:

The default value for the parameter + NUMBER_OF_ENTRIES+ that are to be returned is 0.

Unless you don't want to read parts of the table entries you should not change this value.

The number of table entries is returned with the parameter + NUMBER_OF_ENTRIES+.

Best regards,

André


FUNCTION rfc_get_table_entries.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(BYPASS_BUFFER) LIKE  SY-FTYPE DEFAULT SPACE
*"     VALUE(FROM_KEY) LIKE  SY-ENTRY DEFAULT SPACE
*"     VALUE(GEN_KEY) LIKE  SY-ENTRY DEFAULT SPACE
*"     VALUE(MAX_ENTRIES) LIKE  SY-TABIX DEFAULT 0
*"     VALUE(TABLE_NAME) LIKE  X030L-TABNAME
*"     VALUE(TO_KEY) LIKE  SY-ENTRY DEFAULT SPACE
*"  EXPORTING
*"     VALUE(NUMBER_OF_ENTRIES) LIKE  SY-INDEX
*"  TABLES
*"      ENTRIES STRUCTURE  TAB512
*"  EXCEPTIONS
*"      INTERNAL_ERROR
*"      TABLE_EMPTY
*"      TABLE_NOT_FOUND
*"----------------------------------------------------------------------

Former Member
0 Kudos

Hi Andre,

Thanks for your reply.

But the FM rfc_read_table_entries is returning the whole result, even if max_entries (I think you meant that) is 0.

Also the FM is not able to filter by non-key-fields.

Bye,

Alex

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Alex,

plese check <a href="http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_bc_dwb/~form/handler{5f4150503d3030323030363832353030303030303031393732265f4556454e543d444953504c4159265f4e4e554d3d313932333939}">SAP Note 192399 No authorization check in FG RFC1</a> and <a href="http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_bc_dwb/~form/handler{5f4150503d3030323030363832353030303030303031393732265f4556454e543d444953504c4159265f4e4e554d3d313039353333}">SAP Note 109533 Use of SAP function modules</a>.

The function module rfc_read_table_entries is not released for customers and it is not working correctly any more with current releases.

I assume you will have to write your own function module to achieve your task using

"Select count(*) From ... where ...".

Since you want to get the number of rows and use a select statement that contains non-key-fields please have in mind that this might cause a high load on your database server since such searches require a full table scan.

Best regards,

André

Former Member
0 Kudos

Hi Alex,

I searched but cudnt find a RFC enabled FM for the specifications, suggest that you make a custom RFC FM and call it from outside application. That way you may be able to reduce a lot of load and is very simple to code.

Former Member
0 Kudos

Hi,

Instead of using a FM, u can use 'DESCRIBE' statement to get the no of rows in any internal table.

For DB, "SELECT COUNT(*) from DB into lv" can be used.

Former Member
0 Kudos

Hi,

Yes, but I want to call a FM from an outside application.