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.
Joined: 21 Nov 2009 Posts: 58 Location: California
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.
DISPLAY, WRITE, and PRINT all format *TIMESTMP as hex because it is defined as Binary. There is no need for you to REDEFINE, etc.
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.
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.