2012 Jan 08 8:19 AM
Hello Gurus,
I have an internal table itab1:
col1 | col2 | col3 |
A | X | 123 |
A | | 456 |
A | X | 999 |
B | | 456 |
B | X | 999 |
C | X | 123 |
C | X | 456 |
C | X | 999 |
Now, I need to calculate values for A, B, C, or it could be anything...with respect to col2....
That is, currently,
for A with X, COUNT is 2 and
total COUNT for A is 3
for B with X, COUNT is 1 and
total COUNT for B is 2
for C with X, COUNT is 3 and
total COUNT for C is also 3
Now, since it is dynamic, I can not use describe, or loop using where clause as rows selection depends upon DB table..
Is it possible to use field symbol to capture these values dynamically...or
use AT END clause with FS...?
I dont know how to calculate the number of rows for a specific condition between at end and endat..
Kindly help in deciding the optimized approach....
Thanks in advance..
BR
Malhar
2012 Jan 08 8:40 AM
Hi
You can sort on field1 and field2. You will have to use two end of statements at end of field1 will give total count for and at end of end of field2 will give count for unique combo of field1 and field2
Nabheet
2012 Jan 08 9:11 AM
Ok..
sort itab by col1 col2.
loop at itab1.
at end of col1.
what statement will give me the actual count??
As I understand for summation, we just use SUM.
But, here for the actual count what to be used...?
endat.
at end of col2.
endat.
endloop.
BR
Malhar
2012 Jan 08 9:17 AM
Or is it possible to achieve the same without using the at end of - endat (control break) stmnt and by using the Field Symbols..?
Please advixe me the same!!!
Thanks again..
2012 Jan 08 10:20 AM
Keep local cariables one for total and one for x and count..on end of pass them...
Nabheet
2012 Jan 08 12:21 PM
create another 2 tables itab2, and itab3 with below fields.
col1|col2|col3==> make this of type char10|col4==>i have added col4 of type i.
loop at itab1 into is1.
move corresponding is1 to is2.
clear is2-col3."==>we dont need this for count
is2-col4 = 1.
if is2-col2 = 'X'.
collect is2 into ITAB2."==>for count with X
endif.
clear is2-col2.
collect is2 into ITAB3. "===>for total count
clear is2.
endloop.
output will be below
ITAB2
col1 | col2 | col3 | col4|
A | X | | 2 |
B | X | | 1 |
C | X | | 3 |
ITAB3
col1 | col2 | col3 | col4|
A | | | 3 |
B | | | 2 |
C | | | 3 |