Search | Synergex.com | Contact Us | Resource Center Login | Home|
News

The S_BLD routine is unusual among Synergy routines in that it takes an unspecified number of arguments of various types. How can you wrap S_BLD with your own routine that takes the same arguments and passes them to S_BLD?

Which answer is correct?

a.  You can't.
b.  Use an ArrayList for the arguments.
c.  Use the Synergy Routine Call Block API.
d.  Use ^VARARGARRAY.

Explanation

S_BLD (and a few other routines) differs from the majority of Synergy/DE routines in that it can take any number of arguments, and those arguments can be of any primitive type. Wrapping that routine presents a challenge for the traditional Synergy/DE syntax, in which each argument is named and typed and passed on by reference. But it's not impossible.

ArrayLists (b) allow you to create a variable series of disparately typed objects. Unlike languages such as Perl or Ruby, however, Synergy/DE does not provide a way to pass an ArrayList as an argument list. So the routine being called would have to expect an ArrayList argument in order for that to work. It's a good option for when you control both sides of the call, but that isn't the case here.

The Synergy routine call block API (c) provides a mechanism for replicating the argument list of the current routine, modifying it, changing the destination function, and invoking it. It is therefore perfectly suited to this purpose, except for one thing: if you are using Synergy .NET, you’re out of luck, because the RCB API isn't available. The predisposition of Microsoft's .NET Framework for strong, static typing runs counter to the more dynamic capabilities of the RCB API.

The .NET Framework does support variable argument lists, but only when they're declared that way by the routine being called. Synergy .NET provides access to that facility through the ^VARARGARRAY supplied function. S_BLD declares all of its final optional arguments as VARARGS, so you can use ^VARARGARRAY for those arguments. Unfortunately, ^VARARGARRAY is not available on other platforms.

Thus, the correct answer is (d) on Synergy .NET and (c) everywhere else. Here's an example of wrapping S_BLD in a platform-independent manner:

subroutine my_sbld, varargs
   out req buffer ,a
   out opt len    ,n
   in  req format ,a
.ifndef DBLNET
     .include "DBLDIR:rcbapi.def"
.endc
proc
.ifdef DBLNET
     s_bld(buffer, len, format, ^varargarray) 
.else
     begin
        data rcb, int
        rcb = %rcb_create(%numargs, DRCB_REPLICATE)
        rcb_setfnc(rcb, "s_bld")
        rcb_call(rcb)
     end
.endc
     xreturn
end

Note the "varargs" on the subroutine statement and the .ifdef DBLNET and .else sections. Add whatever else your wrapper routine needs to do either before the .ifdef or after the .endc.

More information about News and Events

Contact Synergex to learn more about  News and Events