cancel
Showing results for 
Search instead for 
Did you mean: 

generating unique no in webdynpro

Former Member
0 Kudos

hi experts,

according to our requirement we have to generate a unique acknowledgement number for an online application form. It purpose is simlar to an online exams form where we get the acknowledgement number to trace the status of our form once we submit it

we are building application in SAP EP (webdynpro)

with warm regards

vijai

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Vijay,

one more easy way is to use, <b>Math.random()</b> function,

Suppose you want to generate a unique 5 digit number,

int uniqueCode = (int) (Math.random() * 90000 + 10000);

hope it helps!!!

Regards

Deepak

Former Member
0 Kudos

hi deepak and denis

thank u for reply, can u send me few coding sample how we can implement this issues in webdynpro since we are using webdynpro persistence

thank you,

warm regards,

Vijai

Former Member
0 Kudos

Hai Vijay.

Wherever you required to generate Unique Id just call the method getUniqueId

Place this codee under

@@begin others

@@end


public String getUniqueId() {
		try {
	 SecureRandom objSecureRandom = SecureRandom.getInstance("SHA1PRNG");
	 String randomNumber = new Integer( objSecureRandom.nextInt() ).toString();
	 MessageDigest objMessageDigest = MessageDigest.getInstance("SHA-1");
	 byte[] result =  objMessageDigest.digest( randomNumber.getBytes() );
	 return  encodeHexaDecimal(result);
   }
   catch ( NoSuchAlgorithmException ex ) {
	 System.err.println(ex);
	 return null;
   }
		
		}
	
	private String encodeHexaDecimal( byte[] aInput){
	   StringBuffer buffer = new StringBuffer();
	   char[] digits = {'0', '1', '2', '3', '4','5','6','7','8','9','a','b','c','d','e','f'};
	   for ( int idx = 0; idx < aInput.length; ++idx) {
		 byte b = aInput[idx];
		 buffer.append( digits[ (b&0xf0) >> 4 ] );
		 buffer.append( digits[ b&0x0f] );
	   }
	   return buffer.toString();
	 }

Regards,

Naga

Former Member
0 Kudos

I would avoid Deepak's & Naga's solution as they are based on random number generation... the output of which are pseudo-random, but not at all guaranteed to be unique.

Denis' suggestion seems more appropriate here - UIDs & VMIDs were designed to be unique, not just random. I think that is what you are looking for.

Former Member
0 Kudos

Vijay,

Make use of Java persistence, create storage for a number eg. 100,000 (Assume this as the start number), fetch that number every time application is submitted, increment it by one and assign it as the acknowledgement number. Also update the database back with the new value.

I think this will solve your problem,

So whenever user submits the application, will get the new number (incremented) as the acknowledgment number.

Regards

Deepak

Former Member
0 Kudos

There are pair of little known classes called java.rmi.server.UID and java.rmi.dgc.VMID.

The UID class can generate identifiers that are unique over time within a JVM. The VMID class is even cooler - it provides uniqueness across ALL JVM's.

For the detail heads, UID consists of a unique number based on a hashcode, system time and a counter, and a VMID contains a UID and adds a SHA hash based on IP address.