Application Development 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: 

Strange! GT and LT does not work...

Former Member
0 Kudos

IF p_co LT c_llimit.

MESSAGE ID hr_msg_class TYPE 'E' NUMBER '170'.

ENDIF.

IF p_co GT c_hlimit.

MESSAGE ID hr_msg_class TYPE 'E' NUMBER '170'.

ENDIF.

Here p_co, c_llimit, c_hlimit are all of char type and lt. 3.

And constant val;ues assigned to c_llimit and c_hlimit are 95 and 105.

But if I enter a value say p_co equal to 99, it enters the second IF condition even though it is NOT GT than 105! and Similarly if I enter a value p_co = 100 it enters the first IF condition even though it is NOT LT 95!

Please help.

Edited by: Julius Bussche on Jul 26, 2009 10:30 PM

Subject title improved...

7 REPLIES 7

Former Member
0 Kudos

Hi,

In Character data types, u will face this problem always.

Basically in character data types, '99' will be treated as '99_ ' and on character to character comparison, '99_ ' is greater than '105'.

Similarly '100' is less than '95 '.

Instead u can use the NUMC data type if possible.

Regards,

Himanshu

Former Member
0 Kudos

Hi Anand,

what is the type of p_co? Number? Or char-like?

If it's char-like, '95' is greater than '105', because SAP performs a lexicographic comparison, byte by byte, so '9' is greater than '1', and then the condition is true.

I hope it helps. Best regards,

Alvaro

raymond_giuseppi
Active Contributor
0 Kudos

'99' is greater than '105', in fact '99 ' is greater than '105' but '099' is lower than '105'.

So use NUMC fields or if you actualy need CHAR field, fill the default value with leading zeroes and insure that the field use conversion exit ALPHA (choose a data element ad hoc) so user input will also been right justified and filled with leading zeroes.

Regards

Former Member
0 Kudos

Hi,

it happens so often,as comparison is done byte to byte i.e, lexographical..

so,'99' would be GT 105 and even 100 would be LT 99.

use Numc data type instead and try.

thanx.

Former Member
0 Kudos

Believe this is a very valid q which unfortunately has not been satisfactorily answered. I even have no answer to this q and would be happy to find one.

But just to paraphrase even if we were to accept byte by byte and lexi comparison as stated by many respondents - still - for numeric values of data type CHAR the padding is done at the left which would mean 99 would be 099. So anyways it is less than 100.

So believe this q needs better resolution.

faisal_altaf2
Active Contributor
0 Kudos

Hi,

Please USE Meaningful Subject Line Next Time

Regards,

Faisal

Former Member
0 Kudos

Declare them as NUMC would solve.

Thanks

Kiran