I couldn't agree more with this underutilized ability in RBase. Let Razaak devote precious resources to the big picture and let the niggling small things go for a while and anything you can't dream up in a stored procedure, you can get from a VBScript (no kidding).
----- Original Message ----- From: "A. Razzak Memon" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, November 21, 2001 9:06 AM Subject: From The Edge: Add Your Own Functions to R:BASE > > November 21, 2001 > > ==================================================================== > From the Edge: Add Your Own Functions to R:BASE > Section: Stored Procedures and Triggers > Chapter: Running R:BASE Your Way! > Platform: R:BASE 2000 (ver 6.5++) for DOS/Windows > Build: 1.842xRT03 and Higher > ==================================================================== > > With the enhancements and major bug-fixes in the recent versions > of R:BASE 2000 (version 6.5) and higher, sometimes you wonder > what you could do to take advantage of powerful features, such as > creating your own functions using Stored Procedures and Triggers. > > Well, here is just a simple example to show you how you can use > the POWER of R:BASE Features to create your own function. > > Instead of bugging R:Team to include small functions like how to > find the Integer Week from any given date, you could create your > own function. > > The following example shows how to create a Stored Procedure to > make this work, and how you can effectively "Add Your Own Functions" > to R:BASE. > > Put the following in a file called IWK.PRO > > *(IWK.PRO - Stored Procedure to find Integer Week) > -- Date in question is in the parameter p1 > > -- Extract the Current Year > SET VAR vYear INTEGER = (IYR4(.p1)) > > -- Create the date of January 1 for this year > SET VAR vJan01 DATE = (RDATE(1,1,.vYear)) > > -- Get the day of the week for January 1 > SET VAR vDwk INTEGER = (IDWK(.vJan01)) > > -- Compute the number of days between January 1 and our date > SET VAR vDiff INTEGER = (.p1 - .vJan01) > > -- Adjust this difference to compensate for the day of the > -- week for January 1 > SET VAR vDiff = (.vDiff - .vDwk + 1) > > -- Now compute the week for our date > SET VAR vIWK INTEGER = ((.vdiff/7) + 1) > CLEAR VAR vYear, vJan01, vDwk, vDiff > RETURN .vIWK > > At the R> prompt enter the following command to store this > procedure in the database: > > PUT IWK.PRO AS IWK p1 DATE RETURN INTEGER > > To use this procedure you can do things like this: > > Example 01: > > SET VAR vWeek = (CALL IWK(.#DATE)) > vWeek will return the value of 47 (based on 11/21/2001) > STP_RETURN will also return the value of 47. > > Example 02: > > SET VAR vMyDate DATE = 04/19/2002 > SET VAR vWeek = (CALL IWK(.vMyDate)) > vWeek will return the value of 16 > STP_RETURN will also return the value of 16 > > Additional Notes: > > The STP_RETURN is a system variable that contain the value > returned by a Stored Procedure. This return value is set by > using the RETURN command. The STP_RETURN variable will be > whatever type is needed by the RETURN statement within the > Stored Procedure. > > Enjoy the Power and Flexibility of R:BASE 2000 (ver 6.5)! > > --- > > Download PDF version of this article at: > > http://www.rbase.com/FromTheEdge/AddYourOwnFunctions.pdf > > Send your constructive comments to: mailto:[EMAIL PROTECTED] > > Very Best Regards, > > Razzak. > > ===================================-============================ > Official R:BASE List Server: mailto:[EMAIL PROTECTED] > RBTI Events/Training: http://www.rbase2000.com/events > R:DCC Members: http://www.rbase2000.com/rdcc > ================================================================ > R:BASE, Oterro & R:Tango are registered trademarks of RBTI. > ==================================-============================= > >
