View previous topic :: View next topic
|
Author |
Message |
Bob Steinkraus
New User
Joined: 09 Aug 2016 Posts: 3 Location: USA
|
|
|
|
Good morning (where I am) -
I am a Natural/ADABAS developer. My task is to generate a 4-digit random number to use in a superdescriptor (along with other fields). So -
- First off, is there any way to generate a random number in Natural? I don't have access to the SYSEXP library, and I looked at the SAG website and didn't find anything.
- So I decided to try to generate my own random number. My thought was to use the *TIMESTMP system variable, and try to get the random number from there.
The *TIMESTMP is a binary 8 field. I have puzzled and puzzled, using edit masks and redefines and Heaven only knows what else. I can get the *TIMESTMP to display as Hex by Redefining the B8 as N8 and using (EM=HHHHHHHH) but that doesn't get me any further. I tried using VAL to get the numeric value, but that didn't work either.
Does anyone know of a clever and/or elegant way to convert the B8 to an N8 (or probably, a larger field) so I can pick out the most random part? I am not allowed to write any COBOL or Assembler user exits or anything like that.
Any advice gratefully accepted.
Regards,
Bob Steinkraus |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
Back to top |
|
|
Bob Steinkraus
New User
Joined: 09 Aug 2016 Posts: 3 Location: USA
|
|
|
|
Thanks, I will look at the code samples.
I am running on the mainframe, if that matters.
Regards,
Bob Steinkraus |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Does ADABAS have any function to get RANDOM value generated like DB2? or you can see if the sequence number can be generated that is also unique instead of writing algorithm freshly. |
|
Back to top |
|
|
Bob Steinkraus
New User
Joined: 09 Aug 2016 Posts: 3 Location: USA
|
|
|
|
In theory, there is a RAND function, but I can't find how to work it on the mainframe.
Regards,
Bob Steinkraus |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
If Ralph zbrog drops by, it might be worth calling his attention to this thread. |
|
Back to top |
|
|
Ralph Zbrog
New User
Joined: 21 Nov 2009 Posts: 58 Location: California
|
|
|
|
Quote: |
is there any way to generate a random number in Natural |
There is no built-in function, but sample Natural code has been posted/discussed on the SAG-L listserv, so do some research there. Years ago Jim Wisdom had an excellent routine on his Natural Conference website, but that's gone now, and I couldn't find other sites that used to have it cross-posted.
The RAND function is not part of Natural, but is available from SAG's Code Samples site: techcommunity.softwareag.com/ecosystem/communities/public/adanat/products/natural/codesamples.
Quote: |
get the *TIMESTMP to display as Hex |
DISPLAY, WRITE, and PRINT all format *TIMESTMP as hex because it is defined as Binary. There is no need for you to REDEFINE, etc.
Quote: |
I don't have access to the SYSEXP library |
All developers should have access to SYSEXT in a Development environment, but some Natural administrators fear that could result in the end of the world. Once you have experience with the functions there, you can make a case for having a specific module made available in UAT & Production.
If your NatAdmin is stubborn, get a copy of Natural Community Edition and install it on Windows. Many of the API modules (i.e. SYSEXT) are common to mainframe. It's a great way to learn the API with no negative impact on the mainframe environment.
Quote: |
Does anyone know of a clever and/or elegant way to convert the B8 to an N8 |
There are several modules in SYSEXT which deal with converstion from/to the various time formats, including *TIMESTMP. |
|
Back to top |
|
|
|