‎2007 Apr 12 10:06 AM
Hi Guys,
i have an internal table like this:-
company_code Region Salesoffice salesorder amount
xx1 E CAL 001 100.00
xx1 E CAL 002 70.00
xx1 E SIL 003 50.00
xx1 W MUM 004 700.00
xx1 E ASL 005 100.00
xx2 E CAL 006 200.00
xx2 S CHE 007 100.00
xx3 W MUM 008 400.00
xx3 E SIL 009 70.00
xx3 S CHE 010 300.00
I have generate a report like this
Company code : xx1
Region : E
Salesoffice Sales Order Amount
CAL 001 100.00
CAL 002 70.00
SIL 003 50.00
ASL 005 100.00
-
Net : 320.00
Region : W
Salesoffice Salesorder Amount
MUM 004 700.00
-
Net : 700.00
-
Company Code : Net amont
xx1 1020.00
I have successfully written a program using AT NEW,ON CHANGE,AT END ,
I want to write the same program using LOOP AT and READ TABLE . Plz
anyone help me to solve this and send me the exact code .
‎2007 Apr 12 10:10 AM
‎2007 Apr 12 10:13 AM
check this code and get back if it doesn't work
sort itab. by ccode region soff sorder amount.
loop at itab
wa_table = itab.
at new ccode.
write:/'Company Code',wa_table-ccode.
endat.
at new region.
write:/'Region',wa_table-region.
endat.
write:/itab-soff, itab-sorder, itab-amont.
at end of region.
sum.
write:/itab-amount.
endat.
endloop.
‎2007 Apr 12 10:20 AM
Hi Rajesh,
please read the question carefully before answering it. I have already done this but now i want to do the same thisng using read table statement.
‎2007 Apr 12 10:24 AM
hi Friend,
Please try the following logic:
data: wa_temp type type_itab,
wa_itab type type_itab,
itab type table of type_itab,
lv_flag ,
lv_region_amount type ...,
lv_ccode_amount type.....
loop at itab into wa_itab.
if wa_temp is initial.
write:/ 'Company Code' , wa_itab-company_code.
write:/ 'Region' , wa_itab-region.
write:/ 'Sales office' , 'Sales Order' , 'Amount'.
write:/ wa_itab-sales_office, wa_itab-sales_order, wa_itab-amount.
lv_region_amount = lv_region_amount + wa_itab-amount.
lv_ccode_amount = lv_ccode_amount + wa_itab-amount.
lv_flag = 'X'.
endif.
if lv_flag is initial.
if wa_itab-company_code <> wa_temp-company_code.
write:/ 'Company code Net', lv_ccode_amount.
clear lv_ccode_amount.
clear lv_region_amount.
write:/ 'Company Code' , wa_itab-company_code.
write:/ 'Region' , wa_itab-region.
write:/ 'Sales office' , 'Sales Order' , 'Amount'.
write:/ wa_itab-sales_office, wa_itab-sales_order, wa_itab-amount.
lv_region_amount = lv_region_amount + wa_itab-amount.
lv_ccode_amount = lv_ccode_amount + wa_itab-amount.
else.
if wa_itab-region <> wa_temp-region.
write:/ 'Region Net', lv_region_amount.
clear lv_region_amount.
write:/ 'Region' , wa_itab-region.
write:/ 'Sales office' , 'Sales Order' , 'Amount'.
write:/ wa_itab-sales_office, wa_itab-sales_order, wa_itab-amount.
lv_region_amount = lv_region_amount + wa_itab-amount.
lv_ccode_amount = lv_ccode_amount + wa_itab-amount.
endif
write:/ wa_itab-sales_office, wa_itab-sales_order, wa_itab-amount.
lv_region_amount = lv_region_amount + wa_itab-amount.
lv_ccode_amount = lv_ccode_amount + wa_itab-amount.
endif.
endif.
wa_temp = wa_itab.
clear lv_flag.
endloop.
write:/ 'Company code Net', lv_ccode_amount.
.
Hope this helps,
Sajan Joseph.
Message was edited by:
Sajan Joseph