1

I want to have a SELECT-OPTIONS field in ABAP with the data type FLTP, which is basically a float. But this is not possible using SELECT-OPTIONS.

I tried to use PARAMETERS instead which solved this issue. But now of course I get no results when using this parameter value in the WHERE clause when selecting.

So on the one side I can't use data type 'F', but on the other side I get no results. Is there any way out of this dilema?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
JKD
  • 1,279
  • 1
  • 6
  • 26
  • As far as I know, the type `F` is possible with `PARAMETERS` only if you use `NO-DISPLAY` e.g. `PARAMETERS param TYPE f NO-DISPLAY` (checked with ABAP 7.52 and 7.55), I'm surprised that it works for you. – Sandra Rossi Nov 03 '21 at 16:58

1 Answers1

1

Checking floating point values for exact equality is a bad idea. It works in some edge-cases (like 0), but often it does not work. The reason is that not every value the user can express in decimal notation can also be expressed as a floating point value. So the values get rounded internally and now you get inequality where you would expect equality. Check the website "What Every Programmer Should Know About Floating-Point Arithmetic" for more information on this phenomenon.

So offering a SELECT-OPTION or a single PARAMETER to SELECT floating point values out of a table might be a bad idea.

What I would recommend instead is have the user state a range between two values with both fields obligatory:

PARAMETERS:
   p_from TYPE f OBLIGATORY,
   p_to TYPE f OBLIGATORY.

SELECT somdata 
  FROM table 
  WHERE floatfield >= p_from AND floatfield <= p_to.

But another solution you might want to consider is if float is really the appropriate data-type for your situation. When the table is a Z-table, you might want to consider to change the type of that field to a packed number or one of the decfloat flavors, as those will cause you far fewer surprises.

Philipp
  • 67,764
  • 9
  • 118
  • 153