Re: [U2] Custom Functions
In message [EMAIL PROTECTED], [EMAIL PROTECTED] writes When I said 'hack' I meant the ugly code that I had to create to make the trick work--the idea of having to put a dummy parameter into the function call in the basic program in order to make it compatable with the subr call in the i-type. Sorry for the confusion there. I don't get that ... As I say, I'm talking UV, but it's the SUBROUTINE that has the extra argument to make them compatible ... Your example had both the subroutine and the function with the same number of arguments. IME, using the function version hides the first argument making it have one less. So if you want to call a function from the SUBR() routine, I'd do FUNCTION MYHACK( A, B) code RETURN then call it with SUBR( *MYHACK, A, B) ;* Don't forget I'm using UV with that * :-) Cheers, Wol -- Anthony W. Youngman [EMAIL PROTECTED] 'Yings, yow graley yin! Suz ae rikt dheu,' said the blue man, taking the thimble. 'What *is* he?' said Magrat. 'They're gnomes,' said Nanny. The man lowered the thimble. 'Pictsies!' Carpe Jugulum, Terry Pratchett 1998 Visit the MaVerick web-site - http://www.maverick-dbms.org Open Source Pick --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
[EMAIL PROTECTED] writes When I said 'hack' I meant the ugly code that I had to create to make the trick work--the idea of having to put a dummy parameter into the function call in the basic program in order to make it compatible with the subr call in the i-type. Sorry for the confusion there. Ed, UniData doesn't advertise FUNCTIONs as being compatible with SUBR(). I don't see why it is any uglier to have to write a FUNCTION with two arguments in order to be able to invoke it via SUBR passing only one parameter than it is to code a SUBROUTINE that way. Anthony W. Youngman wrote: I don't get that ... As I say, I'm talking UV, but it's the SUBROUTINE that has the extra argument to make them compatible ... Your example had both the subroutine and the function with the same number of arguments. IME, using the function version hides the first argument making it have one less. Wol, I will say this only once more. Current releases of UniData *DO NOT* implement FUNCTION as a SUBROUTINE with an extra, hidden argument. UniVerse does. In UniVerse a FUNCTION declared with two parameters *IS* a SUBROUTINE with three. On UniData a FUNCTION declared with two parameters is exactly that - a FUNCTION which expects two parameters. Cheers, Ken --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Ken: Ditto! :-) One might add faster and more stable triggers and built-in input timing. Bill -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ken Wallis Sent: Friday, June 24, 2005 6:04 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions [snipped] Anyway, I really don't want to go near the 'why buy UD instead of UV' discussion...[snipped]... The only thing I will say before moving quickly along is 'indexes'. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] Custom Functions
I think it's a universe/unidata difference. I get the segmentation fault running unidata in ecl type U as well. Here's some interesting info and an ugly hack--in unidata. It seems completely wrong to me (UV in Prime flavour) Apparently, the keywords SUBROUTINE and FUNCTION are interchangable as far as BASIC is concerned, so create a subroutine SUBROUTINE MYHACK(A,B) Actually, I don't think they are ... at least npt the way you imply. A=B*2 ;* note that we both assign the result to a parameter AND return the result RETURN A This is weird ... Then you can call it as a function with PROGRAM HACKTEST DEFFUN MYHACK(A,B) CRT MYHACK('',2);* --- there's the hack. You need that placeholder parameter This is why it blows up ... Or use it as a subroutine: PROGRAM HACK2 CALL MYHACK(A,2) CRT A Or from a virtual attribute: I SUBR('MYHACK',EXTRACT(@RECORD,1,0,0)) Let's say we want a function called MYHACK. The following two declarations are identical... SUBROUTINE MYHACK( RESULT, A, B) ... RESULT = whatever RETURN or FUNCTION MYHACK( A, B) ... RETURN (whatever) If you want to access the first version from a calling program by doing DEFFUN MYHACK( A, B) ANSWER = MYHACK( 1, 2) that'll work. As will calling the latter version with CALL MYHACK( ANSWER, 1, 2) So you can mix and match between treating it as a subroutine and as a function, but the function version always has one less argument - the first one is missing as it is an implied result. Someone said don't risk this because it may change in future. As far as I'm aware, it WON'T change, because the SUBR call relies on this behaviour. Look up SUBR in the docu, and you'll see that anything it calls MUST be this sort of function, after all, when you call a subroutine using SUBR, you can't pass in the first argument ... Cheers, Wol --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Well, the idea was to produce something that could be called as a function from basic, because the function calling syntax is cool and convenient in a lot of cases, but that could also be used in a I-type. For things to work in SUBR in an i-type, you need that extra parameter. Of course you could maintain two versions--a simple function, and then a subroutine wrapper around the function to use in the i-type. I was trying to avoid that. And, if you're using universe, you can just use the function in the i-type anyway. The more I see of it, the more unidata feels like universe's really poor relative. Which begs the question--given a choice, why would one pick unidata over universe? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 6:04 PM To: 'u2-users@listserver.u2ug.org' Subject: RE: [U2] Custom Functions Interesting. But you NEED that extra parameter? I tried DEFFUNing a SUBROUTINE that has only 1 parameters and could not get it to work. If your FUNCTION sets any of the parameters, you can CALL It from UniBasic -- and you don't have to DEFFUN it. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 5:52 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions I think it's a universe/unidata difference. I get the segmentation fault running unidata in ecl type U as well. Here's some interesting info and an ugly hack--in unidata. Apparently, the keywords SUBROUTINE and FUNCTION are interchangable as far as BASIC is concerned, so create a subroutine SUBROUTINE MYHACK(A,B) A=B*2 ;* note that we both assign the result to a parameter AND return the result RETURN A Then you can call it as a function with PROGRAM HACKTEST DEFFUN MYHACK(A,B) CRT MYHACK('',2);* --- there's the hack. You need that placeholder parameter Or use it as a subroutine: PROGRAM HACK2 CALL MYHACK(A,2) CRT A Or from a virtual attribute: I SUBR('MYHACK',EXTRACT(@RECORD,1,0,0)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 4:09 PM To: 'u2-users@listserver.u2ug.org' Subject: RE: [U2] Custom Functions I've never seen this asterisk thing on the front of a cataloged program. I've never had to do that in UniData. I can call a SUBROUTINE fine from a Virtual attribute no problem - and not asterisk. Could it have something to do with the fact that we run BASICTYPE 'p' and ECLTYPE 'p'? -Original Message- From: gerry-u2ug [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:41 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 10:46 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org
RE: [U2] Custom Functions
Something I did in some subroutines which makes them more of a multi tasker (I-descriptors) and flexible, is to pass file variables as parameters - when you can. So, the subroutine would look something like; snip SUBROUTINE GET.NEXT.IJKEY(FILE.CN, ERR, F.STAT, IJKEY) $INCLUDE HEADERS STD.EQUATES $INCLUDE HEADERS ERRCODES.EQUATES $INCLUDE HEADERS IM.CTRL.EQUATES $INCLUDE SYSCOM FILEINFO.INS.IBAS * *THE FILE(S) MAY OR MAY NOT BE OPENED * * OPENED.CN = FALSE NEED.TO.OPEN = FILEINFO(FILE.CN,0) IF NEED.TO.OPEN = 0 THEN OPEN '','CN' TO FILE.CN ELSE ERR = ERR$CODE.OPENERR F.STAT = STATUS() GO STOP.RUN END OPENED.CN = TRUE END /snip We are using Universe. You never know what need you might have in the future and this can make things much easier. Actually, I thought 2 dynamic array params (passed and returned) and a headers file as pointers is probably more ideal. Then you can do any of this sort of thing on the fly and you wouldn't have too much code to change/recompile when needs arise. Anthony -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wendy Smoak Sent: Thursday, June 23, 2005 12:18 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Custom Functions From: Ray Wurlod [EMAIL PROTECTED] Try using the SUBR() function, as I mentioned in another post. Ouch. Granted my function opens a file and [currently, for debug] prints to the screen, but attempting to call it with SUBR from an I-Descriptor caused... '25945 Bus error' and left the session unresponsive. Leaving aside the I-Descriptor issue for a moment... Is there a way for it a function to assume that the last file opened is the one I want to use? I thought there might be an @FILE or something, the way there is @ID and you can have a 'default' file for READ. http://www.pickwiki.com/cgi-bin/wiki.pl?TreeTraversal I thought of opening the file in the calling program, and passing a file handle instead of the filename. But I need this to work when called [indirectly] from UOJ also, and historically I've seen 'Error 30102' if I attempt to pass file handles around in any code called from UOJ. Advice on how to improve this would be gratefully accepted [see code in Wiki link above]. While the first one isn't TOO bad... there's a companion function that finds all of the children of a particular node, and it calls the first function to look back up the tree for any child that has multiple parents. In that case I open the same file over, and over and over. Thanks, Wendy Smoak --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Anthony Dzikiewicz Sent: Friday, June 24, 2005 9:40 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Something I did in some subroutines which makes them more of a multi tasker (I-descriptors) and flexible, is to pass file variables as parameters - when you can. So, the subroutine would look something like; snip SUBROUTINE GET.NEXT.IJKEY(FILE.CN, ERR, F.STAT, IJKEY) $INCLUDE HEADERS STD.EQUATES $INCLUDE HEADERS ERRCODES.EQUATES $INCLUDE HEADERS IM.CTRL.EQUATES $INCLUDE SYSCOM FILEINFO.INS.IBAS * *THE FILE(S) MAY OR MAY NOT BE OPENED * * OPENED.CN = FALSE NEED.TO.OPEN = FILEINFO(FILE.CN,0) IF NEED.TO.OPEN = 0 THEN OPEN '','CN' TO FILE.CN ELSE ERR = ERR$CODE.OPENERR F.STAT = STATUS() GO STOP.RUN END OPENED.CN = TRUE END /snip We are using Universe. You never know what need you might have in the future and this can make things much easier. Actually, I thought 2 dynamic array params (passed and returned) and a headers file as pointers is probably more ideal. Then you can do any of this sort of thing on the fly and you wouldn't have too much code to If you pass 3 dimensioned arrays would be ideal. 1 array for incoming variables (you can store an entire dynamic array inside one cell of a dimensioned array), 1 array for outgoing varibles, and 1 array for file headers since you store multiple fileheaders in a dimensioned array, but not in a dynamic array. George change/recompile when needs arise. Anthony --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions - UV or UD
One I can thing of, and I normally work on UV and prefer, is that you can debug programs which interact with file which have triggers on them. In UV this is not possible and is seen as an enhancement! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Saturday, 25 June 2005 1:46 a.m. To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Well, the idea was to produce something that could be called as a function from basic, because the function calling syntax is cool and convenient in a lot of cases, but that could also be used in a I-type. For things to work in SUBR in an i-type, you need that extra parameter. Of course you could maintain two versions--a simple function, and then a subroutine wrapper around the function to use in the i-type. I was trying to avoid that. And, if you're using universe, you can just use the function in the i-type anyway. The more I see of it, the more unidata feels like universe's really poor relative. Which begs the question--given a choice, why would one pick unidata over universe? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 6:04 PM To: 'u2-users@listserver.u2ug.org' Subject: RE: [U2] Custom Functions Interesting. But you NEED that extra parameter? I tried DEFFUNing a SUBROUTINE that has only 1 parameters and could not get it to work. If your FUNCTION sets any of the parameters, you can CALL It from UniBasic -- and you don't have to DEFFUN it. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 5:52 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions I think it's a universe/unidata difference. I get the segmentation fault running unidata in ecl type U as well. Here's some interesting info and an ugly hack--in unidata. Apparently, the keywords SUBROUTINE and FUNCTION are interchangable as far as BASIC is concerned, so create a subroutine SUBROUTINE MYHACK(A,B) A=B*2 ;* note that we both assign the result to a parameter AND return the result RETURN A Then you can call it as a function with PROGRAM HACKTEST DEFFUN MYHACK(A,B) CRT MYHACK('',2);* --- there's the hack. You need that placeholder parameter Or use it as a subroutine: PROGRAM HACK2 CALL MYHACK(A,2) CRT A Or from a virtual attribute: I SUBR('MYHACK',EXTRACT(@RECORD,1,0,0)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 4:09 PM To: 'u2-users@listserver.u2ug.org' Subject: RE: [U2] Custom Functions I've never seen this asterisk thing on the front of a cataloged program. I've never had to do that in UniData. I can call a SUBROUTINE fine from a Virtual attribute no problem - and not asterisk. Could it have something to do with the fact that we run BASICTYPE 'p' and ECLTYPE 'p'? -Original Message- From: gerry-u2ug [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:41 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 10:46 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's
RE: [U2] Custom Functions - UV or UD
That's a useful feature. Anyone else know of any? I've noticed that unidata is accomodating about letting you run subroutines as though they were programs, and calling programs as though they were subroutines. Is that an advantage or something scary? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of phil walker Sent: Friday, June 24, 2005 4:21 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions - UV or UD One I can thing of, and I normally work on UV and prefer, is that you can debug programs which interact with file which have triggers on them. In UV this is not possible and is seen as an enhancement! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Saturday, 25 June 2005 1:46 a.m. To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Well, the idea was to produce something that could be called as a function from basic, because the function calling syntax is cool and convenient in a lot of cases, but that could also be used in a I-type. For things to work in SUBR in an i-type, you need that extra parameter. Of course you could maintain two versions--a simple function, and then a subroutine wrapper around the function to use in the i-type. I was trying to avoid that. And, if you're using universe, you can just use the function in the i-type anyway. The more I see of it, the more unidata feels like universe's really poor relative. Which begs the question--given a choice, why would one pick unidata over universe? --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
When I said 'hack' I meant the ugly code that I had to create to make the trick work--the idea of having to put a dummy parameter into the function call in the basic program in order to make it compatable with the subr call in the i-type. Sorry for the confusion there. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ken Wallis Sent: Friday, June 24, 2005 9:04 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions [EMAIL PROTECTED] wrote So you can mix and match between treating it as a subroutine and as a function, but the function version always has one less argument - the first one is missing as it is an implied result. Someone said don't risk this because it may change in future. As far as I'm aware, it WON'T change, because the SUBR call relies on this behaviour. Look up SUBR in the docu, and you'll see that anything it calls MUST be this sort of function, after all, when you call a subroutine using SUBR, you can't pass in the first argument ... Wol, it was me that said don't assume this will always be how it works. I think you missed my point. I wasn't saying that the SUBR() interface from I-types might change - why should it? What I was saying is that you shouldn't assume that the only way to implement FUNCTION was as a SUBROUTINE with an extra hidden argument, and you shouldn't assume that the only way to implement RETURN X was to set that hidden argument to the value of X. It appears to me from Wendy and Ed's investigations that UniData has indeed made a change somewhere since 4.1 when I last looked at this in detail such that there is no hidden extra argument on a FUNCTION and that RETURN X actually puts X on the stack somewhere. I stand by my comment: the way FUNCTION is currently implemented on both UniVerse and UniData is undocumented and should not be relied upon. If you want a FUNCTION which can also be called as a SUBR then code for it - write a wrapper for one or the other. Separately, Ed seems to have decided that UniData not following this undocumented mode of operation is a deficiency in UniData. I don't see it that way, but he's entitled to his opinion. On further inspection, I'm not even sure that what he identifies as a hack really is. The only undocumented feature in his program is that he successfully does a DEFFUN for a SUBROUTINE and then invokes the FUNCTION. The UniData documentation for DEFFUN *never* mentions the possibility that a SUBROUTINE can be referenced. All it mentions is FUNCTION. The doco on FUNCTION never suggests that FUNCTIONs map to SUBROUTINEs with an extra hidden argument. Anyway, I really don't want to go near the 'why buy UD instead of UV' discussion. There used to be a heap of reasons, but a lot have been flattened out in the various mergers and acquisitions. Discussions on this list do very occasionally throw up something UV has which I think would have been nice in UD - SEEK and REVREMOVE are examples, but UD still has some nice things that UV doesn't - GETENV, DIR and PCPERFORM come to mind. The only thing I will say before moving quickly along is 'indexes'. Cheers, Ken --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wendy Smoak Sent: Wednesday, June 22, 2005 8:47 PM To: u2-users@listserver.u2ug.org Subject: [U2] Custom Functions --- snip --- We consider subroutines fairly expensive in terms of system resources, and tend to just use GOSUB within most programs. But coming from the Java/OO world, the global variables are *killing* me. And I'm partial to the nested parenthesis notation as well. I always thought that if you have a globally catalogued subroutine and use it like this: MY.SUB = '*MY.SUB' CALL @MY.SUB(parm1,parm2...) What happens under the hood, must be that the compiled subroutine is loaded into a variable, and that variable is either placed somewhere on the stack or another area, and the way a function works is the same way, just with another syntax.. ?? that would take the exact same amount of clock cycles to reach the subroutine as a call to a function would A function is also 'just' a loaded subroutine, so in effect the runtime does a longjump to the routine.. Am i totally wrong on this ?? best regards from 'melted down' denmark Claus Derlien Frie Funktionfrer - faglig organisation og tvfrfaglig a-kasse - www.f-f.dk *** Denne email og alle filer vedlagt som bilag kan indeholde fortroligt materiale, der kun er beregnet for adressaten, og maa ikke udleveres eller kopieres til uvedkommende. Har De ved en fejltagelse modtaget denne email, bedes De venligst omgaaende meddele os dette pr. telefon : 6313 8550. Paa forhaand tak. *** This email and any files transmitted with it may contain confidential information intended for the addressee(s) only. The information is not to be surrendered or copied to unauthorised persons. If you have received this communication in error, please notify us immediately by telephone: +45 6313 8550. Thank you. *** --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] Custom Functions
From: Ray Wurlod [EMAIL PROTECTED] Try using the SUBR() function, as I mentioned in another post. Ouch. Granted my function opens a file and [currently, for debug] prints to the screen, but attempting to call it with SUBR from an I-Descriptor caused... '25945 Bus error' and left the session unresponsive. Leaving aside the I-Descriptor issue for a moment... Is there a way for it a function to assume that the last file opened is the one I want to use? I thought there might be an @FILE or something, the way there is @ID and you can have a 'default' file for READ. http://www.pickwiki.com/cgi-bin/wiki.pl?TreeTraversal I thought of opening the file in the calling program, and passing a file handle instead of the filename. But I need this to work when called [indirectly] from UOJ also, and historically I've seen 'Error 30102' if I attempt to pass file handles around in any code called from UOJ. Advice on how to improve this would be gratefully accepted [see code in Wiki link above]. While the first one isn't TOO bad... there's a companion function that finds all of the children of a particular node, and it calls the first function to look back up the tree for any child that has multiple parents. In that case I open the same file over, and over and over. Thanks, Wendy Smoak --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 10:46 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Wendy; I tend not to use a FUNCTION unless I really need it for the syntax. It helps me to remember that even when calling a function you can change any of the passed variables - not just the return variable (just like a subroutine). For some reason I didn't think a function could do that, I'm not sure if I saw that in the documentation or was just the way I thought it should work. In any case, I don't know how to give it a default file to use. If you call it from UniQuery you have the @ID and @RECORD variables to use but nothing really for a file. What I did - that made a HUGE difference - was to put the filevar into named common. Since the program could be called from multiple accounts I also put the path into common as well. E.g.: SUBROUTINE TESTSUB(RET_DATA, FILENAME, ID, FIELDNUM) COMMON /TESTSUB/ PATH, FILEVAR RET_DATA = '' IF UNASSIGNED(PATH) THEN PATH = 'Some path that will not exist on any system' IF PATH # @PATH THEN OPEN FILENAME TO FILEVAR THEN PATH = @PATH END ELSE RETURN END END READV RET_DATA FROM FILEVAR, ID, FIELDNUM ELSE RET_DATA = '' RETURN This will help if you call it from UniQuery or multiple times from another subroutine; I'm not sure how well it will work if you called it multiple times from UniObjects. Colin Alfke From Calgary, AB where I can't believe we've been flooded for a week -Original Message- From: Wendy Smoak From: Ray Wurlod [EMAIL PROTECTED] Try using the SUBR() function, as I mentioned in another post. Ouch. Granted my function opens a file and [currently, for debug] prints to the screen, but attempting to call it with SUBR from an I-Descriptor caused... '25945 Bus error' and left the session unresponsive. Leaving aside the I-Descriptor issue for a moment... Is there a way for it a function to assume that the last file opened is the one I want to use? I thought there might be an @FILE or something, the way there is @ID and you can have a 'default' file for READ. http://www.pickwiki.com/cgi-bin/wiki.pl?TreeTraversal I thought of opening the file in the calling program, and passing a file handle instead of the filename. But I need this to work when called [indirectly] from UOJ also, and historically I've seen 'Error 30102' if I attempt to pass file handles around in any code called from UOJ. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
I've never seen this asterisk thing on the front of a cataloged program. I've never had to do that in UniData. I can call a SUBROUTINE fine from a Virtual attribute no problem - and not asterisk. Could it have something to do with the fact that we run BASICTYPE 'p' and ECLTYPE 'p'? -Original Message- From: gerry-u2ug [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:41 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 10:46 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Ouch. Granted my function opens a file and [currently, for debug] prints to the screen, but attempting to call it with SUBR from an I-Descriptor caused... '25945 Bus error' and left the session unresponsive. I don't get the example as posted - seems like F.FILE doesn't get saved anywhere between calls. Shouldn't it be: FUNCTION A51.ULTIMATE.PARENT( ID, FILENAME, F.FILE, FIELD.NUM ) snip ** IF NOT(FILEINFO(F.FILE,0)) THEN CRT 'Opening file' OPEN FILENAME TO F.FILE ELSE RETURN -2 END ELSE CRT 'Using existing file handle' END Instead? Seems like your choices are passing around the file handle as a parameter, sticking it in named common or one of the @user variables. Ian --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
I think it's a universe/unidata difference. I get the segmentation fault running unidata in ecl type U as well. Here's some interesting info and an ugly hack--in unidata. Apparently, the keywords SUBROUTINE and FUNCTION are interchangable as far as BASIC is concerned, so create a subroutine SUBROUTINE MYHACK(A,B) A=B*2 ;* note that we both assign the result to a parameter AND return the result RETURN A Then you can call it as a function with PROGRAM HACKTEST DEFFUN MYHACK(A,B) CRT MYHACK('',2);* --- there's the hack. You need that placeholder parameter Or use it as a subroutine: PROGRAM HACK2 CALL MYHACK(A,2) CRT A Or from a virtual attribute: I SUBR('MYHACK',EXTRACT(@RECORD,1,0,0)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 4:09 PM To: 'u2-users@listserver.u2ug.org' Subject: RE: [U2] Custom Functions I've never seen this asterisk thing on the front of a cataloged program. I've never had to do that in UniData. I can call a SUBROUTINE fine from a Virtual attribute no problem - and not asterisk. Could it have something to do with the fact that we run BASICTYPE 'p' and ECLTYPE 'p'? -Original Message- From: gerry-u2ug [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:41 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 10:46 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Interesting. But you NEED that extra parameter? I tried DEFFUNing a SUBROUTINE that has only 1 parameters and could not get it to work. If your FUNCTION sets any of the parameters, you can CALL It from UniBasic -- and you don't have to DEFFUN it. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 5:52 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions I think it's a universe/unidata difference. I get the segmentation fault running unidata in ecl type U as well. Here's some interesting info and an ugly hack--in unidata. Apparently, the keywords SUBROUTINE and FUNCTION are interchangable as far as BASIC is concerned, so create a subroutine SUBROUTINE MYHACK(A,B) A=B*2 ;* note that we both assign the result to a parameter AND return the result RETURN A Then you can call it as a function with PROGRAM HACKTEST DEFFUN MYHACK(A,B) CRT MYHACK('',2);* --- there's the hack. You need that placeholder parameter Or use it as a subroutine: PROGRAM HACK2 CALL MYHACK(A,2) CRT A Or from a virtual attribute: I SUBR('MYHACK',EXTRACT(@RECORD,1,0,0)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 4:09 PM To: 'u2-users@listserver.u2ug.org' Subject: RE: [U2] Custom Functions I've never seen this asterisk thing on the front of a cataloged program. I've never had to do that in UniData. I can call a SUBROUTINE fine from a Virtual attribute no problem - and not asterisk. Could it have something to do with the fact that we run BASICTYPE 'p' and ECLTYPE 'p'? -Original Message- From: gerry-u2ug [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:41 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Burwell, Edward Sent: Thursday, June 23, 2005 10:46 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Here is a sample: MYFUNC looks like: 001 FUNCTION MYFUNC(ARG) 002 RETURN (ARG=Y) 003 END MYFUNC is globally cataloged DICT FILE TEST looks like: 001 V 002 SUBR(MYFUNC,Y) 003 004 005 1R 006 S when I LIST FILE TEST, I get a Segmentation fault(coredump) and it dumps me into Unix. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Thursday, June 23, 2005 1:22 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
gerry-u2ug wrote: globally catalogued as in CATALOG SUB.BP *MYFUNC ? so you should be using : SUBR(*MYFUNC,Y) we do this all the time in universe since at least v7 As others have mentioned, its a difference between UniData and UniVerse. On UniData you *CAN* use an asterisk before a SUBROUTINE name to identify it as globally cataloged, but there is no need to and no benefit gained from doing it. [EMAIL PROTECTED] wrote: Here's some interesting info and an ugly hack--in unidata. Apparently, the keywords SUBROUTINE and FUNCTION are interchangeable as far as BASIC is concerned, so create a subroutine SUBROUTINE MYHACK(A,B) A=B*2 ;* note that we both assign the result to a parameter AND return the result RETURN A Then you can call it as a function with PROGRAM HACKTEST DEFFUN MYHACK(A,B) CRT MYHACK('',2);* --- there's the hack. You need that placeholder parameter Or use it as a subroutine: PROGRAM HACK2 CALL MYHACK(A,2) CRT A Or from a virtual attribute: I SUBR('MYHACK',EXTRACT(@RECORD,1,0,0)) That's quite interesting Ed. Does it behave the same if you code MYHACK as 'FUNCTION MYHACK(A,B)'? Cheers, Ken --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
I could be wrong, but AFAIK a FUNCTION is just a SUBROUTINE with some syntax magic (the DEFFUN statement) that lets you reference it in an expression rather than using the CALL statement. A function call has the same overhead as a subroutine call. You can't put local functions inside of your program and get local variables that way (although you could do that on the old ADDS MENTOR systems. I wish universe had included that functionality) The return from the function can be multi-valued, and you can change the value of parameters just like in a subroutine call. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wendy Smoak Sent: Wednesday, June 22, 2005 2:47 PM To: u2-users@listserver.u2ug.org Subject: [U2] Custom Functions I was just looking at the documentation for FUNCTION after hearing a couple of people make reference to custom functions. How did we not know about this?! (Has this always been possible, or was it added recently?) We consider subroutines fairly expensive in terms of system resources, and tend to just use GOSUB within most programs. But coming from the Java/OO world, the global variables are *killing* me. And I'm partial to the nested parenthesis notation as well. Does anyone have any best practice advice or gotchas to impart? We have a need to find the Ultimate Parent in a tree of corporation/parent/subsidiary relationships. In particular, I might find a case where there is more than one Ultimate Parent and I need to signify an error. Do I return -1, or set @SYSTEM.RETURN.CODE to a positive number? Thanks, -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University, PA, IRM --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
In a function, you would RETURN(-1). In a subroutine, you would pass back a variable as one of the parameters. RESULT = '';MY.VAR='SOMETHING' CALL MY.SUB(RESULT, MY.VAR) IF RESULT = @TRUE .. Whatever . . SUBROUTINE MY.SUB(RESULT, MY.VAR) [EMAIL PROTECTED] IF MY.VAR = 'SOMETHING' THEN [EMAIL PROTECTED] RETURN END Im not positive about this (please check), but I always considered subroutines as being 'I-Type' capable and functions not. So if you create a subroutine, you can also use it as an 'I-Type' in a dictionary. If you create a function you cannot. This is the reason I have always used subroutines. We find them very handy in simple selects and reports as well as being able to be called in programs - a multi-tasker. As far as being expensive, I guess that is relative. For us it is not. Anthony -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wendy Smoak Sent: Wednesday, June 22, 2005 2:47 PM To: u2-users@listserver.u2ug.org Subject: [U2] Custom Functions I was just looking at the documentation for FUNCTION after hearing a couple of people make reference to custom functions. How did we not know about this?! (Has this always been possible, or was it added recently?) We consider subroutines fairly expensive in terms of system resources, and tend to just use GOSUB within most programs. But coming from the Java/OO world, the global variables are *killing* me. And I'm partial to the nested parenthesis notation as well. Does anyone have any best practice advice or gotchas to impart? We have a need to find the Ultimate Parent in a tree of corporation/parent/subsidiary relationships. In particular, I might find a case where there is more than one Ultimate Parent and I need to signify an error. Do I return -1, or set @SYSTEM.RETURN.CODE to a positive number? Thanks, -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University, PA, IRM --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
subroutine sub(rtn,a1,a2) function(a1,a2) for use within a basic program functions have to be predefined using deffun : deffun func(a1,a2) to call a globally catalog a function within a basic program use : deffun func(a1,a2) calling *func if call the function via subr() the predefine is not required. functions can be used in i-types the same as subroutines as long is they are catalogued subr(*sub,a1,a2) subr(*func,a1,a2) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Anthony Dzikiewicz Sent: Wednesday, June 22, 2005 04:05 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions In a function, you would RETURN(-1). In a subroutine, you would pass back a variable as one of the parameters. RESULT = '';MY.VAR='SOMETHING' CALL MY.SUB(RESULT, MY.VAR) IF RESULT = @TRUE .. Whatever . . SUBROUTINE MY.SUB(RESULT, MY.VAR) [EMAIL PROTECTED] IF MY.VAR = 'SOMETHING' THEN [EMAIL PROTECTED] RETURN END Im not positive about this (please check), but I always considered subroutines as being 'I-Type' capable and functions not. So if you create a subroutine, you can also use it as an 'I-Type' in a dictionary. If you create a function you cannot. This is the reason I have always used subroutines. We find them very handy in simple selects and reports as well as being able to be called in programs - a multi-tasker. As far as being expensive, I guess that is relative. For us it is not. Anthony -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wendy Smoak Sent: Wednesday, June 22, 2005 2:47 PM To: u2-users@listserver.u2ug.org Subject: [U2] Custom Functions I was just looking at the documentation for FUNCTION after hearing a couple of people make reference to custom functions. How did we not know about this?! (Has this always been possible, or was it added recently?) We consider subroutines fairly expensive in terms of system resources, and tend to just use GOSUB within most programs. But coming from the Java/OO world, the global variables are *killing* me. And I'm partial to the nested parenthesis notation as well. Does anyone have any best practice advice or gotchas to impart? We have a need to find the Ultimate Parent in a tree of corporation/parent/subsidiary relationships. In particular, I might find a case where there is more than one Ultimate Parent and I need to signify an error. Do I return -1, or set @SYSTEM.RETURN.CODE to a positive number? Thanks, -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University, PA, IRM --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] Custom Functions
From: Burwell, Edward [EMAIL PROTECTED] I use/write functions all the time. I love 'em. You can return ANYTHING you want from a single digit to an array. If you have some specific questions, ask away. Can you use them in I-Descriptors? Doesn't look like it from 'Using UniData' though I suppose you could write a subroutine that did nothing but call the function. -- Wendy Smoak --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Previous posters have pretty much covered the ground. UniVerse (and, I suspect but can't be certain about, UniData) functions are implemented as subroutines, with the first argument position on the stack reserved for the return value which is a DATUM. It can even be a file variable or subroutine variable! It follows that, while a subroutine can have 255 arguments, a function is only allowed 254. Don't go there! --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] Custom Functions
You can use functions in I-descriptors (via the SUBR function only) because the mechanism that reserves the first position on the stack for functions is exactly the same mechanism used by the SUBR() function. You can not use custom functions directly as functions in I-descriptors because you have no mechanism for declaring that the name of the function is a function name (that is, a DEFFUN declaration) in the query engine. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. -Original Message- From: Ray Wurlod [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 22, 2005 7:00 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Previous posters have pretty much covered the ground. UniVerse (and, I suspect but can't be certain about, UniData) functions are implemented as subroutines, with the first argument position on the stack reserved for the return value which is a DATUM. It can even be a file variable or subroutine variable! It follows that, while a subroutine can have 255 arguments, a function is only allowed 254. Don't go there! --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ __ This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on MCI's Managed Email Content Service, visit http://www.mci.com. __ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
From: Burwell, Edward [EMAIL PROTECTED] I use/write functions all the time. I love 'em. You can return ANYTHING you want from a single digit to an array. If you have some specific questions, ask away. Wendy Smoak wrote: Can you use them in I-Descriptors? Doesn't look like it from 'Using UniData' though I suppose you could write a subroutine that did nothing but call the function. Wendy, you can, but it isn't documented and it happens 'by accident' because functions are internally implemented as subroutines with an extra hidden argument at the front for the return value, just like virtual field/I-Type SUBRs need to be. Personally, I prefer not to rely on this always being the way FUNCTIONs are implemented, and I'd do what you suggest and implement a trivial wrapper SUBROUTINE to invoke the FUNCTION, but as currently implemented that is not required. Earlier in the thread you mentioned that 'we' consider SUBROUTINEs to be computationally expensive and prefer GOSUB. I suspect that 'we' includes folk who were brought up on Prime's and various other run machine implementations. I remember I first came across MV databases with INFORMATION on 50 Series at a software house that was just starting to look at Universe (PI EXL). I couldn't understand why so much of their code was rammed into big ugly programs and subroutines that started with a huge ON GOSUB and seemed to contain stuff that was completely unrelated. It turned out that INFORMATION had a 64K object code limit, and that CALLs had always been exceedingly slow because they went through the standard 50 Series 'snap' mechanism for locating routines which was always slow the first time you referenced something and could only be overcome by caching the subroutine name in a variable and calling it indirectly on subsequent attempts: X=MYSUB; CALL @X So experience with 50 Series had taught them to use as few subroutines as possible, and in each one, to pack as much code as would fit in 64K of object. Little did it matter to them that once they started to deliver their software largely on UniVerse and UniData they lost their 64K limit and the CALL 'snap' mechanism disappeared. At one point I actually did some benchmarking with their code to demonstrate that some of their GOSUBs to labels at the other end of their 64K object code took longer than an equivalent CALL to a small SUBROUTINE which did the same thing once that routine had been loaded into memory by sbcs. this was an extreme though - GOSUB is usually quicker than CALL, but not much. CALL worked out about 20 times more expensive than a variable assignment on UniData, which in my book is not worth half a days additional debugging associated with every variable having global scope within a single program. As I said, the way I understand it FUNCTIONs in UniData are just CALLs wearing a disguise, but at various points in the past there have been discussions about changing this - presumably to make them faster and better - more than one function in a source code file would be nice). Certainly they are worthwhile - you can overlay any UniData built-in function if you like: DEFFUN SYSTEM(VBLE) CALLING MYSYSTEM for example is a way to extend the facilities of UniData's SYSTEM function to suit code being converted off a platform that provides different SYSTEM() facilities. Cheers, Ken --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] Custom Functions
Try using the SUBR() function, as I mentioned in another post. - Original Message - From: Burwell, Edward [EMAIL PROTECTED] To: 'u2-users@listserver.u2ug.org' u2-users@listserver.u2ug.org Subject: RE: [U2] Custom Functions Date: Wed, 22 Jun 2005 19:49:44 -0400 I've tried calling functions from UniData Virtual Attribute and they blow up. Bummer. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/