Simplicty and flexibility!


Subroutine


Started by Marco Marchesi
Search
You will need to Sign In to be able to add or comment on the forum!

Subroutine

I need to create a subroutine to be called many many times by a DQL. (from 50000 to 80000 and more times to run)
Using "run procedure" I can pass parameters to the routine and receive back the results using global variables but the execution is very slow.
I know that using "ExecDQL" (or MemoExecDQL etc..) function processing would be much faster, but how to pass parameters to the routine and get back the results?
To pass parameters to the routine I know I can use the "data-entry Field1" "data-entry Field2" "data-entry Field3" "data-entry field4" variables (up to a maximum of 4 but I would need more!).
The question is : How can I do instead to get back the calculated parameters / results of the routine?
At the moment I use 8.2.0.1700 version. Thanks.


Written by Marco Marchesi 16/03/17 at 09:13:58 Dataease [{8}]FIVE

Re:Subroutine

Hello Marco.

This is much easier to do in ExecDQL and as you say much much much faster.

The original idea behind ExecDQL was this i.e to be able to run DQL without being burdened with the heavy DFW Document GUI.

8.2 is a long time ago now, but I am sure you have everything you need in there to do this too.

I will not go into all the fantastic opportunities that ExecDQL offers now but you can in fact read and write directly into a form with SetValue()/GetValue() etc.

However what you need for this is simply SetVar()/GetVar()

You can transfer as many values as you like to and from the ExecDQL and also between them with SetVar()/GetVar().

Ex.

Action on button.
SetVar("Input1",InputFIeld1)+MemoExecDQL(DQL) 

DQL
define "retval" text .
define "counter" number .
for MyTable with Field = GetVar("Input1") ;
counter := counter + 1 .
retval := SetVar(concat("Retval:",counter),price*number*vat .
end

There has been a fantastic evolution throughout DE8 so I am not sure when we got variable arguments etc.

In 8.5 you can produce output to files, pdf, Memo etc. 

There is absolutely no good reason to stay behind in 8.2 as you simply loose out on the best functionality.

However everything we have shown above you should be able to do in 8.2 just make sure you use the correct formatting for MemoExecDQL()

Which back then was (I think) fixed with 6 arguments

DQL,Data-entry1,Data-entry2,Data-entry3,Data-entry4,Outputfile


Written by DataEase 16/03/17 at 16:10:44 Dataease [{8}]FIVE

Re:Re:Subroutine

Download: 8. ExecDQL.zip

It doesn't work. In de 8.2. I receive a GPF error. Your DQls are not checked.

In DE 8.5 (last version) I create the DQLs  and table like yours 

MyTable

StartDQL

define "a" number .
define "InputFieId1" text 25 .

assign temp InputFieId1 := "Berlin" .
a := SetVar("Input1", temp InputFieId1 ) .
a:= MemoExecDQL("DQL") .
message Getvar("Retval") window .

assign temp InputFieId1 := "Paris" .
a := SetVar("Input1", temp InputFieId1 ) .
a := MemoExecDQL("DQL") .
message Getvar("Retval") window .

assign temp InputFieId1 := "Rome" .
a := SetVar("Input1", temp InputFieId1 ) .
a := MemoExecDQL("DQL") .
message Getvar("Retval") window .

DQL

define "retval" text 50 .
define "counter" number .
-- message GetVar("Input1") window .
for MyTable with Field = GetVar("Input1") ;
counter := counter + 1 .
retval := SetVar( "RetVal" , concat(Field , " " , "Retval : " , counter , " - " , (price*number*vat) ) ) .
end

Running the StartDQL I receive three times  the same message

In the form "test" you'll find the solution via button but I need a solution with a DQL that launch several times the routine.

In attach the database zipped for reference


Written by Marco Marchesi 17/03/17 at 11:38:18 Dataease [{8}]FIVE

Re:Re:Re:Subroutine

Download: ExecDQL.zip

Download Sample!

Hi again.

Thanks for the sample application.

From that I can see that you can't get your head around how this works.

You are not alone, so I have created a sample (8.5) that show how ExecDQL works.

The main importance of this is to remember that it has NOTHING to do with the DQL that you are used to use other than the syntax of DQL itself.

ExecDQL live outside the paradigm of DQL from DFD and DFW.


ExecDQL is not a document it is a script as text and it can be stored in a field, in a derivation in a memo, in a file or in a lable etc.

You cannot execute a ExecDQL by doing RunProcedure() or DocumentOpen()

If you use RunProcedure() or DocumentOpen() in a ExecDQL it will open a old style DQL and not an execDQL.

An ExecDQL is part of the data and not part of the definition/document hierarchy.

If you have a memo in your form you can execute a DQL written (looked up) in that Memo with the command 

MemoExecDQL(FieldName etc) ex. MemoExecDQL(MyDQLMemo etc.
LabelExecDQL("ObjectName")  ex LabelExecDQL("MyDQLLabel" etc
FileExecDQL("FileName" ex. FileExecDQl("C:\DQLS\DQL1.TXT" etc.
ExecDQL("DQL script directly") ex. ExecDQL("delete records in MyTable .") 


Written by DataEase 17/03/17 at 13:27:40 Dataease [{8}]FIVE

Re:Re:Re:Re:Subroutine

Thanks for all. My original request was "how to use a DQL as a subroutine". I mean .. If I use a DQL via ExecDQL or MemoExecDQL or LabelExecDQL it seems to me that it not synchronized with the main SQL that use those functions and it doesn't works correctly and returns not correct results. Do you have a suggestion for this case? Thanks.


Written by Marco Marchesi 04/04/17 at 08:24:01 Dataease [{8}]FIVE

Subroutine using ExecDQL Explained!

Download Revised Sample


Sorry, Marco. Had to revisit your example.

I'm sorry but in danger of breaking the rule of "The customer is always right" I have to say that you are completely off the mark.

You can't get your head around how it works as you are stuck in the old paradigm.

You don't get the correct result because from what I can see you haven't yet managed to execute the the DQL.

In your TRADITIONAL DQL you do the following

assign temp InputFieId1 := "Berlin" . -- set temp variable to Berlin

a := SetVar("Input1", temp InputFieId1 ) . -- set global variable input1 to Inputfield i.e. Berlin

a:= MemoExecDQL("DQL") . -- Run the MemoExecDQL function with an illegal reference, the input need to be a MEMO column and you have used a string that contain the word DQL. This does give no meaning. In 8.5 we simply ignore wrong commands as this is a runtime function and errormessages will only disrput the use. In 8.2 you get an error message simply because your SCRIPT is illegal a DQL Script cannot be simply "DQL" it should be something like: for Tablename etc..

message Getvar("Retval") window . -- Since no ExecDQL has been executed the retval will be what it was the last time you run something that set it.

assign temp InputFieId1 := "Paris" . -- and then the story start over again. My guess is that you run a traditional DQL or something that set Retval to Rome and as this DQL do nothing it just remain as Rome.

a := SetVar("Input1", temp InputFieId1 ) .

a := MemoExecDQL("DQL") .

message Getvar("Retval") window .

assign temp InputFieId1 := "Rome" .

a := SetVar("Input1", temp InputFieId1 ) .

a := MemoExecDQL("DQL") .

message Getvar("Retval") window .



When you use ExecDQL you execute the code stored in a TEXT not in a document. 


You can transfer 4 data-entry variables directly so you don't need to transfer values via GetVar()/SetVar() if you need only to transfer 4 values or left.

MemoExecDQL(DQLMemo,DataEntry1,DataEntry2,DataEntry3,DataEntry4,"PDF:C:\myTestDocument.pdf",MyFormatMemo)

We are sorry, but we can't really spend any more time on this now. If you can't get your head around it you need to sit down with someone and get this explained to you in a ordered fashion as there is nothing wrong with ExecDQL - in truth it is the most powerful tool in DataEase so far - but it is a change in thinking and approach so you are not alone in having problems in getting your head around it.


Written by DataEase 04/04/17 at 09:06:00 Dataease [{8}]FIVE
DG3_ForumList