cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

string comparison

Former Member
0 Likes
527

Hi

Do the standard comparison operators only work for numeric values?

I'm finding that

"a" < "b"

"a" > "b"

"a" == "b"

all return false.

"a" <= "b"

"a" >= "b"

both return true.

How do I properly compare "a" and "b"?

Thanks

Nick

Edited by: Nick Stannage on Sep 16, 2008 9:21 AM

View Entire Topic
Former Member
0 Likes

Assuming you want to compare strings for equality/inequality, I would use the the match() function in the BL editor which would return a 0/1 as the case may be.

Is this what you are looking for?

Former Member
0 Likes

No, I want to check > and <. basically I have two variables with dates as strings and want to know if one date is greater than the other, eg

2008-09-15 < 2008-09-16

but it could just have easily been two other strings, for example batchA and batchB

Former Member
0 Likes

Nick,

Use the datecompare function, if you want to compare two dates.


datecompare(datetoxmlformat("2008-09-15","yyyy-MM-dd"),datetoxmlformat("2008-09-16","yyyy-MM-dd))

See the help for more info: http://help.sap.com/saphelp_xmii115/helpdata/en/Business_Logic_Services/expressions.htm

John

Former Member
0 Likes

But unless you are looking for an equivalent ascii value for a string I do not see how you can get a greater or less than for a string.

If this is the case then I guess you would need a custom action because as far as I know no methods are available for these.

Otherwise what John's posted (for dates) should be the way to go.

For strings that are just numeric you can use the number() function followed by the different operators for comparison.

jcgood25
Active Contributor
0 Likes

How about datetoseconds? Get the java long for the equivalent datetime string and then you can do your > or < checks against numbers.

Regards,

Jeremy

Former Member
0 Likes

Thanks for all the replies, and for my current problem the date conversion functions will do the job.

It's a bit of a hole in the language though is it not?