2008 Apr 02 10:41 AM
Hi,
This is very urgent, i need to compare two records of an internal table and then add one counter to it.
like
Filed1 Field2
A 100
A 200
B 300
C 400
Now i have to set a counter for field1 and for A the value of the counter would be 2. For B and C it would be 1. Can you suggest how to do that? It is really urgent.
2008 Apr 02 10:50 AM
Internal table itab has following data:
Field1 Field2
A 100
A 200
B 300
C 400
data: counter type i.
sort itab by field1 field2.
loop at itab.
at new field1.
clear counter.
endat
counter = counter + 1.
at end of field1.
move itab-field1 to itab1-field1.
move counter to itab1-counter.
append itab1.
endat.
endloop.
itab1 will now contain
A 2
B 1
C 1
Reward if useful.
Hi,
This is very urgent, i need to compare two records of an internal table and then add one counter to it.
like
Filed1 Field2
A 100
A 200
B 300
C 400
Now i have to set a counter for field1 and for A the value of the counter would be 2. For B and C it would be 1. Can you suggest how to do that? It is really urgent.
2008 Apr 02 10:48 AM
loop at internal table.
if field1 = 'A'.
add 1 to counter_a.
elseif field1 = 'B'.
add to counter_b.
elseif field1 = 'C'.
add 1 to counter_c.
endloop.
2008 Apr 02 10:50 AM
Hi,
There is not only 3 values , there is a around 1000 values, i cant hardcode all of them, i need to compare between the two adjacent rows, i need a logic for that.
2008 Apr 02 10:57 AM
With the DELETE ADJACENT DUPLICATES FROM itab comparing A or B. you will have all distinct value.
I suggest that you keep your internal table as counter where you will put the value counter next of the original value.
2008 Apr 02 10:50 AM
Internal table itab has following data:
Field1 Field2
A 100
A 200
B 300
C 400
data: counter type i.
sort itab by field1 field2.
loop at itab.
at new field1.
clear counter.
endat
counter = counter + 1.
at end of field1.
move itab-field1 to itab1-field1.
move counter to itab1-counter.
append itab1.
endat.
endloop.
itab1 will now contain
A 2
B 1
C 1
Reward if useful.
2008 Apr 02 10:52 AM
hi,
You must already have a counter by different value that you have in the table or you know what king of value you will have?
you can sort you table by A and use the event AT :
AT - itab
Syntax
LOOP AT itab result ...
[AT FIRST.
...
ENDAT.]
[AT NEW comp1.
...
ENDAT.
[AT NEW comp2.
...
ENDAT.
[...]]]
[ ... ]
[[[...]
AT END OF comp2.
...
ENDAT.]
AT END OF comp1.
...
ENDAT.]
[AT LAST.
...
ENDAT.]
ENDLOOP.
and then do the same thing with sorting by B.
Regards
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |