2008 Jun 24 3:33 PM
Hi All,
I am doing sum using collect statement,
here I am having two fields one is text and another one is numeriacal
I done like below
text field numerial field
a 1
b 2
c 2
a 2
a 8
a 3
so here I got a = 14,b = 2,c = 2.
I done sort by using text field
but what my problem is I need show the values in desending order of numerial field,
for that I done again sort by taking all these values into another internal table,
but again the data chaged as it is how before adding these field,
pls any one help me.
Thanks®ds,
Nicky.
2008 Jun 27 7:45 AM
Instead of using collect - go for control break events.
Table contains two fields text & value.
sort itab by text.
loop at itab into wa.
wa1 = wa.
sum = sum + wa-value.
at end of text.
wa1-text = wa-text.
wa1-value = sum.
append wa1 to itab1.
clear sum.
endat.
clear: wa, wa1.
endloop.
sort itab1 by value descending.
reward if useful.
2008 Jun 24 3:37 PM
Hello,
Though, it is very difficult to understand what exactly U are looking for..
I'm assuming that there is some problem and for that try using the below logic:
SORT by text field numeric field DESCENDING.
Let us know, if this helps.
<removed_by_moderator>
Rgds,
Raghu.
Edited by: Julius Bussche on Jun 24, 2008 7:04 PM
2008 Jun 24 3:47 PM
2008 Jun 24 3:38 PM
Snicky,
No need of another itab.
after doing SUM you can sort by decending at numeric field.
Amit.
2008 Jun 24 3:48 PM
2008 Jun 24 3:38 PM
You can first sort by text field and then by numerical field DESCENDING.
<removed_by_moderator>
Edited by: Julius Bussche on Jun 24, 2008 7:10 PM
2008 Jun 24 3:41 PM
Hi,
I done that,it became same as earlier before done sum,it means it sorted as desending order but no sum on similar fields.
Thanks®ds,
Nicky.
2008 Jun 24 3:41 PM
Hi,
After your Collect Statement write the following statement.
sort <second_internal_table> by text field.
<removed_by_moderator>
Warm Regards
R Adarsh
Edited by: Julius Bussche on Jun 24, 2008 7:11 PM
2008 Jun 24 3:52 PM
Hi Adarsh,
Can you expalin me bit,I tried as u suggested but no use.
Thanks®ds,
Nicky.
2008 Jun 24 3:42 PM
hiiii
just use AT NEW fieldname.
& SUM..it will give you correct result.
like below
loop at..
at new field1.
sum.
write
endloop.
<removed_by_moderator>
thx
twinkal
Edited by: Julius Bussche on Jun 24, 2008 7:11 PM
2008 Jun 24 3:44 PM
Hi,
You can do the desired output like below way-
First sort the internal table by numerical field(Field 2) Descending in Descending Order.
After that sort Internal table again By Text Field (Field 1)
in Ascending order.
<removed_by_moderator>
Regards,
Sujit
Edited by: Julius Bussche on Jun 24, 2008 7:09 PM
2008 Jun 24 3:50 PM
hi,
this is what you need at the end?
a 14
b 2
c 2
(numbers in descending order)
in this case you have to do:
SORT itab BY text.
COLLECT itab.
SORT itab BY number descending.
hope this helps
ec
2008 Jun 24 3:58 PM
Hi,
Here I am using like below
Sort itab by text.
loop at itab into wa.
collect wa into itab.
sort itab by num.
endloop.
but here numerical value became increment.
can u suggest me how to proceed.
Thanks®ds,
Nicky.
2008 Jun 24 4:01 PM
-if the internal table has header line, than forget the LOOP and just do, what I suggested above
-if the internal table has NO header line, than you'll need a 2nd internal table (same as the first) and you have to code like:
Sort itab by text.
loop at itab into wa.
collect wa into itab2.
endloop.
sort itab2 by num DESCENDING.
pls. see the differences to your code:
COLLECT into itab2
SORT outside the LOOP and DESCENDING
2008 Jun 24 4:23 PM
2008 Jun 24 4:34 PM
how did you define the internal table? probably the number field is not defined as type n/p/i ?
2008 Jun 24 4:38 PM
2008 Jun 24 4:39 PM
2008 Jun 24 4:44 PM
2008 Jun 24 4:45 PM
I ask you third time: Copy here the definition of the internal table! The whole table, not just the number field!
2008 Jun 24 4:50 PM
HI Eric,
I am getting these values from functionmodule by providing input values,
This is the structure of that FM
KURZTEXT1 CHAR40 CHAR
QMTXT QMTXT CHAR
AUSZT2 ZDEC DEC
QMNUM QMNUM CHAR
KURZTEXT2 CHAR40 CHAR
KURZTEXT3 CHAR40 CHAR
KURZTEXT4 CHAR40 CHAR
ZSUM ZDEC DEc 13 2
PER ZDEC DEC
SUM1 ZDEC DEC 13 2
______________________________ ______________________________ ____________________________________________________________________________________________________________________________________
2008 Jun 24 4:54 PM
2008 Jun 24 6:03 PM
As per your original request/specs
DATA:
BEGIN OF itab_rec,
text TYPE c,
num TYPE i,
END OF itab_rec.
DATA:
itab LIKE STANDARD TABLE OF itab_rec,
sumtab LIKE STANDARD TABLE OF itab_rec.
START-OF-SELECTION.
PERFORM build_itab.
REFRESH sumtab.
LOOP AT itab INTO itab_rec.
COLLECT itab_rec INTO sumtab.
ENDLOOP.
SORT sumtab DESCENDING BY num.
LOOP AT sumtab INTO itab_rec.
WRITE:/ itab_rec-text, itab_rec-num.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form build_itab
*&---------------------------------------------------------------------*
FORM build_itab.
itab_rec-text = 'a'. itab_rec-num = 1. APPEND itab_rec TO itab.
itab_rec-text = 'b'. itab_rec-num = 2. APPEND itab_rec TO itab.
itab_rec-text = 'c'. itab_rec-num = 2. APPEND itab_rec TO itab.
itab_rec-text = 'a'. itab_rec-num = 2. APPEND itab_rec TO itab.
itab_rec-text = 'a'. itab_rec-num = 8. APPEND itab_rec TO itab.
itab_rec-text = 'a'. itab_rec-num = 3. APPEND itab_rec TO itab.
and the output
a 14
b 2
c 2
2008 Jun 25 7:57 AM
ok, just follow what Paul suggested, create an internal table with fields KURZTEXT1 and AUSZT2 only. The COLLECT does not work on your original table, because you have more fields in the table (which have different data; I assume) and these fields are also used for the comparision.
2008 Jun 27 7:13 AM
Hi Paul,
In my case I am working in BSP,so I am explicitly defining work area and body,pls explain me how to concatenate by using body and work area,I am expecting solution from you.
Thanks®ds,
Sree.
2008 Jun 27 7:33 AM
hi ,
do like this,
concider ur internal table itab.then declare another internal table of same type.
now :
loop at itab.
itab1-text = itab - text.
itab1-num = itab-num.
collect itab1. -
instead of append u use collect.
clear itab1.
endloop.
sort itab1 by text .
regards,
diana.
2008 Jun 27 7:45 AM
Instead of using collect - go for control break events.
Table contains two fields text & value.
sort itab by text.
loop at itab into wa.
wa1 = wa.
sum = sum + wa-value.
at end of text.
wa1-text = wa-text.
wa1-value = sum.
append wa1 to itab1.
clear sum.
endat.
clear: wa, wa1.
endloop.
sort itab1 by value descending.
reward if useful.
2008 Jun 27 7:52 AM
Hi SnickyUcan ,
did u try my code. it will definitely work fine..
i have done before..
try this. and let me know if any further clarification u need..
regards,
diana.
2008 Jun 28 5:05 AM