2007 Sep 28 8:45 AM
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
2007 Sep 28 8:47 AM
sort itab acccording to division.
count = 0.
loop at itab.
At new division
count = count +1.
endat.
endloop
regards
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
2007 Sep 28 8:47 AM
sort itab acccording to division.
count = 0.
loop at itab.
At new division
count = count +1.
endat.
endloop
regards
2007 Sep 28 8:48 AM
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
2007 Sep 28 8:48 AM
2007 Sep 28 8:51 AM
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)
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |