05-13-2014 2:34 PM
I have a problem sorting data when for all entries is used
for example i got it_pernr like this
row pernr
1 5
2 2
3 8
Then i got the selection
SELECT pernr test_column
FROM test_table INTO CORRESPONDING FIELDS OF TABLE it_test_table
FOR ALL ENTRIES IN it_pernr
WHERE pernr = it_pernr-pernr
AND begda <= sy-datum
AND endda >= sy-datum.
After selection i got table it_test table like this :
row pernr test_column
1 2 test2
2 8 test8
3 5 test5
So my question is how can I sort it like this ( like in it_pernr):
row pernr test_column
1 5 test5
2 2 test2
3 8 test8
Thanks in advance
05-13-2014 2:47 PM
1. Create one more table with same structure as it_test say it_test1
2. Loop over the table it_pernr
Read it_test into w_test with key it_pernr-pernr
If sy-subrc = 0
append w_test to it_test1.
endif.
endloop.
3. clear it_test[].
4. it_test[] = it_test1[].
05-13-2014 2:43 PM
Hi,
TRy below code.
sort IT_TEST_TABLE by pernr.
Loop at IT_PERNR into WA_PERNR.
read table IT_TEST_TABLE into WA_TAB with key pernr = wa_pernr-pernr binary search.
if sy-subrc = 0.
apppend WA_TAB to it_new_sort.
endif.
endloop.
IT_NEW_SORT will be in the order of IT_PERNR.
Regards
Sree
05-13-2014 2:45 PM
Hi,
You are getting given output in shown format because row, pernr is key field.
If you want the output in desired format then create 1 more internal table ITBA3 with three field-row, pernr, test_column.
sort it_test_table by pernr.
Loop on it_pernr into wa_pernr.
wa_itab3-row = wa_pernr-row.
wa_itab3-pernr = wa_pernr-pernr.
read table it_test_table into wa_test with key pernr = wa_pernr-pernr.
if sy-subrc eq 0.
wa_itab3-test_column = wa_test-test_column.
endif.
if wa_itab3 is not initial.
append wa_itab3 to it_tab3.
endif.
clear:wa_itab3, wa_pernr, wa_test.
endloop.
Now your it_tab3 is desired output.
If you have any query, let me know.
Regards,
Sudeesh Soni
05-13-2014 2:47 PM
1. Create one more table with same structure as it_test say it_test1
2. Loop over the table it_pernr
Read it_test into w_test with key it_pernr-pernr
If sy-subrc = 0
append w_test to it_test1.
endif.
endloop.
3. clear it_test[].
4. it_test[] = it_test1[].
05-13-2014 3:03 PM
If you want both to be in the same order, why not sort both the tables on pernr itself.
Also SORT means order either ascending or descending what order is 5,2,8 ????
Regards
05-13-2014 3:15 PM
There is no sorting problem. Your first internal table is actually not sorted.
When you use for all entries, system will give data in sorted order.
If your requirement is to get the order as per first internal table, then u can write extra logic to get desire output.
05-13-2014 3:44 PM
05-13-2014 5:23 PM
hi
Please mark the correct answer or mark helpful answer and close the thread.
Regards,
Sudeesh Soni