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: 

count number of rows

Former Member
0 Kudos

how to count the number of rows in a loop satisfying a specific condition

like there are 5 rows of kunnr = '10001'

I dnt want to increment counter because Im doing an inner loop for that condition

In a sense I want to compare the numbe rof records in the inner loop and outer loop where kunnr = '10001'

1 ACCEPTED SOLUTION

former_member223537
Active Contributor
0 Kudos

Hi,

You can have a temporary table.

data : l_lines type i.
gt_temp[] = gt_data[].

delete gt_temp where kunnr ne '10001'.
describe gt_temp lines l_lines.

l_lines will have the necessary values.

Best regards,

Prashant

5 REPLIES 5

former_member223537
Active Contributor
0 Kudos

Hi,

You can have a temporary table.

data : l_lines type i.
gt_temp[] = gt_data[].

delete gt_temp where kunnr ne '10001'.
describe gt_temp lines l_lines.

l_lines will have the necessary values.

Best regards,

Prashant

former_member212653
Active Contributor
0 Kudos

you can move the data to a dummy table with only valid records and get the line count.


data : lines type i.
i_temp[] = i_data[].
"lines will have the no of rows of the temp table
delete gt_temp where kunnr ne '10001'.
lines = lines( i_temp ).

Former Member
0 Kudos

Paste some part of the code for better understanding..

Former Member
0 Kudos

Hi,

try this short example:

DATA: IVBAK TYPE TABLE OF VBAK WITH HEADER LINE.

DATA: BEGIN OF IKUNNR OCCURS 0,

KUNNR LIKE VBAK-KUNNR,

I TYPE I,

END OF IKUNNR.

*

SELECT * FROM VBAK INTO TABLE IVBAK.

*

LOOP AT IVBAK.

IKUNNR-KUNNR = IVBAK-KUNNR. IKUNNR-I = 1.

COLLECT IKUNNR.

ENDLOOP.

*

SORT IKUNNR.

*

LOOP AT IKUNNR. WRITE: / IKUNNR-KUNNR, IKUNNR-I. ENDLOOP.

Regards, Dieter

Former Member
0 Kudos

Hi sia anjali,

Declare a Temporary table(say itab1) and Try as following;

REFRESH itab1.
itab1[] = itab[].
DELETE itab1 WHERE kunnr = '1001'.
DESCRIBE TABLE itab1.

After Describe statement System field SY-TFILL contain the number of lines in the table itab1. Use that.

Regards

Karthik D