Skip to Content
author's profile photo
Former Member

Function Module

Hi Guys,

I have a condition where I need to round off the number:

1st case: 15/2= 7.5 then it should return 8

IInd cse : 13/3 = 4.3 then it should return 4

and IIIrd case: 17/3= 5.67 then it should return 6

So is tehre any function module that will help me out.

Thanks

Rajeev gupta

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:35 PM

    Rajeev,

    <b>

    J_1I6_ROUND_TO_NEAREST_AMT</b>.

    Thanks

    Aneesh.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      DATA: out TYPE i.

      DATA: input TYPE f.

      DATA : v_input(10) TYPE c.

      input = '10.1'.

      DATA : v_dec(2) TYPE c,

      v_value(10) TYPE c.

      DATA : v_sign TYPE c.

      v_input = input.

      SPLIT v_input AT '.' INTO v_value v_dec.

      IF v_dec GE 5.

      v_sign = '+'.

      ELSE.

      v_sign = '-'.

      ENDIF.

      CALL FUNCTION 'ROUND'

      EXPORTING

      • DECIMALS = 0

      input = input

      sign = v_sign

      IMPORTING

      output = out

      EXCEPTIONS

      input_invalid = 1

      overflow = 2

      type_invalid = 3

      OTHERS = 4

      .

      IF sy-subrc <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      WRITE out.

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:30 PM

    Check with below FM's :

    ROUND_AMOUNT

    ROUND

    if you need any other FM's ,just goto SE37 Transaction -> search like round -> here you get list of FM's

    Thanks

    Seshu

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:32 PM

    Hi,

    Observe the below code which is useful for you .

    **************************************************

    REPORT RAMESH.

    *trunc, ceil and

    data:A TYPE P LENGTH 5 DECIMALS 2,

    B TYPE P LENGTH 5 DECIMALS 2,

    C TYPE P LENGTH 5 DECIMALS 2,

    A1 TYPE I,

    B1 TYPE I,

    C1 TYPE I.

    A = '7.5'.

    A1 = CEIL( A ).

    WRITE:/ A1.

    B = '4.3'.

    B1 = TRUNC( B ).

    WRITE: / B1.

    C = '5.67'.

    C1 = CEIL( C ).

    WRITE:/ C1.

    ************************************************

    Regards

    Ramesh mavilla.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:36 PM

    Just use a integer to store the values:

    DATA: I1 TYPE I.

    DATA: I2 TYPE I.

    DATA: I3 TYPE I.

    I1 = 15 / 2.

    I2 = 13 / 3.

    I3 = 17 / 3.

    WRITE:/ I1, I2, I3.

    result: 8, 4 and 6.

    Add comment
    10|10000 characters needed characters exceeded