09-11-2008 2:54 PM
Hi All,
I have an internal table as follows.
PRCTR PERNR
1 101
1 102
1 103
2 104
3 105
3 106
Now i would like to calculate the total number of employees (PERNR) against each Profit Center (PRCTR) into one more table as follows....
PRCTR PERNR
1 3
2 1
3 2
How to incorporate code to meet this logic?
Kindly help me out....
Regards
Pavan
Edited by: Pavan Sanganal on Sep 11, 2008 7:26 PM
09-11-2008 2:57 PM
TYPES: BEGIN OF ty_totals,
PRCTR TYPE PRCTR,
number TYPE i,
END OF ty_totals.
DATA: itab2 TYPE STANDARD TABLE OF ty_totals,
wa2 TYPE ty_totals.
LOOP AT itab1 INTO wa1.
wa2-PRCTR = wa1-PRCTR.
wa2-number = 1.
COLLECT wa2 INTO itab2.
ENDLOOP.
Regards,
Valter Oliveira.
09-11-2008 2:57 PM
TYPES: BEGIN OF ty_totals,
PRCTR TYPE PRCTR,
number TYPE i,
END OF ty_totals.
DATA: itab2 TYPE STANDARD TABLE OF ty_totals,
wa2 TYPE ty_totals.
LOOP AT itab1 INTO wa1.
wa2-PRCTR = wa1-PRCTR.
wa2-number = 1.
COLLECT wa2 INTO itab2.
ENDLOOP.
Regards,
Valter Oliveira.
09-11-2008 2:59 PM
You can make used of control break statements : AT NEW, AT LAST
Example
LOOP AT ITAB INTO WA.
AT NEW PRCTR
CLEAR LV_COUNT.
LV_COUNT = LV_cOUNT + 1.
AT LAST PRCTR.
WRITE WA-PRCTR, LV_COUNT.
ENDLOOP.
You can also make use of COLLECT statement. See keyword documentation for more details
09-11-2008 3:04 PM
Hi Pavan,
This code will handle that.
data: i_st type i,
no_ees type i.
Loop at it.
at new prctr.
i_st = sy-tabix.
endat.
at end of prctr.
no_ees = sy-tabix - i_st + 1.
write: / it-prctr, no_ees.
endat.
endloop.
Regards
Marcin
09-11-2008 3:06 PM
Hi
DATA :
BEGIN OF fs_temp,
a TYPE i,
b TYPE i,
END OF fs_temp.
DATA :
t_temp LIKE
STANDARD TABLE OF
fs_temp.
DATA :
w_temp TYPE i.
DEFINE populate.
fs_temp-a = &1.
fs_temp-b = &2.
append fs_temp to t_temp.
END-OF-DEFINITION.
populate 1 101.
populate 1 102.
populate 1 103.
populate 2 201.
populate 2 202.
LOOP AT t_temp INTO fs_temp.
AT NEW a.
WRITE :
/ fs_temp-a.
CLEAR w_temp.
ENDAT.
AT NEW b.
ADD 1 TO w_temp.
ENDAT.
AT END OF a.
WRITE :
/ w_temp.
ENDAT.
ENDLOOP.
Regards
Pavan
09-11-2008 3:15 PM
Hi Pavan,
Try it like this:
loop at itab into wa.
count = count + 1.
at end of PRCTR .
write count. "total number of employees against wa-PRCTR
clear count.
endat.
endloop.
With luck,
Pritam.