Application Development and Automation 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: 
Read only

count from an internal table

Former Member
0 Likes
782

Hi

In my internal table, I have multiple entries for different divisions.

I need the count of all the distinct divisions.

For example: I have

2 records for division 20,

2 records for division 30, and

2 records for division 40.

then in this case the count value should be 3.

Can anyone suggest any logic for this.

Points will be rewarded for correct answer.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
657

sort itab acccording to division.

count = 0.

loop at itab.

At new division

count = count +1.

endat.

endloop

regards

sort itab acccording to division.

count = 0.

loop at itab.

At new division

count = count +1.

endat.

endloop

regards

4 REPLIES 4
Read only

Former Member
0 Likes
658

sort itab acccording to division.

count = 0.

loop at itab.

At new division

count = count +1.

endat.

endloop

regards

Read only

Former Member
0 Likes
657

Hi

use the control break statements and achive this count

Sort the itab by DIVISION.

Use AT NEW and AT END OF events and use a counter variable and get it

see the sample code for this control events

All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

Some time you will get * when mopving data from this int table to other table using these commands

so you have to use

READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Regards

Anji

Read only

Former Member
0 Likes
657

Use

DEscribe table itab lines l.

<b>pls reward if helpful.</b>

Read only

Former Member
0 Likes
657

Hi,

U take a variable for divison. when increasing the counter u check the condition with variable if variable is equal to previous variable then don't increase the counter.

else increase the counter and every time in the loop u update divison value with latest divison value.

Rewardpoints if useful.

Regards

(YUGANDHAR.P)