ABAP生成随机UUID / GUID

时间:2011-10-25 10:04:26

标签: primary-key guid abap

我希望在UUID中使用Java生成随机UUID.randomUUID()

我想出了函数GUID_GENERATE并像这样使用它

    DO 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.

此计划的结果始终相同GUID。每次请求我都需要一个新的随机的。

我想将它用作数据库表中的主键。此密钥也将通过Web服务传输到Java应用程序,并将用户作为标识符传输。

您是否有任何想法如何在UUID/GUID中生成随机ABAP

2 个答案:

答案 0 :(得分:9)

您是否绝对确定创建的GUID始终相同?因为这不应该发生。请注意,当您在快速循环中生成它们时,它们之间的差异可能只是一个字符。

答案 1 :(得分:8)

首先,您使用的是已过时的功能模块。源代码开头的注释说明了这一点。

*"----------------------------------------------------------------------
* 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)
*"----------------------------------------------------------------------

请使用课程CL_SYSTEM_UUID和以下方法:

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