Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Generate random XSTRING

oliver_am
Active Participant
0 Likes
2,106

Hi,
I need to generate a random xstring with lenght 32.

Completely random, not using FM like CMS_API_GENERAL_GUID_CREATE that generate data like this, "sequential":

BB5242AF6F291EE99FC0B89A99310BB6
BB5242AF6F291EE99FC0B901667F0BB6
BB5242AF6F291EE99FC0C7483C194BDF

Any idea how to do it?

Thanks

5 REPLIES 5
Read only

matt
Active Contributor
0 Likes
1,770

Use one of the documented techniques for generating a random number in ABAP and then convert it to hex?

Read only

oliver_am
Active Participant
0 Likes
1,770

but how to ensure it will have a lenght of 32 ?

Read only

matt
Active Contributor
0 Likes
1,770

Generate a random integer between 0 and 15, convert to hex, 32 times should do it.

Read only

oliver_am
Active Participant
0 Likes
1,770

A solution could be generate random 0 to F and concatenate 32 times...

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
1,770
Two important things to note:
  1. Length of x + xstring (byte-like data types) is usually measured by bytes. You are probably mentioning its separate characters representation length.
  2. GUID_CREATE (called in your FM, BTW replaced by UUID - cl_system_uuid) is generating "globally unique ID". You will never get two same numbers. But by generating random XSTRING you might get same number multiple times.
-- Tomas --