<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: using mod in the calculation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512049#M1423641</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this for logic&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data:lv_input type string. 
data:lv_index type i,
     lv_odd_pos type string,
     lv_even_pos type string,
     lv_result type string,
     lv_flag type char01.

lv_input = '123456789X'.

lv_index = strlen( lv_input ) - 2.
if lv_index  &amp;gt; 0.
do.
if lv_flag is initial.
lv_odd_pos = lv_odd_pos + lv_input+lv_index(1).
condense lv_odd_pos.
lv_flag = 'X'.
else.
lv_even_pos = lv_even_pos + lv_input+lv_index(1).
condense lv_even_pos.
clear lv_flag.
endif.
if lv_index = 0.
exit.
endif.
lv_index = lv_index - 1.
enddo.
else.
lv_odd_pos = lv_input+lv_index(1).
endif.

lv_result = ( ( lv_odd_pos * 3 ) + lv_even_pos ) ) MOD 10.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Keshav.T on Jan 19, 2010 8:05 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Jan 2010 13:39:48 GMT</pubDate>
    <dc:creator>kesavadas_thekkillath</dc:creator>
    <dc:date>2010-01-19T13:39:48Z</dc:date>
    <item>
      <title>using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512044#M1423636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;experts&lt;/P&gt;&lt;P&gt;810312301234X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to calculate the x value in the above field . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;logic is as shown below.&lt;/P&gt;&lt;P&gt;First we need to add all the odd numbers starting from left ie in our above example it is 4 because x we should not consider so first number is 4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var1 = sum of odd(4&lt;EM&gt;2&lt;/EM&gt;0&lt;EM&gt;2&lt;/EM&gt;3+1)  = 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First we need to add all the even numbers starting from left  here in our case 3 is the first even number and x we should not consider.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var2 = sum of even(3&lt;EM&gt;1&lt;/EM&gt;3&lt;EM&gt;1&lt;/EM&gt;0+8) = 16&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var3 = var1&lt;STRONG&gt;3 + var2  = 10&lt;/STRONG&gt;3 + 16 = 46&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;finally we need to take the mod value ie the remainder and that is our desired value X.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var4 = mod(var3/10) = mod(46/10) = 6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;x= var4 = 6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now please tell me how to do this easily in sap ie how to calculate this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for the replies.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 10:20:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512044#M1423636</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T10:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512045#M1423637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;var = 810312301234X&lt;/P&gt;&lt;P&gt;Get the length of the variable using strlen&lt;/P&gt;&lt;P&gt;varlen = strlen(var)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add all odd digits using the positioning syntax &lt;/P&gt;&lt;P&gt;Eg - &lt;/P&gt;&lt;P&gt;var1 = var&lt;EM&gt;varlen(1)&lt;/EM&gt;....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;same case for var2 also add all the even digits.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var3 = (var1 x 3) + var2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var4 = mod(var3/10) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vartemp = varlen - 1.&lt;/P&gt;&lt;P&gt;replace x by var4 - concatenate var++(vartemp) var4 into var.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 10:59:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512045#M1423637</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T10:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512046#M1423638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;var1 = varlen(1) + varlen(1) + varlen(5) + varlen(7). this is giving wrong result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please anyone tell me another logic&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 12:13:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512046#M1423638</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T12:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512047#M1423639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it should be var+varlen(1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg - var+2(1) which is the third digit. after 2 place 1 digit.&lt;/P&gt;&lt;P&gt;       var+3(5) which is startinf from third position, 5 places.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 12:25:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512047#M1423639</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T12:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512048#M1423640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shiva,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: varx TYPE c LENGTH 10 VALUE '12345x',&lt;/P&gt;&lt;P&gt;      var1 TYPE I,&lt;/P&gt;&lt;P&gt;      var2 TYPE I,&lt;/P&gt;&lt;P&gt;      var3 TYPE I,&lt;/P&gt;&lt;P&gt;      cnt TYPE I,&lt;/P&gt;&lt;P&gt;      mod1 TYPE I,&lt;/P&gt;&lt;P&gt;      x TYPE I.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cnt = STRLEN( varx ) - 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DO cnt TIMES.&lt;/P&gt;&lt;P&gt;  mod1 = var2 mod 2.&lt;/P&gt;&lt;P&gt;  IF mod1 eq 0. " for even numbers&lt;/P&gt;&lt;P&gt;  var1 = varx+var2(1) + var1.&lt;/P&gt;&lt;P&gt;  ELSE. " for odd numbers&lt;/P&gt;&lt;P&gt;  var3 = varx+var2(1) + var3.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;var2 = var2 + 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;x =  ( ( var3 * 3 ) + var1 )  mod 10.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Swarna Munukoti&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 13:03:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512048#M1423640</guid>
      <dc:creator>former_member217544</dc:creator>
      <dc:date>2010-01-19T13:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512049#M1423641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this for logic&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data:lv_input type string. 
data:lv_index type i,
     lv_odd_pos type string,
     lv_even_pos type string,
     lv_result type string,
     lv_flag type char01.

lv_input = '123456789X'.

lv_index = strlen( lv_input ) - 2.
if lv_index  &amp;gt; 0.
do.
if lv_flag is initial.
lv_odd_pos = lv_odd_pos + lv_input+lv_index(1).
condense lv_odd_pos.
lv_flag = 'X'.
else.
lv_even_pos = lv_even_pos + lv_input+lv_index(1).
condense lv_even_pos.
clear lv_flag.
endif.
if lv_index = 0.
exit.
endif.
lv_index = lv_index - 1.
enddo.
else.
lv_odd_pos = lv_input+lv_index(1).
endif.

lv_result = ( ( lv_odd_pos * 3 ) + lv_even_pos ) ) MOD 10.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Keshav.T on Jan 19, 2010 8:05 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 13:39:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512049#M1423641</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-01-19T13:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512050#M1423642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This appears to be a homework question rather than business related. If it is indeed business related, please let us know the business case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 14:50:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512050#M1423642</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T14:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512051#M1423643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might be a check algorithm logic, i have gone through such requirement for a bank key validation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 14:55:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512051#M1423643</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-01-19T14:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512052#M1423644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 15:22:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512052#M1423644</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T15:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: using mod in the calculation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512053#M1423645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: STR1(20) VALUE '810312301234X'.
DATA: STR2(20).
DATA: VAR1 TYPE I, VAR2 TYPE I, VAR3 TYPE I, VAR4 TYPE I.

STR2 = STR1.
SHIFT STR2 RIGHT DELETING TRAILING SPACE.
SHIFT STR2 RIGHT BY 1 PLACES. " suppress trailing 'X'.

WHILE STR2 NE SPACE.
  SHIFT STR2 RIGHT BY 2 PLACES CIRCULAR.
  IF STR2+1(1) CO '0123456789'.  "numeric ?
    ADD STR2+1(1) TO VAR1.
  ENDIF.
  IF STR2(1) CO '0123456789'. "numeric ?
    ADD STR2(1) TO VAR2.
  ENDIF.
  CLEAR STR2(2).
ENDWHILE.
VAR3 = 3 * VAR1 + VAR2.
VAR4 = VAR3 MOD 10.
WRITE: / VAR1, VAR2, VAR3, VAR4.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please note that in my system 4&lt;EM&gt;2&lt;/EM&gt;0&lt;EM&gt;2&lt;/EM&gt;3+1 = 12 and not 10.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jan 2010 11:22:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-mod-in-the-calculation/m-p/6512053#M1423645</guid>
      <dc:creator>former_member194797</dc:creator>
      <dc:date>2010-01-20T11:22:58Z</dc:date>
    </item>
  </channel>
</rss>

