Re: Variables to call...
Posted in 1994
> >Hi folks, > >I am running 4gl 4.10.UC1 on a Sun and have the following question: > >Is there not a method to pass variables to the 4gl 'call' routine or > >construct a string that can be run that contains 'call'? > > >It would seem short-sighted to have designed the tools without this > >feature if this is the case. Hmm...dunno if I'd call it short sighted...stuff's been around a pretty long time. Besides, it's kinda hard to get those kind of statements to compile (Heck, even C++ doesn't do that...) > This type of functionality currently isn't available, and I think it > would be very difficult to implement, since function names need to be > known at compile/link time. You could, of course, make the functions > seperate executables, then RUN them, passing in appropriate > parameters. The RUN has the advantage of being background batched, so > you don't have to wait for one report to complete before firing off > another one. Welllll....ummm...There is a way...sorta. You need 4.1, a C compiler, and it only works with RDS. But it does work. With those prerequisites, class..let's turn to page 203 of our "Informix 4gl Supplement" manual. There is a chapter on calling 4GL functions from 'C'. If you dig into it a little bit, it all boils down to a macro "fgl_call(funcname,num_parms)". Tracking through the .h file fgl_api.h, we find that fgl_call turns into 'p4gl_call("funcname",num_parms)'. This means, that with RDS and a little help from a C compiler, we can write a function to which we can pass a string value that contains the name of a function we want executed. I've done it, and it works but I haven't used it in anything production. It was more a "This is a novel idea, let's try it out". It worked. The real difficult part will be the passing of variables, but if all of your reports uses the same variables, it may not be a problem. Or, of course, better yet, you have something like: function rep1() report xyz(a,b,c) to printer end function function rep2() report zyx(a,b,c,d) to file "hoopla.out" end function and then: prompt "Enter report name (rep1, rep2):" for rep_name call func_by_name(rep_name) Overall, it's pretty crafty. I'm not sure if you really GAIN anything (over, say a big 'ol case statement), but if you've got a bazillion reports, it can work. It's not all that much trouble (especially if you wrap the reports like above -- then it's trivial). Of course, if you're really into some twisted stuff, a little later it talks about dynamically loading .4go's into your program. I've tried it, and that works too. Have fun! Will (villy@collinscomp.com)