1

Hello to every one and HAPPY NEW YEAR. I have the following problem: a char field contains an amount and I want to make the following check: if wfile-dmbtr < 0.00

The code I use:

data: lv_dmbtr(18) type n.    
write wfile-dmbtr to lv_dmbtr.
replace first occurrence of '.' in lv_dmbtr with ''.
translate lv_dmbtr using ',.'.
if lv_dmbtr <= '0.00'.

The problem is for values between 0.01 to 0.49, and the program most probably round them to 0 and returns True.

The dmbtr amounts have the following mask: 12.235,99. Does anyone knows how to overcome this issue?

Thanks in advance.

Elias

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
ekekakos
  • 563
  • 3
  • 20
  • 39

1 Answers1

4

Elias. Happy new year to you too.

Type N does not allow the use of decimals (even though you might be able to see it in the debugger if you force such value). That's the reason why the number is being rounded and the condition evaluation 'seems' to fail.

In addition, after you do the number conversion / formatting, you might be better off using a decimal type variable to do the condition evaluation (such as type of data element MAXBT).

Example:

DATA: lv_dmbtr(18) TYPE c,       " Used to be type N instead of pure CHAR.
      lv_aux       TYPE maxbt.


WRITE '0,01' TO lv_dmbtr.
REPLACE FIRST OCCURRENCE OF '.' IN lv_dmbtr WITH ''.
TRANSLATE lv_dmbtr USING ',.'.
CONDENSE lv_dmbtr.

lv_aux = lv_dmbtr.

IF lv_aux <= '0.00'.

  BREAK-POINT.

ELSE.

  BREAK-POINT.    " It should enter this bracket for the value 0,01

ENDIF.

Hope it helps.