This is a test message to test the length of the message box.
Login
ABAP quick min-max values
Created by Software-Heroes

ABAP Quick - Min/max values of data types

4326

Sometimes it is important to know the maximum limits of a data type before assigning a value to them. We show you today in our tip how it works.



In today's little tip we want to show you how to determine the minimum and maximum values of a data type. To this end, we want to make clear with a small example, with which simple code this is possible.

 

Preparation

To do this, we define a number whose data type we want to analyze afterwards and a data reference which should receive the result.


DATA:
  ld_number TYPE p LENGTH 16 DECIMALS 10,
  lr_result TYPE REF TO data.

 

Minimum value

Using class CL_ABAP_EXCEPTIONAL_VALUES, we can derive the minimum value and get back a data reference containing the minimum value. If the reference is set, we assign the value to a field symbol via inline declaration and pass the result to the demo output function.


lr_result = cl_abap_exceptional_values=>get_min_value( ld_number ).

IF lr_result IS NOT INITIAL.
  ASSIGN lr_result->* TO FIELD-SYMBOL(<ld_result>).
  cl_demo_output=>write_data( <ld_result> ).
ENDIF.

 

Maximum value

To get the maximum value we use another method of the same class. Again we pass the value to the output method. Afterwards we show the result as a popup with the display method of the output class.


lr_result = cl_abap_exceptional_values=>get_max_value( ld_number ).

IF lr_result IS NOT INITIAL.
  ASSIGN lr_result->* TO FIELD-SYMBOL(<ld_result2>).
  cl_demo_output=>write_data( <ld_result2> ).
ENDIF.

" Output
cl_demo_output=>display( ).

 

Conclusion

As you can see, finding the minimum and maximum value of a data type is not difficult. The class contains additional functions to validate other data types. Just try it out and get acquainted with it to use it effectively for dynamic programming.


Included topics:
QuickMin/Max
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP Quick - Handling of Function modules

Category - ABAP

How do you actually handle function modules and error handling within ABAP? In this short tip, we'll also look at handling them within the context of RFC.

08/26/2025

ABAP Quick - Generic Data Types

Category - ABAP

What exactly distinguishes CLIKE from CSEQUENCE? Generic types can sometimes be a bit opaque, and as ABAP developers, we might choose a type that's too generic.

08/12/2025

BTP - Quick Deployment

Category - ABAP

Want to make Fiori Elements apps available even faster after RAP modeling? Quick Deployment is now possible.

07/18/2025

Recycling Heroes (Explained)

Category - ABAP

What do the Recycling Heroes have to do with modern ABAP development and ABAP Cloud? In this article, we provide insights into the idea.

07/15/2025

ABAP Quick - Ranges and Select Options

Category - ABAP

Ranges and Select Options in ABAP are very similar, yet there are subtle differences in their use in the ABAP OO context. Here we'll look at their modern usage.

05/09/2025