Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Logic for this..

Former Member
0 Likes
724

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.

5 REPLIES 5
Read only

Former Member
0 Likes
580

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)

Read only

0 Likes
580

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

Read only

0 Likes
580

Using FLOOR will round down, CEIL will round up.

Regards,

Rich Heilman

Read only

0 Likes
580

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.

Read only

0 Likes
580

Has your problem here been solved? Please close post and rewared points accordingly. Thanks.

Regards,

Rich Heilman