‎2007 Aug 30 10:26 AM
Hi Experts,
i have an internal table with data as follows:
matnr date balance
b 20061010 0
a 20061016 10
a 20061016 20
a 20061016 30
before sorting the internal has data like the above.
But after the statement:
sort itab by matnr date.
the internal table itab is like this:
matnr date balance
a 20061016 30
a 20061016 20
a 20061016 10
b 20061010 0
how the order of the balance changed from 10,20,30 to 30,20,10.
if i want to get the data as follows:
matnr date balance
a 20061016 10
a 20061016 20
a 20061016 30
b 20061010 0
what should i do?
Please help.
Regards,
Soumya
‎2007 Aug 30 10:28 AM
‎2007 Aug 30 10:28 AM
‎2007 Aug 30 10:29 AM
Hi Soumya,
Try using
SORT ITAB BY MATNR DATE <b>ASCENDING</b>.
<b>Reward points for helpful answers</b>.
Best Regards,
Ram.
‎2007 Aug 30 10:29 AM
‎2007 Aug 30 10:29 AM
‎2007 Aug 30 10:30 AM
hi
may b the records in the table were inserted in that order....
first a 20061016 30 then the next....
‎2007 Aug 30 10:31 AM
hi,
when u sort ur table try this ;:
sort itab by matnr balance.
if this does not give u the results try
sort matnr date balance.
reward with points if useful
thank
nayan
‎2007 Aug 30 10:31 AM
hi,
sort itab by matnr date balance.
Reward with points if helpful.
‎2007 Aug 30 10:31 AM
Hi Soumya,
Please try :
sort itab ascending by matnr date balance.
Reward points if useful.
Rgds,
Preeti
‎2007 Aug 30 10:43 AM
i don't think you will get the desired results by a standard sort statement...
you want to sort on matnr by ascending and date descending - this is possible
sort itab by matnr ascending date descending.
you want to put the zero values at the end for balance....while keeping the rest of the values ascending.....this is not possible by the sort statement
do this manually
first sort it on balance by ascending
sort itab by matnr ascending date descending balance ascending.
then loop on the table and wherever you find zero for balance...put it at the end
loop at itab into wa.
i_tabix = sy-tabix.
if wa-balance eq 0.
append wa to itab.
delete itab index i_tabix.
endif.
endloop.
hope this helps...
forgot to mention.....do remember to adjust this code a bit...else it will lead to an infinite loop......
for this...may be you can store the number of lines originally in the table and proceed with the append-delete thing only up to that value of sy-tabix.
Message was edited by:
Priyank Jain
Message was edited by:
Priyank Jain
‎2007 Aug 30 11:03 AM
Hi,
My problem is not regarding the balance.
before sorting the itab was like this:
matnr date balance
a 20061016 10
a 20061016 20
a 20061016 30
b 20061010 0
i am sorting based on the matnr and date field.
since the matnr and date field values for the first three entries are the same, i should keep it it like that only.
the problem is after sorting , it reversed like this:
matnr date balance
a 20061016 30
a 20061016 20
a 20061016 10
why it happened so?
‎2007 Aug 30 12:16 PM
hi,
Ya but what is the problem in sorting itab by balance also as every one suggest?
‎2007 Aug 30 1:41 PM
Hi all,
My problem is solved using STABLE addition like below:
sort itab stable by matnr date.
Regards,
Soumya