‎2007 Apr 12 7:40 PM
Hi,
I have an internal table as follows..
loc1 matnr charg good
loc1 matnr charg good
loc1 matnr charg good
loc1 matnr charg ok
loc1 matnr charg bad
loc2 matnr charg good
loc2 matnr charg good
loc2 matnr charg ok
loc2 matnr charg bad
Now i want to get a count of how many goods,bad and ok are there in another table..
For ex my result should be as follows..
Loc good ok bad
-
loc1 3 1 1
loc2 2 1 1
Thanks for any ideas..
‎2007 Apr 12 7:56 PM
Hi,
Please try this.
DATA: BEGIN OF ITAB2 OCCURS 0,
LOC(4),
T_GOOD TYPE I,
T_OK TYPE I,
T_BAD TYPE I.
DATA: END OF ITAB2.
SORT ITAB1 BY LOC.
LOOP AT ITAB1.
CLEAR ITAB2.
ITAB2-LOC = ITAB1-LOC.
CASE ITAB1-COND.
WHEN 'GOOD'.
ITAB2-T_GOOD = '1'.
WHEN 'OK'.
ITAB2-T_OK = '1'.
WHEN 'BAD'.
ITAB2-T_BAD = '1'.
ENDCASE.
COLLECT ITAB2.
ENDLOOP.
LOOP AT ITAB2.
WRITE: / ITAB2-LOC, ITAB2-T_GOOD, ITAB2-T_OK, ITAB2-T_BAD.
ENDLOOP.
Regards,
Ferry Lianto
‎2007 Apr 12 7:49 PM
hi aries,
in the loop of the internal table u can keep a counter like when that value of the variable is good, increase the counter to 1. Likewise u can proceed.
Regards...
Arun
‎2007 Apr 12 7:56 PM
Hi,
Please try this.
DATA: BEGIN OF ITAB2 OCCURS 0,
LOC(4),
T_GOOD TYPE I,
T_OK TYPE I,
T_BAD TYPE I.
DATA: END OF ITAB2.
SORT ITAB1 BY LOC.
LOOP AT ITAB1.
CLEAR ITAB2.
ITAB2-LOC = ITAB1-LOC.
CASE ITAB1-COND.
WHEN 'GOOD'.
ITAB2-T_GOOD = '1'.
WHEN 'OK'.
ITAB2-T_OK = '1'.
WHEN 'BAD'.
ITAB2-T_BAD = '1'.
ENDCASE.
COLLECT ITAB2.
ENDLOOP.
LOOP AT ITAB2.
WRITE: / ITAB2-LOC, ITAB2-T_GOOD, ITAB2-T_OK, ITAB2-T_BAD.
ENDLOOP.
Regards,
Ferry Lianto
‎2007 Apr 12 8:15 PM
‎2007 Apr 12 7:56 PM
Hi,
Use at new control break statement and put one variable like count = 0, then
increase this count to 1 after end of control statement.
loop at itab.
at new matnr
write count.
endat.
count = count +1.
endloop.
Regards,
Bhaskar
‎2007 Apr 12 8:30 PM
I have just modified Ferry's code and added a line CLEAR ITAB2 .
DATA: BEGIN OF ITAB2 OCCURS 0,
LOC(4),
T_GOOD TYPE I,
T_OK TYPE I,
T_BAD TYPE I,
END OF ITAB2.
SORT ITAB1 BY LOC.
LOOP AT ITAB1.
ITAB2-LOC = ITAB1-LOC.
CASE ITAB1-COND.
WHEN 'GOOD'.
ITAB2-T_GOOD = '1'.
WHEN 'OK'.
ITAB2-T_OK = '1'.
WHEN 'BAD'.
ITAB2-T_BAD = '1'.
ENDCASE.
COLLECT ITAB2.
CLEAR ITAB2. * ELSE ALL THE CONDITION TYPES SAY GOOD BAD AND OK WUD GET ADDED EACH TIME.
ENDLOOP.
LOOP AT ITAB2.
WRITE: / ITAB2-LOC, ITAB2-T_GOOD, ITAB2-T_OK, ITAB2-T_BAD.
ENDLOOP.