Skip to Content
author's profile photo Former Member
Former Member

how to use the remainder opertor in abap

Hi,

I want to use the % operator to get the remainder.

What i have done is

lv_data = 301.

lv_test = lv_data % 3.

I want to get the result as 1.

But this just fails to work

Please suggest a solution.

regards,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 10:59 AM

    Use the MOD operator

    i am giving u an example

    DATA: COUNTER TYPE I.

    COMPUTE COUNTER = COUNTER + 1.

    COUNTER = COUNTER + 1.

    ADD 1 TO COUNTER.

    Here, the three operational statements perform the same arithmetic operation, i.e. adding 1 to the contents of the field COUNTER and assigning the result to COUNTER.

    DATA: PACK TYPE P DECIMALS 4,

    N TYPE F VALUE '+5.2',

    M TYPE F VALUE '+1.1'.

    PACK = N / M.

    WRITE PACK.

    PACK = N DIV M.

    WRITE / PACK.

    PACK = N MOD M.

    WRITE /PACK.

    The output appears as follows:

    4.7273

    4.0000

    0.8000

    REWARD POINTS IF USEFUL

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 11:02 AM

    Hello,

    Use MOD keyword to get the remainder.

    Please Reward points.

    Viswam.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 11:04 AM

    HI,,

    sarma

    in SAP % does not works insted of that you have to use 'MOD' it iwll work for sure

    plzz reward if it is useful....

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 10:59 AM

    Hi,

    I think you should use mod operator to get reminder not % operator

    Example

    DATA: D1 TYPE I, D2 TYPE I, D3 TYPE I, D4 TYPE I,

    M1 TYPE P DECIMALS 1, M2 TYPE P DECIMALS 1,

    M3 TYPE P DECIMALS 1, M4 TYPE P DECIMALS 1,

    PF1 TYPE F VALUE '+7.3',

    PF2 TYPE F VALUE '+2.4',

    NF1 TYPE F VALUE '-7.3',

    NF2 TYPE F VALUE '-2.4'.

    D1 = PF1 DIV PF2. M1 = PF1 MOD PF2.

    D2 = NF1 DIV PF2. M2 = NF1 MOD PF2.

    D3 = PF1 DIV NF2. M3 = PF1 MOD NF2.

    D4 = NF1 DIV NF2. M4 = NF1 MOD NF2.

    The variables now have the following values:

    D1 = 3, M1 = 0.1,

    D2 = - 4, M2 = 2.3,

    D3 = - 3, M3 = 0.1,

    D4 = 4, M4 = 2.3.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 11:00 AM

    Hi,

    data: lv_data type i.

    data: lv_test type i.

    lv_data = 301.

    lv_test = lv_data mod 3.

    write lv_test.

    regards,

    Santosh Thorat

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 11:03 AM

    Hi,

    % this operator will use only for characters finding.

    example u have

    sunil kumar

    praveenkumar

    anilkumar

    if u %kumar then it will display all names which is having kumar

    in ur program if u want display 1 instead of 301 just do shift operator.

    reward me a points if it is use full answer.

    praveen

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.