‎2013 Jul 05 5:44 PM
Hi,
I have some doubt about how it works, the comparation between fields with the type C.
For example with the field type KOSTL it is a CHAR 10.
Data types (C, D, T, X), the comparison runs from left to right. The first character from the left that is different in each field determines which operand is greater. Text fields (type C) are compared based on the underlying character codes.
For the other types (C, N, X) with different lengths, the shorter operand is converted to the length of the longer before the comparison. It is then filled out as follows: Character strings (type C) are filled with spaces from the right
But I can't understand why this are true.
00383E0000 <= 0383045997 <= 0383E00196
Thank you in advance.
‎2013 Jul 06 5:47 AM
00383E0000 <= 0383045997 <= 0383E00196
Case 1::
00383E0000 <= 0383045997
1st 2nd Result
0 0 Equal
0 3 Here 0 < 3. True.
So first condition is TRUE.
Case 2::
0383045997 <= 0383E00196
1st 2nd Result
0 0 Equal
3 3 ""
8 8 ""
3 3 ""
0 E Here E > 0 , should fail.
So first condition is TRUE.
‎2013 Jul 05 9:57 PM
Look at them again. the first number begins with 003, the other two begin with 038, so 003 will come first as it does. The second one begins with 03830 while the third one begins with 0383E. Since 0 comes before E the second number comes before the third.
‎2013 Jul 06 5:47 AM
00383E0000 <= 0383045997 <= 0383E00196
Case 1::
00383E0000 <= 0383045997
1st 2nd Result
0 0 Equal
0 3 Here 0 < 3. True.
So first condition is TRUE.
Case 2::
0383045997 <= 0383E00196
1st 2nd Result
0 0 Equal
3 3 ""
8 8 ""
3 3 ""
0 E Here E > 0 , should fail.
So first condition is TRUE.
‎2013 Jul 06 4:05 PM
In order to know why 'E' is considered greater than '0', you can refer the ASCII chart.
Decimal or hex equivalent of 'E' is greater than that of '0'.
Lowercase characters appear further late in the chart. So 'e' is greater than 'E'.
‎2013 Jul 06 4:54 PM
Hi Kishore,
Thank you for the example, it's very clear, right the text said, the comparison runs from left to right and the first character from the left that is different in each field determines which operand is greater. Text fields (type C) are compared based on the underlying character codes( thank you Manish).
Best Regards.
‎2013 Jul 06 6:09 AM
Hi Miguel,
Kishore has explained it beautifully.
Tip-
Code it and see -
TYPES : BEGIN OF ty_char,
record TYPE string,
END OF ty_char.
DATA : ls_char TYPE ty_char,
lt_char TYPE STANDARD TABLE OF ty_char.
ls_char-record = '00383E0000'.
APPEND ls_char TO lt_char.
ls_char-record = '0383E00196'.
APPEND ls_char TO lt_char.
ls_char-record = '0383045997'.
APPEND ls_char TO lt_char.
SORT lt_char.
For this part,
Case 2::
0383045997 <= 0383E00196
1st 2nd Result
0 0 Equal
3 3 ""
8 8 ""
3 3 ""
0 E Here E > 0 , should fail.
What it means is E>0 so it(String of 2nd in Case2) should be the largest and be at the bottom of sort.
Ask if not clear.
BR.