‎2009 Feb 23 5:08 AM
hi Abapers,
Here is my code which seems to like below, in which i need to add amount fields.
TYPES: BEGIN OF TY_FINAL,
KDGRP LIKE KNVV-KDGRP,
KTEXT LIKE T151T-KTEXT,
KUNNR LIKE BSID-KUNNR,
NAME1 LIKE KNA1-NAME1,
ORT01 LIKE KNA1-ORT01,
TSO LIKE BSID-ZUONR,
VNAMC LIKE PA0002-VNAMC,
BELNR LIKE BSID-BELNR,
BLDAT LIKE BSID-BLDAT,
REFER LIKE BSID-VBELN,
DMBTR LIKE BSID-DMBTR,
ZTERM LIKE BSID-ZTERM,
VTEXT LIKE TVZBT-VTEXT,
BLART LIKE BSID-BLART,
DIFF1 LIKE BSID-DMBTR, " Amount field
DIFF2 LIKE BSID-DMBTR, " Amount field
DIFF3 LIKE BSID-DMBTR, " Amount field
DIFF4 LIKE BSID-DMBTR, " Amount field
DIFF5 LIKE BSID-DMBTR, " Amount field
DIFF6 LIKE BSID-DMBTR, " Amount field
DIFF7 LIKE BSID-DMBTR, " Amount field
TOTAL LIKE BSID-DMBTR, " Amount field ( diff1 + diff2 +... + diff7)
SCHEM TYPE CHAR15,
POSTD LIKE BSID-BUDAT,
BSTKD LIKE VBKD-BSTKD,
BSTDK LIKE VBKD-BSTDK,
ZCS1 TYPE CHAR40,
ZCS2 TYPE CHAR40,
ZCS3 TYPE CHAR40,
ZCS4 TYPE CHAR40,
END OF TY_FINAL.
Data:
IT_FINTSO TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 0,
WA_FINTSO TYPE TY_FINAL.
I had all the data in IT_FINTSO ( FINAL INTERNAL TABLE ) based on customer number, i want to add the amounts based on customer number.
i think collect statement will not work because there are few fields which
please provide sample code .
Thanks & regards,
Hari priya
‎2009 Feb 23 5:11 AM
Hi:
use calculate or add the individual fields too
Regards
Shashi
‎2009 Feb 23 5:19 AM
Loop at itab.
itab-f4 = itab-f3 + itab-f2 + itab-f1 .
modify table itab with f4.
endloop.This is a pseudo code .
‎2009 Feb 23 5:22 AM
HI
move the customer number and fields that r to be added (ie.DIFF1 ,..DIFF7) to a separate internal table.
SORT table based on customer num.then LOOP that table.
Use COLLECT.
Then use READ stmt with Key as Customer Number and get the added amount.
‎2009 Feb 23 5:23 AM
Hi, Hari
Total Questions: 58 (35 unresolved)
First of all you have many open questions please close these.
Test the following Sample Code hope will solve out your problem, i am using collect and think that it will work for you too. in fact collect will add up you all amount fields with grouping all Char Fields. i think it is the best solution of your problem,
TYPES: BEGIN OF t_it ,
name1(2),
name2(2),
amount1 TYPE p DECIMALS 0,
amount2 TYPE p DECIMALS 0,
amount3 TYPE p DECIMALS 0,
amount4 TYPE p DECIMALS 0,
amount5 TYPE p DECIMALS 0,
END OF t_it.
DATA: it1 TYPE STANDARD TABLE OF t_it WITH HEADER LINE,
it2 TYPE STANDARD TABLE OF t_it WITH HEADER LINE.
it1-name1 = 'A1'.
it1-name2 = 'B1'.
DO 9 TIMES.
it1-amount1 = '100'.
it1-amount2 = '200'.
it1-amount3 = '300'.
it1-amount4 = '400'.
it1-amount5 = '500'.
APPEND it1 TO it1.
add 1 to : it1-name1+1(1),
it1-name2+1(1).
ENDDO.
it1-name1 = 'A1'.
it1-name2 = 'B1'.
DO 9 TIMES.
it1-amount1 = '100'.
it1-amount2 = '200'.
it1-amount3 = '300'.
it1-amount4 = '400'.
it1-amount5 = '500'.
APPEND it1 TO it1.
add 1 to : it1-name1+1(1),
it1-name2+1(1).
ENDDO.
LOOP AT it1 into it1.
it2 = it1.
COLLECT it2 into it2.
ENDLOOP.
Please Reply if else Requirements
Kind Regards,
Faisal.
‎2009 Feb 23 5:27 AM
hi,
u can do like this
1.if for each customer only sinlge record is there,perform this
loop at internal table.
for each record u add the amount fields and put into total field which is to be declared within the internal table so that the resuly will be against each record.
endloop.
2.if each cutomer multiple records are there,then use at end of statement and perform the above.
‎2009 Feb 23 5:27 AM
Hi,
Use this logic:
SORT IT_FINTSO BY KUNNR.
LOOP AT IT_FINTSO.
AT END OF KUNNR.
SUM.
IT_FINTSO-TOTAL = IT_FINTSO-DIFF1 + IT_FINTSO-DIFF2 + IT_FINTSO-DIFF3. " add ur itab-fields
MODIFY IT_FINTSO TRANSPORTING TOTAL.
CLEAR IT_FINTSO.
ENDAT.
ENDLOOP.thanks\
Mahesh
‎2009 Feb 23 5:41 AM
Hi. copy paste the code and hope u will have Kunnr(customer total) at end of every customer.
but i have made ur KUNNR the ist field.
And after selectin in it_fintso make it sort as
sort it_fintso by kunnr.
TYPES: BEGIN OF TY_FINAL,
KUNNR LIKE BSID-KUNNR,
KDGRP LIKE KNVV-KDGRP,
KTEXT LIKE T151T-KTEXT,
NAME1 LIKE KNA1-NAME1,
ORT01 LIKE KNA1-ORT01,
TSO LIKE BSID-ZUONR,
VNAMC LIKE PA0002-VNAMC,
BELNR LIKE BSID-BELNR,
BLDAT LIKE BSID-BLDAT,
REFER LIKE BSID-VBELN,
DMBTR LIKE BSID-DMBTR,
ZTERM LIKE BSID-ZTERM,
VTEXT LIKE TVZBT-VTEXT,
BLART LIKE BSID-BLART,
DIFF1 LIKE BSID-DMBTR, " Amount field
DIFF2 LIKE BSID-DMBTR, " Amount field
DIFF3 LIKE BSID-DMBTR, " Amount field
DIFF4 LIKE BSID-DMBTR, " Amount field
DIFF5 LIKE BSID-DMBTR, " Amount field
DIFF6 LIKE BSID-DMBTR, " Amount field
DIFF7 LIKE BSID-DMBTR, " Amount field
TOTAL LIKE BSID-DMBTR, " Amount field ( diff1 + diff2 +... + diff7)
SCHEM TYPE CHAR15,
POSTD LIKE BSID-BUDAT,
BSTKD LIKE VBKD-BSTKD,
BSTDK LIKE VBKD-BSTDK,
ZCS1 TYPE CHAR40,
ZCS2 TYPE CHAR40,
ZCS3 TYPE CHAR40,
ZCS4 TYPE CHAR40,
END OF TY_FINAL.
Data:
IT_FINTSO TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 0,
WA_FINTSO TYPE TY_FINAL.
data: it_fintso2 TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 0,
wa_it_fintso2 like wa_fintso.
data: ckunnr(1).
loop at it_fintso into wa_fintso.
wa_fintso2 = wa_fintso.
at new kunnr.
ckunnr = 'X'.
append wa_finsto to it_fintso2.
endat.
if ckunnr = 'X'.
clear ckunnr.
else.
wa_fintso-kunnr = ''.
endif.
append wa_fintso to it_fintso2.
at end of kunnr.
sum.
wa_fintso-name1 = 'Kunnr Total'.
append wa_fintso to it_fintso2.
endat.
endloop.
‎2009 Feb 23 5:47 AM
HI,
Please try using this with appropriate fields, I have not used the proper fields that u have used so please replace with the required fields,
LOOP AT it_fintso INTO wa_fintso.
AT NEW "CUSTOMER NUMBER".
sum.
WRITE:/128 sy-vline, wa_fintso-diff1.
ENDAT.
ENDLOOP.
use the Customer Number field in place of "CUSTOMER NUMBER",
the above code will give the total of field Diff1,
In the same way u can do it for the other total fields.
Pls try it out and let me know if it works.
Thanks
Suraj