‎2011 Oct 12 9:37 AM
Dear Experts,
I have the following fields in the internal Table,
Doc No, Section No, Tax code, Value ,Surcharge, TDS Amt.
1000, aaa, a1,CO 1000,100
2000,aaa,a1,nonco,2000,200
3000, aaa,a1,co,1000,100
4000,bbb,a1,nonco,1000,100
the required output should be
aaa,a1,co,2000,200
aaa,a1,nonco,2000,200
bbb,a1,nonco,1000,100
ie it should sum the values based on Value field for the particular section & taxcode, It should not
consider Doc No.
the code i have used is
sort section no Taxcode value
At end of value
SUM.
Endat.
But i cant get the required output, Please reply <removed by moderator>
Thanks in Advance
Edited by: Thomas Zloch on Oct 12, 2011 9:29 PM
‎2011 Oct 12 9:41 AM
For AT statements to work, all fields left from the field you are checking on with AT have to be similar. Additionally the internal table on which you want to use AT statements has to be sorted by your field you are doing your AT at.
So you either make yourself a structure where doc_no isnt in at all or if, then right to your field you want to check with AT.
you could however make this groupchange algorithm manually. it aint that hard.
‎2011 Oct 12 9:41 AM
For AT statements to work, all fields left from the field you are checking on with AT have to be similar. Additionally the internal table on which you want to use AT statements has to be sorted by your field you are doing your AT at.
So you either make yourself a structure where doc_no isnt in at all or if, then right to your field you want to check with AT.
you could however make this groupchange algorithm manually. it aint that hard.
‎2011 Oct 12 9:48 AM
thank for your prompt reply,
I had moved to another internal table without Doc Field, But still i am not able to get the correct output.
Can u please provide me the sample code for this?
‎2011 Oct 12 9:55 AM
well, section number and taxcode are still left from your field and have different values. so this wil mess up the AT statement.
And dont forget you need that table sorted by value.
‎2011 Oct 12 10:03 AM
But to be honest in such a simple case i´d rather avoid AT statements, since they will bring up oher problems as well, as long as you dont make use of a field-symbol as a workarea to loop to.
So i would code something like:
Therefor i take ITAB as declared internal table and WA as your declared workare to loop to, as given.
data: wa_check like line of itab,
lv_value type kbetr.
sort itab by value ascending.
read table itab
into wa_check
index 1.
loop at itab into we.
"do your summing here
if wa-value NE wa_check-value. "end of value reached
"trigger print of line here
wa_check = wa.
endif.
endloop.
‎2011 Oct 12 10:11 AM
Thank u Very Much...
I am getting the result as per the requirement by tour valuable suggestion. Problem is i ddnt maintain any sequence in Internal table
Will Assign U the points.
‎2011 Oct 12 10:40 AM
there is another simple method to do these kind of operations. That is to use collect statement. Here is what you should do.
declare types with ur fields as following.
types: begin of ty_sort,
doc type int2,
section type char3,
tax_code type char2,
value type char5,
surcharge type int2,
tds_amnt type int2,
end of ty_sort.now declare two internal tables with keys as follows:
data: lt_sort type standard table of ty_sort with non-unique key section tax_code value,
ls_sort type ty_sort,
gt_sort type standard table of ty_sort with non-unique key section tax_code value,
gs_sort type ty_sort.using gui_upload get your data into the internal table gt_sort. after the logic your output will be stored in lt_sort.
here is the logic
loop at gt_sort into gs_sort.
collect gs_sort into lt_sort.
endloop.thats all, after this logic you will have your result in lt_sort.