Round ABAP values up to the nearest value

The ABAP ROUND statement only rounds to nearest value whether it be up or down. See example below:

data: ld_round type p DECIMALS 2 value '22.23',
      ld_result type p DECIMALS 2.
*Rounding using the ROUND ABAP statement
ld_result = round( val = ld_round dec = 2 ). "rounds ld_round to 2 decimal place
write: ld_result. "result = 22.26 as it is already at 2 decimal places
ld_result = round( val = ld_round dec = 1 ). "rounds ld_round to 1 decimal place
write: ld_result. "result = 22.30
ld_round = '22.23'.
ld_result = round( val = ld_round dec = 1 ). "rounds ld_round to 1 decimal place
write: ld_result. "result = 22.20

But sometimes you may want to always round your values up so the following code demonstrates how to always round a number UP to 1 or 2 decimal places.

Also see here for how to Round values down


*Rounds a value UP to 2 decimal places
REPORT  zround2.
PARAMETER: p_value type p decimals 3 default '22.123'.
DATA: d_value type p decimals 2,
      d_int1 TYPE i,
      d_int2 TYPE i,
      d_number(20)     TYPE c,
      d_num_result(20) TYPE c,
      d_decimal(2)     TYPE c.
****************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
d_number = p_value.
SHIFT d_number LEFT UP TO '.'.
SHIFT d_number LEFT.
d_decimal = d_number+0(2).
d_decimal = d_decimal + 1.
Clear: d_number.
d_number = p_value.
SHIFT d_number RIGHT DELETING TRAILING '123456789 '.
SHIFT d_number LEFT DELETING LEADING ' '.
CONCATENATE d_number d_decimal INTO d_num_result.
d_value = d_num_result.
write:/ 'Value rounded up to 2 decimal places is ', d_value.


*Rounds a value UP to 1 decimal place
REPORT  zround1.
PARAMETER: p_value TYPE p DECIMALS 3 DEFAULT '22.123'.
DATA: d_value TYPE p DECIMALS 1,
      d_int1 TYPE i,
      d_int2 TYPE i,
      d_number(20)     TYPE c,
      d_num_result(20) TYPE c,
      d_decimal(2)     TYPE c.
****************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
  d_number = p_value / 10.
  SHIFT d_number LEFT UP TO '.'.
  SHIFT d_number LEFT.
  d_decimal = d_number+0(2).
  d_decimal = d_decimal + 1.
  CLEAR: d_number.
  d_number = p_value / 10.
  SHIFT d_number RIGHT DELETING TRAILING '123456789 '.
  SHIFT d_number LEFT DELETING LEADING ' '.
  CONCATENATE d_number d_decimal INTO d_num_result.
  d_value = d_num_result * 10.
  WRITE:/ 'Value rounded up to 2 decimal places is ', d_value.

Related Articles

Data manipulation - Example code and information on various data manipulation techniques
Retrun the fraction / whole value of a decimal number using MOD, DIV, FRAC or SHIFT
Remove spaces from character field (CONDENSE)
Move minus sign(-) from end to start of field
ABAP Round functionality to round values down to nearest value based on your decimal place requirement
Inserting TAB's into text strings
Change characters within a string ( TRANSLATE )