11-14-2006 5:36 PM
hi all..
I am having an internal table with 10 columns that is 10 fields. Now one of them is profit centre which is same for many records. Now i want to get all the records for individual profit centre. I know i can do it by using loop and the writing all records to a different internal table for each profit center. Can anyone else suggest me another method??
thanks in advance,
Reena
11-14-2006 5:41 PM
11-14-2006 5:41 PM
11-15-2006 8:56 AM
i will elaborate my question. for example I have an internal table itab. Now 6 records of them have prctr = AA, 3 of them have prctr = BB and 1 of them have prctr = CC.
Now i want all of these records for a particular PRCTR in a different internal table.
i guess this will make things bit clear..
thanks for your support,
Reena
11-15-2006 9:04 AM
Reena...
sort itab by prctr.
v_index = 0.
loop at prctr.
at new prctr.
get new itab1
v_index = v_index + 1.
endat.
if v_index = 1.
get values into itab1
elseif v_index = 2.
get values into itab2
elseif v_index = 3.
get values into itab3
endif.
at end of prctr.
if v_index = 1.
append itab1
elseif v_index = 2.
append itab2
elseif v_index = 3.
append itab3
endif.
endat.
endloop.
-Anu
11-15-2006 9:09 AM
hello ,
try to use like this
Perform read_profit_center using prft_cntr.
Form read_profit_center using value(p_cntr).
read table itab with key pfr_cntr = p_cntr.
if sy-subrc eq 0.
Move the data here
delete itab index sy-tabix
*call the form again.
Perform read_profit_center using p_cntr.
Else.
continue.
Endform.
Hope this will help you.
Thanks,
Krishnakumar
Message was edited by:
Krishnakumar Ramadoss
11-15-2006 9:15 AM
Hi,
Check this
loop at itab.
if itab-prctr eq 'AA'.
move the fields of itab to itab1.
elseif itab-prctr eq 'BB'.
move the fields of itab to itab2.
elseif itab-prctr eq 'CC'
move the fields of itab to itab3.
endloop.
11-14-2006 5:49 PM
you could:
sort my_table profit_center.
read table my_table with key
prt_cnt = "100013" "example
if sy-subrc eq 0.
collect my_table.
endif.
Warren
11-15-2006 9:27 AM
hi Reena ,
data : begin of itab occurs 0,
PRCTR(18),
val(6) ,
end of itab .
DATA : JTAB LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: V_FLAG TYPE C.
itab-PRCTR = 'AA'.
ITAB-VAL = '01'.
APPEND ITAB.
itab-prctr = 'AA'.
ITAB-VAL = '02'.
APPEND ITAB.
itab-PRCTR = 'AA'.
ITAB-VAL = '03'.
APPEND ITAB.
itab-prctr = 'AA'.
ITAB-VAL = '04'.
APPEND ITAB.
itab-PRCTR = 'AA'.
ITAB-VAL = '05'.
APPEND ITAB.
itab-prctr = 'AA'.
ITAB-VAL = '06'.
APPEND ITAB.
itab-PRCTR = 'BB'.
ITAB-VAL = '01'.
APPEND ITAB.
itab-prctr = 'BB'.
ITAB-VAL = '02'.
APPEND ITAB.
itab-PRCTR = 'BB'.
ITAB-VAL = '03'.
APPEND ITAB.
itab-PRCTR = 'CC'.
ITAB-VAL = '02'.
APPEND ITAB.
LOOP AT ITAB .
AT NEW PRCTR.
V_FLAG = 'X'.
ENDAT.
IF V_FLAG = 'X'.
JTAB-PRCTR = ITAB-PRCTR.
JTAB-VAL = ITAB-VAL.
APPEND JTAB.
CLEAR JTAB.
ENDIF.
AT END OF PRCTR.
CLEAR V_FLAG.
CLEAR JTAB.
LOOP AT JTAB.
WRITE:/ JTAB-PRCTR,JTAB-VAL.
ENDLOOP.
skip 2.
WRITE:/ '--------------'.
REFRESH JTAB.
ENDAT.
ENDLOOP.
Now in here as per ur requirement
i need to dynamically generate a internal table for the number of profit centers ..
but if i Populate the JTAB / Profit center
u can check the line '----
' being printed at the end of occurance of each profit center .
hope this helps ,
regards,
Vijay