Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to count SAP table entries

Former Member
0 Kudos

Hi , I have to count the number of entries in the mara table which have the material number '10006877' . I do not want to select it to an internal table and count it .

Is there a direct count statement that can be added to the usual select to get this.

A code will be useful

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

Hi,

You can use SELECT COUNT statement.


TABLES MARA.
DATA   COUNT TYPE I.

SELECT COUNT( * )
INTO COUNT 
FROM MARA
WHERE <condition>.

WRITE: / COUNT.

Regards,

Ferry Lianto

6 REPLIES 6

ferry_lianto
Active Contributor
0 Kudos

Hi,

You can use SELECT COUNT statement.


TABLES MARA.
DATA   COUNT TYPE I.

SELECT COUNT( * )
INTO COUNT 
FROM MARA
WHERE <condition>.

WRITE: / COUNT.

Regards,

Ferry Lianto

Former Member
0 Kudos

Material number is the primary key in MARA. so there will always be only one record with the material 10006877

0 Kudos

once you select the data from MARA Table then use SY-DBCNT System variable,it will show number of entries

Thanks

Seshu

Former Member
0 Kudos
SELECT COUNT ( * ) INTO w_COUNT FROM MARA.

will give you the number of entries in mara table.

Cheers

VJ

Former Member
0 Kudos

<Response deleted>

Message was edited by:

Sudhi Karkada

Former Member
0 Kudos

Since MATNR is the key, there will be 0 or 1 entry with that value. It will be quick to:


SELECT SINGLE matnr FROM MARA
  WHERE matnr = '10006877'.
IF sy-subrc = 0.
* One record
ELSE.
* No records
ENDIF.

You may have to run the material number through a conversion exit before doing the SELECT.

Rob