2006 Jul 05 6:50 AM
A B
-
10 100
20 100
20 100
20 100
30 100
30 100
30 100
here i need to count for a = 10 how many records are there?
i.e., here for 10, 1 record
20, 3 records
30, 3 records
i want to display this things in alv output , so i need to reserve these values..
could you pls help me out..
A B
-
10 100
20 100
20 100
20 100
30 100
30 100
30 100
here i need to count for a = 10 how many records are there?
i.e., here for 10, 1 record
20, 3 records
30, 3 records
i want to display this things in alv output , so i need to reserve these values..
could you pls help me out..
2006 Jul 05 6:55 AM
Do this
Copy the internal table into ITAB2.
SORT ITAB2 BY A.
DELETE ADJACENT DUPLICATES FROM ITAB2 COMPARING A.
LOOP AT ITAB2.
LOOP AT ITAB1 WHERE A = ITAB2-A.
COUNT = COUNT + 1.
ENDLOOP.
Here update the count of the column wherever you want.
CLEAR COUNT.
ENDLOOP.
Regards,
Ravi
Note : Please mark all the helpful answers
2006 Jul 05 6:55 AM
Hi Ramakrishna,
Try with this code.
DATA:
BEGIN OF I_CNT_TAB OCCURS 0,
A TYPE A,
COUNT TYPE I,
END OF I_CNT_TAB.
DATA WA_CNT_TAB LIKE LINE OF I_CNT_TAB.
SORT ITAB BY A.
LOOP AT ITAB.
AT NEW A.
CLEAR V_COUNT.
ENDAT.
V_COUNT = V_COUNT + 1.
AT END OF A.
WA_CNT_TAB-A = ITAB-A.
WA_CNT_TAB-COUNT = V_COUNT.
APPEND WA_CNT_TAB TO I_CNT_TAB.
CLEAR WA_CNT_TAB.
ENDAT.
ENDLOOP.
Thanks,
Vinay
2006 Jul 05 7:00 AM
hi,
data C type i.
Sort Itab by A.
Loop at itab.
c = c + 1.
at end of A.
Write C .
clear C.
end at.
endloop.
2006 Jul 05 7:05 AM
Hi Ram,
SORT lit_output BY A.
LOOP AT lit_output INTO wa_output.
wa_op-A = wa_output-A.
wa_op-cnt = wa_op-cnt + 1.
AT END OF A.
APPEND wa_op TO lit_op.
clear wa_op-cnt.
ENDAT.
ENDLOOP.
Rgds,
Prakash
<b>Please Reward points if helpful</b>
2006 Jul 05 7:13 AM
hi,
chech the below code this may help you.
using this you can have count in another table for each item A....
data : begin of itab occurs 0,
a type i,
b type i,
end of itab.
data : begin of itab1 occurs 0,
a type i,
count type i,
end of itab1.
data : count type i.
itab-a = 10.
itab-b = 100.
append itab.
itab-a = 10.
itab-b = 100.
append itab.
itab-a = 20.
itab-b = 100.
append itab.
itab-a = 20.
itab-b = 100.
append itab.
itab-a = 20.
itab-b = 100.
append itab.
itab-a = 20.
itab-b = 100.
append itab.
itab-a = 30.
itab-b = 100.
append itab.
itab-a = 40.
itab-b = 100.
append itab.
itab-a = 40.
itab-b = 100.
append itab.
itab-a = 50.
itab-b = 100.
append itab.
clear count.
loop at itab.
count = count + 1.
at end of a.
itab1-a = itab-a.
itab1-count = count.
append itab1.
clear : count,
itab.
endat.
endloop.
uline.
write / ' contents of itab'.
uline.
loop at itab.
write : / itab-a , itab-b.
endloop.
uline.
write / ' contents of itab1'.
uline.
loop at itab1.
write : / itab1-a , itab1-count.
endloop.
output:
contents of itab
10 100
10 100
20 100
20 100
20 100
20 100
30 100
40 100
40 100
50 100
contents of itab1
10 2
20 4
30 1
40 2
50 1
2006 Jul 05 7:33 AM
Hi,
Consider this code. Just copy and execute.
I have made use of <b>AT END OF...ENDAT</b> for counting.
REPORT abc.
TYPES : BEGIN OF str_test,
a(5),
b(5),
END OF str_test.
DATA : it_test TYPE STANDARD TABLE OF str_test WITH HEADER LINE,
cnt TYPE i.
it_test-a = 10.
it_test-b = 100.
APPEND it_test.
CLEAR it_test.
it_test-a = 10.
it_test-b = 100.
APPEND it_test.
CLEAR it_test.
it_test-a = 10.
it_test-b = 100.
APPEND it_test.
CLEAR it_test.
it_test-a = 20.
it_test-b = 100.
APPEND it_test.
CLEAR it_test.
it_test-a = 20.
it_test-b = 100.
APPEND it_test.
CLEAR it_test.
it_test-a = 30.
it_test-b = 100.
APPEND it_test.
CLEAR it_test.
SORT it_test BY a.
LOOP AT it_test.
cnt = cnt + 1.
AT END OF a.
WRITE : / 'Field A with value :',
it_test-a,
'No of entries:',
cnt.
CLEAR cnt. <b>"Dont forget to clear</b>
ENDAT.
ENDLOOP.
The ouput will be in this manner.
Field A with value : 10 No of entries: 3
Field A with value : 20 No of entries: 2
Field A with value : 30 No of entries: 1
Regards,
Arun Sambargi.
Message was edited by: Arun Sambargi
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |