Generate random GUID
Solution 1
Are you absolutely sure the created GUID
is always the same? Because this shouldn't be happening. Note that the difference between them can be just one character when you generate them inside a fast loop.
Solution 2
First of all you are using a function module that is obsolete. The comment at the beginning of the source code states that.
*"----------------------------------------------------------------------
* NOW this function has been replaced, see note 935047 "BINK215094
* 28.6.2006 The function module has been switched to the new UUID methods
* which exist in the class cl_system_uuid
* - due to compatibility reasons we catch the exceptions
* - sy-subrc not touched manually
* (sy-subrc was set in case of an error when calling the former
* 'RFCControl' kernel-call, but it wasn't evaluated and finally
* overwritten when leaving this function)
*"----------------------------------------------------------------------
Please use class CL_SYSTEM_UUID
and the following methods:
IF_SYSTEM_UUID_STATIC~CREATE_UUID_X16
IF_SYSTEM_UUID_STATIC~CREATE_UUID_C22
IF_SYSTEM_UUID_STATIC~CREATE_UUID_C26
IF_SYSTEM_UUID_STATIC~CREATE_UUID_C32
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I want to generate a random
UUID
like inJava
withUUID.randomUUID()
.I came up with the function
GUID_GENERATE
and used it like thisDO 5 TIMES. CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_16 = ev_guid_16 ev_guid_22 = ev_guid_22 ev_guid_32 = ev_guid_32. WRITE: /, ev_guid_16, ev_guid_22, ev_guid_32. ENDDO.
The result of this program is always the same
GUID
. I need a new random one at every request.I want to use it as a primary key in database table. This key will be transmitted via a Web Service to a Java application and user there as identifier, too.
Do you have any ideas how I can generate random
UUID/GUID
inABAP
? -
Admin over 12 yearsIt was one single character... Stupid! Thank you for that hint!
-
Admin over 12 yearsThanks for the hint. I will try them and report if they work. If so I guess you earned the green arrow :-)