Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Compare char fields

miguel_silva3
Explorer
5,400

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.


1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,511

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.



5 REPLIES 5
Read only

Former Member
0 Likes
2,511

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.

Read only

Former Member
0 Likes
2,512

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.



Read only

0 Likes
2,511

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'.

Read only

0 Likes
2,511

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.

Read only

Former Member
0 Likes
2,511

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.