‎2009 Jun 23 1:45 PM
Dear all,
Need your help for the following issue.
I intend to sort the internal table (given below) with endda in the descending order along with 2 other key fields, so i was expecting the record with endda '99991231' as the first entry in the internal table, but this is not happening.
REPORT ytest_sort.
DATA:li_p9 TYPE TABLE OF pa0009 WITH HEADER LINE.
li_p9-begda = '20090515'.
li_p9-endda = '20090520'.
li_p9-subty = '0'.
APPEND li_p9.
li_p9-begda = '20090521'.
li_p9-endda = '99991231'.
li_p9-subty = '0'.
APPEND li_p9.
SORT li_p9 BY endda subty seqnr DESCENDING.
DELETE ADJACENT DUPLICATES FROM li_p9 COMPARING subty seqnr.
WRITE 'sorted'.
Need your help in identifying the issue with the sort statement in the above code fragment.
Thanks & Regards,
Kiran N N
‎2009 Jun 23 1:55 PM
sneha,
Thankyou for your reply. If you observe the above code, both seqnr and subty have same values for both entries, so it should be solely dependant on the endda right?
‎2009 Jun 23 1:48 PM
Hi,
Since your sort contains 3 fields it will work on the combination of these 3 and not on the field 'endda' alone..
please check this ... and sort accordingly..
SORT li_p9 BY endda subty seqnr DESCENDING. <--- Check the field 'seqnr'
‎2009 Jun 23 1:54 PM
Hi Kiran
Can you please tell what is the field seqnr?
Where it is populated in the table?
Regards,
Deepa Kulkarni
‎2009 Jun 23 1:54 PM
Hi,
you will have to give the DESCENDING additon after the field for which you want to sort in a descending fashion. Else by default it will take Ascending.
Hence your output is coming incorrectly.
So SORT as follows:-
SORT li_p9 BY endda DESCENDING subty DESCENDING seqnr DESCENDING.
Regards,
Ankur Parab
‎2009 Jun 23 1:55 PM
sneha,
Thankyou for your reply. If you observe the above code, both seqnr and subty have same values for both entries, so it should be solely dependant on the endda right?
‎2009 Jun 23 1:58 PM
Hi,
In that case sort by adding descending for all the fields:
sort li_p9 endda descending subty descending seqnr descending .
or
sort li_p9 endda descending subty seqnr.
‎2009 Jun 23 1:55 PM
Hi,
REPORT ytest_sort.
DATA:li_p9 TYPE TABLE OF pa0009 WITH HEADER LINE.
li_p9-begda = '20090515'.
li_p9-endda = '20090520'.
li_p9-subty = '0'.
APPEND li_p9.
li_p9-begda = '20090521'.
li_p9-endda = '99991231'.
li_p9-subty = '0'.
APPEND li_p9.
SORT li_p9 BY endda DESCENDING subty seqnr . " --> Change
DELETE ADJACENT DUPLICATES FROM li_p9 COMPARING subty seqnr.
WRITE 'sorted'.
‎2009 Jun 23 1:56 PM
‎2009 Jun 23 2:02 PM
Avinash,
The delete statement will simply remove values based on endda alone when we have non-zero / non-equivalent values among the fields (seqnr & subty). Please look at the below code.I am simply simulating an issue that i faced in my application.
REPORT ytest_sort.
DATA:li_p9 TYPE TABLE OF pa0009 WITH HEADER LINE.
li_p9-begda = '20090515'.
li_p9-endda = '20090520'.
li_p9-subty = '0'.
APPEND li_p9.
li_p9-begda = '20090521'.
li_p9-endda = '99991231'.
li_p9-subty = '0'.
APPEND li_p9.
li_p9-begda = '20090515'.
li_p9-endda = '20090520'.
li_p9-subty = '0'.
li_p9-seqnr = '001'.
APPEND li_p9.
li_p9-begda = '20090521'.
li_p9-endda = '99991231'.
li_p9-subty = '0'.
li_p9-seqnr = '001'.
APPEND li_p9.
li_p9-begda = '20090515'.
li_p9-endda = '20090520'.
li_p9-subty = '1'.
li_p9-seqnr = '001'.
APPEND li_p9.
li_p9-begda = '20090521'.
li_p9-endda = '99991231'.
li_p9-subty = '1'.
li_p9-seqnr = '001'.
APPEND li_p9.
SORT li_p9 BY endda DESCENDING subty seqnr .
DELETE ADJACENT DUPLICATES FROM li_p9 COMPARING subty seqnr.
WRITE 'sorted'.
I hope i have made myself clear here.
Regards,
Kiran
‎2009 Jun 23 2:05 PM
Hi,
If you want to delete duplicate entries then its always better to specify all the fields in the delete statement with which the internal table was earlier sorted.
‎2009 Jun 23 2:07 PM
Hi ,
After each field you need to specify the DECENDING key word otherwise
the table will be sorted by that field in ASCENDING order (which is default).
I have modified a bit your code and now it is working fine.
Please check the code - -
DATA:li_p9 TYPE TABLE OF pa0009 WITH HEADER LINE.
li_p9-begda = '20090515'.
li_p9-endda = '20090520'.
li_p9-subty = '0'.
APPEND li_p9.
li_p9-begda = '20090521'.
li_p9-endda = '99991231'.
li_p9-subty = '0'.
APPEND li_p9.
SORT li_p9 BY endda DESCENDING
subty DESCENDING
seqnr DESCENDING. " added DESCENDING after each field
DELETE ADJACENT DUPLICATES FROM li_p9 COMPARING subty seqnr.Regards
Pinaki
‎2009 Jun 23 2:12 PM
Dear all,
Thanks alot for your input.
The sort statement should have been
SORT li_p9 BY subty DESCENDING seqnr DESCENDING endda DESCENDING.
Have granted points to all.
Thanks & Regards,
Kiran