‎2005 Jun 29 3:55 PM
Hi,
Can someone help me in implementing this simple logic in ABAP.
Set of values : (10,20,30,40,50)
If the value is not in this interval then it is updated to next higher value.
Ex: If the value is 25 , it will be updated to 30.
Tushar.
‎2005 Jun 29 4:06 PM
Hi Tushar,
You can take your value, then divide it by 10, and then use the CEIL statement( which give you the next greater integer, and finally multiply by 10.
eg :
* value_in is '25'.
25 / 10 = 2.5
w_next_integer = CEIL( 2.5 )
* w_next_integer take the value '3'.
value_out = w_next_integer x 10.
* value_out = '30'Hope this helps.
Regards,
Erwan.
Message edited by: Erwan LE BRUN "following the Rich's remark" Not FLOOR but 'CEIL' (mistake)
‎2005 Jun 29 4:17 PM
Here is a sample....
report zrich_0005.
data: value type i.
ranges: r_values for value.
start-of-selection.
r_values-sign = 'I'.
r_values-option = 'EQ'.
r_values-low = '10'. append r_values.
r_values-low = '20'. append r_values.
r_values-low = '30'. append r_values.
r_values-low = '40'. append r_values.
r_values-low = '50'. append r_values.
if not value in r_values.
value = ( ceil( value / 10 ) * 10 ).
endif.
write:/ value.
Regards,
Rich Heilman
‎2005 Jun 29 4:21 PM
‎2005 Jun 29 5:00 PM
Another Sample....
REPORT zramki.
PARAMETERS: p_val TYPE i.
DATA:
result TYPE i,
BEGIN OF it_num OCCURS 0,
val TYPE i,
END OF it_num.
START-OF-SELECTION.
it_num-val = 10. APPEND it_num.
it_num-val = 20. APPEND it_num.
it_num-val = 30. APPEND it_num.
it_num-val = 40. APPEND it_num.
it_num-val = 50. APPEND it_num.
SORT it_num.
CLEAR result.
LOOP AT it_num.
IF it_num-val < p_val.
CONTINUE.
ENDIF.
result = it_num-val.
EXIT.
ENDLOOP.
WRITE:/ 'Value =', p_val.
IF result IS INITIAL.
WRITE: / 'Input value higher than largest list value: ',
it_num-val.
ELSE.
WRITE: / 'Result = ', result.
ENDIF.
Cheers,
Ramki Maley.
‎2005 Jun 29 6:24 PM