2015 Apr 05 5:11 AM
Hi Guys,
Just want to ask something, I know its weird but Im having a problem with the sorting of internal tables with multiple selections or fields.Please see my code below:
SORT table BY fieldname ASCENDING
dates ASCENDING
times ASCENDING
begda ASCENDING
process_id ASCENDING.
There are 2 records. All fields have the same record except for process_id:
Fieldname date times begda process_id
field1 20140201 121222 20140201 000008
field1 20140201 121222 20140201 000005
I dont believe I should sort the process_id by descending right?
Please help!
KR,
DF
2015 Apr 06 2:00 AM
Hi,
Heres an extra info regarding my query above as asked by Gupta:
I will be adding an additional data in the table.
Fieldname date times begda process_id
field1 20140201 121222 20140201 000008
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000005
My expected output is:
Fieldname date times begda process_id
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000005
field1 20140201 121222 20140201 000008
However, after it passes to code SORT,
SORT table BY fieldname ASCENDING
dates ASCENDING
times ASCENDING
begda ASCENDING
process_id ASCENDING.
it becomes like this:
Fieldname date times begda process_id
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000008
field1 20140201 121222 20140201 000005
The last two records are not properly sorted out. Need your help here experts
Or using pre 7.4 code, I also get the same results.
This is the program I wrote to try to replicate your problem:
TYPES: BEGIN OF test_ty,
fieldname TYPE fieldname,
dates TYPE d,
times TYPE t,
begda TYPE begda,
process_id TYPE c LENGTH 6,
END OF test_ty.
DATA test_records TYPE STANDARD TABLE OF test_ty.
DATA test_record TYPE test_ty.
test_record-fieldname = 'field1'.
test_record-dates = '20140201'.
test_record-times = '121222'.
test_record-begda = '20140201'.
test_record-process_id = '000008'.
INSERT test_record INTO TABLE test_records.
test_record-fieldname = 'field1'.
test_record-dates = '20140101'.
test_record-times = '121222'.
test_record-begda = '20140101'.
test_record-process_id = '000000'.
INSERT test_record INTO TABLE test_records.
test_record-fieldname = 'field1'.
test_record-dates = '20140201'.
test_record-times = '111524'.
test_record-begda = '20140201'.
test_record-process_id = '000003'.
INSERT test_record INTO TABLE test_records.
test_record-fieldname = 'field1'.
test_record-dates = '20140201'.
test_record-times = '121222'.
test_record-begda = '20140201'.
test_record-process_id = '000005'.
INSERT test_record INTO TABLE test_records.
LOOP AT test_records INTO test_record.
WRITE:/ test_record-fieldname, test_record-dates DD/MM/YYYY,
test_record-times, test_record-begda, test_record-process_id.
ENDLOOP.
SKIP.
SORT test_records BY fieldname ASCENDING
dates ASCENDING
times ASCENDING
begda ASCENDING
process_id ASCENDING.
LOOP AT test_records INTO test_record.
WRITE:/ test_record-fieldname, test_record-dates DD/MM/YYYY,
test_record-times, test_record-begda, test_record-process_id.
ENDLOOP.
When I run it I also get, as expected,
field1 01.01.2014 121222 01.01.2014 000000
field1 01.02.2014 111524 01.02.2014 000003
field1 01.02.2014 121222 01.02.2014 000005
field1 01.02.2014 121222 01.02.2014 000008
What types are you using for each of the fields in your internal table? What type is your internal table?
2015 Apr 05 5:49 AM
If the issue is with process_id value then, try with
SORT table BY fieldname process_id ASCENDING.
Behavior of SORT is seen like you've mentioned when Date, time fields are involved.
Regards
KJogeswaraRao
2015 Apr 05 5:58 AM
Hi Jogeswara,
Yes that eould do, how ever, it will not work since the process_id will only increment if the date and time stamp(fields dates and times) are both the same. the table I am actually referring is the DCTLog. I cannot make it be sorted the way it should have been sorted out
2015 Apr 05 6:54 AM
OK I understand.
Then you should try different sort combinations for date/time fields only the first being DESCENDING to Time field , like
SORT table BY fieldname ASCENDING
dates ASCENDING
times DESCENDING
begda ASCENDING
process_id ASCENDING.
Also try by combining dates, times fields to a timestamp field and sort like your original syntax.
2015 Apr 05 2:52 PM
Hi Jogeswara,
Ill try but i dont think that would work. Thanks for the suggestions tho.
2015 Apr 05 2:53 PM
2015 Apr 05 4:52 PM
Hi,
Try,
SORT table BY fieldname ASCENDING
begda ASCENDING
process_id ASCENDING
dates ASCENDING
times ASCENDING.
Hope it helpful,
Regards,
Venkat.V
2015 Apr 06 1:36 AM
Hi Venkat,
That wont work since the process_id is only being incremented if the time and date stamp is the same.
KR,
DF
2015 Apr 06 7:23 AM
2015 Apr 05 6:27 PM
Hi,
Can you tell me what O/P you are expecting from the same itab-data after sorting.
Regards,
Gupta
2015 Apr 06 1:40 AM
Hi Gupta,
I will be adding an additional data in the table.
Fieldname date times begda process_id
field1 20140201 121222 20140201 000008
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000005
My expected output is:
Fieldname date times begda process_id
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000005
field1 20140201 121222 20140201 000008
However, after it passes to code SORT, it becomes like this:
Fieldname date times begda process_id
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000008
field1 20140201 121222 20140201 000005
Do you know how to properly correct the sorting of this one?
KR,
Philip
2015 Apr 06 2:00 AM
Hi,
Heres an extra info regarding my query above as asked by Gupta:
I will be adding an additional data in the table.
Fieldname date times begda process_id
field1 20140201 121222 20140201 000008
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000005
My expected output is:
Fieldname date times begda process_id
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000005
field1 20140201 121222 20140201 000008
However, after it passes to code SORT,
SORT table BY fieldname ASCENDING
dates ASCENDING
times ASCENDING
begda ASCENDING
process_id ASCENDING.
it becomes like this:
Fieldname date times begda process_id
field1 20140101 121222 20140101 000000
field1 20140201 111524 20140201 000003
field1 20140201 121222 20140201 000008
field1 20140201 121222 20140201 000005
The last two records are not properly sorted out. Need your help here experts
2015 Apr 06 5:00 AM
Hi,
I simulate the issue and do find the solution as below.
TYPES: BEGIN OF ty_data,
name TYPE string,
date1 TYPE dats,
tim1 TYPE tims,
date2 TYPE dats,
id TYPE char10,
END OF ty_data.
DATA lt_itab TYPE TABLE OF TY_DATA.
lt_itab = VALUE #(
( name = 'A' DATE1 = '20140201' TIM1 = '121222' DATE2 = '20140201' ID = '000008' )
( name = 'A' DATE1 = '20140101' TIM1 = '121222' DATE2 = '20140101' ID = '000000' )
( name = 'A' DATE1 = '20140201' TIM1 = '111524' DATE2 = '20140201' ID = '000003' )
( name = 'A' DATE1 = '20140201' TIM1 = '121222' DATE2 = '20140201' ID = '000005' )
).
SORT LT_ITAB BY NAME DATE1 DATE2 ID ASCENDING TIM1 DESCENDING.
**The outcome of the itab after sorting is :-
| A | 20140101 | 121222 | 20140101 | 000000 |
| A | 20140201 | 111524 | 20140201 | 000003 |
| A | 20140201 | 121222 | 20140201 | 000005 |
| A | 20140201 | 121222 | 20140201 | 000008 |
Hope this is what was expected.
Thanks,
Gupta
2015 Apr 06 6:19 AM
2015 Apr 06 6:57 AM
Or using pre 7.4 code, I also get the same results.
This is the program I wrote to try to replicate your problem:
TYPES: BEGIN OF test_ty,
fieldname TYPE fieldname,
dates TYPE d,
times TYPE t,
begda TYPE begda,
process_id TYPE c LENGTH 6,
END OF test_ty.
DATA test_records TYPE STANDARD TABLE OF test_ty.
DATA test_record TYPE test_ty.
test_record-fieldname = 'field1'.
test_record-dates = '20140201'.
test_record-times = '121222'.
test_record-begda = '20140201'.
test_record-process_id = '000008'.
INSERT test_record INTO TABLE test_records.
test_record-fieldname = 'field1'.
test_record-dates = '20140101'.
test_record-times = '121222'.
test_record-begda = '20140101'.
test_record-process_id = '000000'.
INSERT test_record INTO TABLE test_records.
test_record-fieldname = 'field1'.
test_record-dates = '20140201'.
test_record-times = '111524'.
test_record-begda = '20140201'.
test_record-process_id = '000003'.
INSERT test_record INTO TABLE test_records.
test_record-fieldname = 'field1'.
test_record-dates = '20140201'.
test_record-times = '121222'.
test_record-begda = '20140201'.
test_record-process_id = '000005'.
INSERT test_record INTO TABLE test_records.
LOOP AT test_records INTO test_record.
WRITE:/ test_record-fieldname, test_record-dates DD/MM/YYYY,
test_record-times, test_record-begda, test_record-process_id.
ENDLOOP.
SKIP.
SORT test_records BY fieldname ASCENDING
dates ASCENDING
times ASCENDING
begda ASCENDING
process_id ASCENDING.
LOOP AT test_records INTO test_record.
WRITE:/ test_record-fieldname, test_record-dates DD/MM/YYYY,
test_record-times, test_record-begda, test_record-process_id.
ENDLOOP.
When I run it I also get, as expected,
field1 01.01.2014 121222 01.01.2014 000000
field1 01.02.2014 111524 01.02.2014 000003
field1 01.02.2014 121222 01.02.2014 000005
field1 01.02.2014 121222 01.02.2014 000008
What types are you using for each of the fields in your internal table? What type is your internal table?
2015 Apr 06 2:50 PM
What is the domain of process id? is there a conversion exit for it?
Rob
2015 Apr 06 2:55 PM
Maybe it's due to the the internal format of the fields? I would say the table does not have "exactly" what you posted but i may be wrong.. Check for the fields internal formats and/or domains.
Best regards
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |