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

Do decimal places matter when doing logical comparison/expression?

walkerist79
Participant
0 Likes
2,294

CODE# 1

IF GROSS_PRICE <> '0,00' AND NET_PRICE <> '0,00' .
"PRINT SOMETHING HERE"

CODE# 2

IF GROSS_PRICE <> '0' AND NET_PRICE <> '0' .
"PRINT SOMETHING HERE"

Will these code have different results?

CODE# 1

IF GROSS_PRICE <> '0,00' AND NET_PRICE <> '0,00' .
"PRINT SOMETHING HERE"

CODE# 2

IF GROSS_PRICE <> '0' AND NET_PRICE <> '0' .
"PRINT SOMETHING HERE"

Will these code have different results?

4 REPLIES 4
Read only

FredericGirod
Active Contributor
0 Likes
2,057

SAP inside format for decimal is the dot, not the coma. Did you try with a beautiful dot ?

Read only

Sandra_Rossi
Active Contributor
2,057

You are comparing characters, not numbers, so "decimal places" don't mean anything.

If gross_price and net_price have numeric data types, ABAP will convert characters into numbers before comparing, and expects a valid number inside the quotes, i.e. comma is invalid (see ABAP documentation).

Of course, if they have numeric data types, you should write:

IF GROSS_PRICE <> 0 AND NET_PRICE <> 0.
 "PRINT SOMETHING HERE"
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,057

Nice interview question by the way. I expect the interviewer to hear how comfortable you are with talking about ABAP concepts, not to give the "right answer".

Read only

FredericGirod
Active Contributor
0 Likes
2,057

even with ' it works

DATA montant TYPE kbetr.

montant = 10 / 3.
IF montant GT '3.2'.
WRITE 'Cassis'.
ENDIF.
IF montant LT '3.34'.
WRITE 'Pomme'.
ELSE.
WRITE 'Poire'.
ENDIF.