RE: [Openroad-users] Call 4glprocedures and methods dynamically

35 views
Skip to first unread message

Lovell, Simon

unread,
May 22, 2006, 10:02:12 PM5/22/06
to OpenROAD Users

That may not work, but what you should be able to do is pass it like this:

 

Callproc :myvar( :myparam1 = inta, :myparam2 = intb );

 

Obviously, you need to know the number of the parameters and their data types with this though.

 

If you want to be REALLY dynamic, consider passing dynamic expression(s) to your procedure.  I haven’t tried this one, so I’m not sure if moving to a different scope would cause a problem, but I don’t think it should.  And if you don’t know how many parameters you need, you could use an array of dynamic expressions.  I’m not sure why you’d need this, though.

 

Simon Lovell
Analyst/Programmer
CA Technical Services
07 3367 7116


From: openroad-us...@peerlessit.com [mailto:openroad-us...@peerlessit.com] On Behalf Of Sergio Sperandio
Sent: Tuesday, 23 May 2006 2:05 AM
To: openroa...@peerlessit.com; info-...@cariboulake.com
Subject: [Openroad-users] Call 4glprocedures and methods dynamically

 

I would like to call a 4GL Procedure in a very dynamic way, but up to now I was not able in doing that. In order to explain my question, I provide an example.

The following works (procedure without parameters):

my_var = varchar (50);

...

my_var = 'MyProcedure';

callproc :my_var;

This executes procedure "MyProcedure".

My problem arises when I try to specify some parameters, and statically I don't know their names and the values they have to assume.

For example, let procedure MyProcedurePar be defined as follows:

PROCEDURE MyProcedurePar (

            param1 = integer,           param2 = integer

) = DECLARE

ENDDECLARE

BEGIN

            message varchar (param1) + ' - ' + varchar (param2);

END

;

 

I would like to know whether exists a way for calling it without using the following syntax:

 

CALLPROC MyProcedurePar (param1 = 1, param2 = 2);

 

I would like to insert both procedure name and parameters in two varchars, i.e.:

 

my_proc = 'MyProcedurePar (param1 = 1, param2 = 2)'

CALLPROC :my_proc;

 

but it does not work, since OpenRoad considers the whole variable as the procedure name.

I tried to get the ProcHandle and use the call method, but the problem remains.

 

I hope somebody of you might help me.

Thanks,  Sergio

Chris Wallace

unread,
May 22, 2006, 11:18:15 PM5/22/06
to OpenROAD Users

Sergio,

 

Have you considered creating a dynamic procedure that calls your procedure?

 

We use this facility for our Award Interpreter (Payroll) for executing user-define award processing rules.

 

Something like?

 

 

            mv_ps = proc4glsource.create();

 

            // Assemble Parameter String

            // Below is a static example, but we dynamically create the param string from a database table

 

            mv_param_string.Value = ‘param1=’ + param1_value + , param2=’ + param1_value;

 

            // Build Source Code for Dynamic Procedure

            // We have standard transaction context parameters that are passed to all procedures,

            //      however the example below does pass any parameters to the dynamicProcedure

 

            mv_ps.script = 'procedure dynamicProcedure + '( ) = '+hc_newline+

                                                'begin ' + hc_newline +

                                    ‘    return MyProcedure (' + mv_param_string.Value + ') ;' + hc_newline +

                                                'end;' + hc_newline ;

 

            /* Assign Other appropriate items to Dynamic Procedure */

            mv_ps.datatype = 'integer1';

            mv_ps.name = ‘dynamicProcedure’;

            mv_ps.ParentApplication = application.Message_Exec.ObjectSource.ParentApplication;

 

            /* Execute Dynamic Procedure */

            mv_return_status = callproc :mv_tmp_procname ( );

 

Note: If the parameters are static you can create the procedure once in the application and call it as often as you like, passing parameter values if necessary.

 

Regards

Chris Wallace

Management Information Systems (WA) Pty Ltd
Level 9, MIS House
231 Adelaide Terrace, PERTH  WA  6000
Ph: (08) 9221-9221  Fax: (08) 9221-9224

Email: chr...@miswa.com.au
Web: http://www.miswa.com.au

Disclaimer
:  Management Information Systems (MIS)
This e-mail is private and confidential. If you are not the intended recipient, please advise us by return e-mail immediately, and delete the e-mail and any attachments without using or disclosing the contents in any way. The views expressed in this e-mail are those of the author, and do not represent those of MIS unless this is clearly indicated.  You should scan this e-mail and any attachments for viruses.  MIS accepts no liability for any direct or indirect damage or loss resulting from the use of any attachments to this e-mail.

 


From: Brian Risley [mailto:bris...@earthlink.net]
Sent: Tuesday, 23 May 2006 10:51 AM
To: OpenROAD Users
Subject: Re: [Openroad-users] Call 4glprocedures and methods dynamically

 

Forgot to clear p1 between parse calls.
Brian


Brian Risley wrote:

This should be fairly simple:
Build up a varchar using the keyword parameter concept:
paramname1=value;paramname2=value;  etc.
Then all you have to do is
something like this:
param=_stringparsekeyword(string=pass1, keyword='TABLE_NAME');

You can add the pass1 value to existing parameters and test if pass1 is empty.  If it is not, then you can set the parameters using this method.  This way a procedure can be called dynamically or hard coded and not change your existing code:

procedure test_call(rc=integer not null, /*return code*/, inintparm=integer not null,indateparm=date not null,invarcharparm=varchar(50) not null,pass1=varchar(2000) not null)=
declare
 p1=varchar(2000) not null, /* holder for params */
enddeclare
begin
 if squeeze(pass1) !='' then /* we need to get params via pass1 */
  p1  =_stringparsekeyword(string=pass1, keyword='ININTPARM');
  if squeeze(p1)!='' then
      inintparm=int4(P1);
  endif;
 p1  =_stringparsekeyword(string=pass1, keyword='INDATEPARM');
 if squeeze(p1)!='' then
    indateparm=date(p1);
 endif;
  p1  =_stringparsekeyword(string=pass1, keyword='INVARCHARPARM');
 if squeeze(p1) !='' then
  invarcharparm=p1;
endif;
/*  procedure code block
*/
end;

Now you can easily setup a common procedure to handle building up pass1: (You will need for each data type or convert the data into a varchar in your calling process)

Procedure build_varchar_pass1(paramname=varchar(32) not null,paramvalue=varchar(2000) not null,pass1=varchar(2000) not null)=
begin
  if squeeze(paramname) ='' then
    return; /* can't add without a name */
  endif;
  if squeeze(pass1) !='' then /* only do this for empty pass1 */
   if right(squeeze(pass1),1)!=';' then /* not properly terminated */
     pass1=pass1+';';  /* add terminator */
   endif;
  endif;
  pass1=pass1+uppercase(paramname)+paramvalue+';';
end;

Float data types are best converted to a fixed decimal format if possible.


Now I did this off the cuff, so if there are any typo's or other problems, don't complain!

You could do something similar with an array of a userclass that has a varchar and an object pointer if you must pass objects. 
My thanks to those who explained to me how to use this format in the clienttext attribute.

Brian Risley
EGTS


Lovell, Simon wrote:


------------------------------------------------------------------------

_______________________________________________
Openroad-users mailing list
Openroa...@peerlessit.com
http://www.peerlessit.com/mailman/listinfo/openroad-users
 



 



 
_______________________________________________
Openroad-users mailing list
Openroa...@peerlessit.com
http://www.peerlessit.com/mailman/listinfo/openroad-users
  

Sergio Sperandio

unread,
May 22, 2006, 12:04:56 PM5/22/06
to openroa...@peerlessit.com, info-...@cariboulake.com

Brian Risley

unread,
May 22, 2006, 10:47:22 PM5/22/06
to OpenROAD Users

Brian Risley

unread,
May 22, 2006, 10:51:06 PM5/22/06
to OpenROAD Users
Forgot to clear p1 between parse calls.
Brian


Brian Risley wrote:
------------------------------------------------------------------------

_______________________________________________
Openroad-users mailing list
Openroa...@peerlessit.com
http://www.peerlessit.com/mailman/listinfo/openroad-users
 

Reply all
Reply to author
Forward
0 new messages