<?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: Random number generation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401119#M1546894</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are several different classes or functions that can be used to generate random numbers, which you can find in the help files or by searching the browsers.  You're never guaranteed uniqueness though, even when using GUIDs.  But I agree with Suhas - it makes no sense at all to require that.  I can't see any security scenario where the delivery number has to be unpredicatable.  If you need a unique identifier for a delivery for some security purpose, I would use an additional field.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Oct 2010 13:58:09 GMT</pubDate>
    <dc:creator>brad_bohn</dc:creator>
    <dc:date>2010-10-11T13:58:09Z</dc:date>
    <item>
      <title>Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401115#M1546890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello &lt;/P&gt;&lt;P&gt;I want to generate random number in SAP. we use this random number as Outbound Delivery number i.e. LIKP-VBELN. We are not generating sequential number as the requirement is such that a person should not be able to predict the next delivery number for security purpose.&lt;/P&gt;&lt;P&gt;I thought of using fm QF05_RANDOM_INTEGER. It generates random number. But I am not sure if this FM will repeat the number as this can be used globally by any user. Kindly advice If I should use fm QF05_RANDOM_INTEGER.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 12:55:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401115#M1546890</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-11T12:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401116#M1546891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; I want to generate random number in SAP. we use this random number as Outbound Delivery number i.e. LIKP-VBELN. We are not generating sequential number as the requirement is such that a person should not be able to predict the next delivery number for security purpose.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if the number is going to be assigned to some document e.g., OB Delivery as you have mentioned, then i think we should respect the number range defined for the particular document.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 13:06:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401116#M1546891</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2010-10-11T13:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401117#M1546892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Suhas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for ur quick reply. But here the business requirement is that delivery number should be a random number. And using number range we get sequential number. Thus I am thinking of using Random Number generation logic. We would update this table in LIKP-VBELN in enhancement spot.&lt;/P&gt;&lt;P&gt;Do you know any other method to get random number for OB delivery.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 13:34:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401117#M1546892</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-11T13:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401118#M1546893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; We would update this table in LIKP-VBELN in enhancement spot.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope you are aware that the delivery number is also stored in several other database tables....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And regarding the requirement: i don't think i have ever come across such a weird one. Who cares what the delivery number is or will be? As long as unauthorized persons cannot enter your system i don;t see any reason why the next number should not be possible to guess.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 13:48:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401118#M1546893</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-11T13:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401119#M1546894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are several different classes or functions that can be used to generate random numbers, which you can find in the help files or by searching the browsers.  You're never guaranteed uniqueness though, even when using GUIDs.  But I agree with Suhas - it makes no sense at all to require that.  I can't see any security scenario where the delivery number has to be unpredicatable.  If you need a unique identifier for a delivery for some security purpose, I would use an additional field.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 13:58:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401119#M1546894</guid>
      <dc:creator>brad_bohn</dc:creator>
      <dc:date>2010-10-11T13:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401120#M1546895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look to the class&lt;/P&gt;&lt;P&gt;CL_ABAP_RANDOM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ivan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 15:55:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401120#M1546895</guid>
      <dc:creator>_IvanFemia_</dc:creator>
      <dc:date>2010-10-11T15:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401121#M1546896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This will be really difficult to do. In addition to generating an random document number (easy), you also have to check that has not been used before. To do this you will have to read the database after generating the number and if it is already there, generate another. Keep doing this until you have a unique document number. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This won't take long at the start, but as the range fills up, it will become a performance problem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 16:04:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401121#M1546896</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-11T16:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401122#M1546897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check the code snippet designed as per your requirement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: lcl_random TYPE REF TO cl_abap_random_int,
      v_from TYPE nrfrom,
      v_to TYPE nrto,
      v_min TYPE i,
      v_max TYPE i,
      v_random TYPE i.

* Get the Number Range details for PERNR
SELECT fromnumber tonumber UP TO 1 ROWS
  FROM nriv
  INTO (v_from, v_to)
  WHERE object = 'RP_PREL'
  AND nrrangenr = '02'.
ENDSELECT.

CHECK sy-subrc = 0.
MOVE: v_from TO v_min,
      v_to TO v_max.

* Get the Random Number generator class instance
TRY.
    lcl_random = cl_abap_random_int=&amp;gt;create( min = v_min
                                             max = v_max ).
  CATCH cx_abap_random.
ENDTRY.

DO.
*   Get the Random Number:
  v_random = lcl_random-&amp;gt;get_next( ).

*   Check if the number is already used up
  SELECT COUNT( * ) FROM pa0003
    WHERE pernr = v_random.
  IF sy-dbcnt = 0.
    EXIT. "If no PERNR found, then use the number
  ELSE.
    CLEAR v_random.
  ENDIF.
ENDDO.

WRITE: / 'Random Personnel Number Generated:',
      40 v_random NO-GROUPING.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you see the DO ... ENDDO block will be the one causing the pain &lt;SPAN __jive_emoticon_name="sad"&gt;&lt;/SPAN&gt; As the Number Range gets filled the number of iterations will also increase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway hope this helps you a lil'bit &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 17:31:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/random-number-generation/m-p/7401122#M1546897</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2010-10-11T17:31:11Z</dc:date>
    </item>
  </channel>
</rss>

