SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Numeric Calculations → Numerical Functions → Examples of numerical functions →Extremum functions nmax, nmin
The example demonstrates the extremum functions nmax and nmin.
Source Code
REPORT demo_nmax_nmin.
SELECTION-SCREEN COMMENT /1(10) text-par.
PARAMETERS: a TYPE i DEFAULT 1,
b TYPE i DEFAULT 0,
c TYPE i DEFAULT 0.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
CONSTANTS: xmin TYPE i VALUE -100,
xmax TYPE i VALUE 100,
n TYPE i VALUE 20000.
DATA: x TYPE decfloat34,
y TYPE decfloat34,
y0 TYPE decfloat34.
DATA txt TYPE string.
DO n + 1 TIMES.
x = ( xmax - xmin ) / n * ( sy-index - 1 ) + xmin.
y = a * x ** 2 + b * x + c.
IF sy-index = 1.
y0 = y.
ELSE.
IF a > 0.
txt = 'Minimum'.
y0 = nmin( val1 = y0 val2 = y ).
ELSE.
txt = 'Maximum'.
y0 = nmax( val1 = y0 val2 = y ).
ENDIF.
ENDIF.
ENDDO.
txt = |{ txt } value of parabola is: { y0 }|.
MESSAGE txt TYPE 'I'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
AT SELECTION-SCREEN.
IF a = 0.
MESSAGE 'You must enter a non-zero value for a' TYPE 'E'.
ENDIF.
Description
The program determines the minimum or maximum value of a parabola which is opened upward or downward and whose parameters can be input on the selection screen.