This is a test message to test the length of the message box.
Login

ABAP Obsolete - Create GUID

How do you create a unique identification (ID) in the system? You probably know the answer, but is it still up to date?

Advertising

In most help sites on the Internet or in forums, you will always stumble upon the use of a function module. If you've been following our series on New ABAP, you already know that the use of function module should now be reduced to a minimum. Not because function modules are obsolete, but rather should be used for other purposes.

 

What is it?

GUID means "globally unique identifiers", so it is a unique key in the system that can not happen twice. This key is generated from various information from the system, the time and random numbers, comparable to a hash in other languages/systems.

A number can be generated in three output formats:

  • 16-digit type x (42D85ED56C0A1EE9A5CA741861FC924B)
  • 32-digit type c (42D85ED56C0A1EE9A5CA741861FC924B)
  • 22-digit type c (GjXUrMmA7kcbodGOOVoIIm)

The first two formats are the same in the output, but differ by their type in which they are stored.

 

Function module

When you call the function module GUID_CREATE, you get all three GUIDs returned with one call. Via the Write output, you can view the values directly.


DATA:
  ld_guid_16 TYPE guid_16,
  ld_guid_22 TYPE guid_22,
  ld_guid_32 TYPE guid_32.

CALL FUNCTION 'GUID_CREATE'
  IMPORTING
    ev_guid_16 = ld_guid_16
    ev_guid_22 = ld_guid_22
    ev_guid_32 = ld_guid_32.

WRITE: / ld_guid_16, ', ', ld_guid_22, ', ', ld_guid_32

 

The use of the function module has already been marked as obsolete, and the comments contain the replacement class for generating the IDs.

 

Class

The replacement to the function module is the class CL_SYSTEM_UUID, with which you can also generate all IDs. SAP provides a separate method for each data type at this point. Of course, the advantage of using it, is the inline declaration in the program, which makes the code clearer and cleaner.


DATA(ld_new_16) = cl_system_uuid=>create_uuid_x16_static( ).
DATA(ld_new_22) = cl_system_uuid=>create_uuid_c22_static( ).
DATA(ld_new_32) = cl_system_uuid=>create_uuid_c32_static( ).

WRITE: / ld_new_16, ', ', ld_new_22, ', ', ld_new_32.

 

In addition to the use of static methods, instance methods are also provided that can be called after the object has been created. For these methods, no interface aliases are provided in the class, which slightly lengthens the spelling.


DATA(ld_new_16x) = NEW cl_system_uuid( )->if_system_uuid~create_uuid_x16( ).
DATA(ld_new_22x) = NEW cl_system_uuid( )->if_system_uuid~create_uuid_c22( ).
DATA(ld_new_32x) = NEW cl_system_uuid( )->if_system_uuid~create_uuid_c32( ).

WRITE: / ld_new_16x, ', ', ld_new_22x, ', ', ld_new_32x.

Conclusion

The creation of unique IDs has changed a bit, but should not be a problem for you. With the methods you are definitely a bit more flexible, especially when it comes to the chaining of functions. If this is not new to you, then just to refresh your knowledge.

 

Source:
SAP Answers


Included topics:
ObsoleteGUIDUnique ID
Comments (0)
Advertising

ABAP - Naming conventions

Category - ABAP

How important is it nowadays to adhere to naming conventions or even to use naming conventions in the modern ABAP environment? We want to look at that in this article.

04/09/2021

ABAP - Use INSERT

Category - ABAP

APPEND already has a long history in ABAP, but this will play less and less of a role in the future. We'll show you why.

12/11/2020

ABAP Obsolete - Assignment and calculation

Category - ABAP

How does it actually work with the assignments and the calculation in ABAP? Here you will find out the current language constructs and what you should avoid.

06/26/2020

ABAP Obsolete - Ranges and Headers

Category - ABAP

Generate a decent range for an interface? Tables with or without header lines? We show you what is still possible and what you should rather be.

06/12/2020

ABAP Obsolete - DESCRIBE

Category - ABAP

Again we have for you a most used ABAP term for which there is already a new alternative, this time not just one alternative.

11/15/2019