生成随机GUID



我想用UUID.randomUUID()生成一个像Java一样随机的UUID

我提出了函数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应用程序和用户作为标识符。

你有什么想法我可以在ABAP生成随机UUID/GUID吗?

首先,您使用的是过时的功能模块。源代码开头的注释指出。

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

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

相关内容

  • 没有找到相关文章

最新更新