Passing empty DataSet to Appserver - progress-4gl

I'm trying to create a single proxy query to our appserver, which uses the following parameters:
editTest.p
DEFINE TEMP-TABLE TT_Test NO-UNDO
BEFORE-TABLE TT_TestBefore
FIELD fieldOne LIKE MyDBTable.FieldOne
FIELD fieldTwo LIKE MyDBTable.FieldTwo
FIELD fieldThree LIKE MyDBTable.FieldThree
.
DEFINE DATASET dsTest FOR TT_Test.
/* Parameters */
DEF INPUT-OUTPUT PARAM DATASET FOR dsTest.
The idea is that the program would call this procedure in 2 different ways:
with passed dataset parameter: read passed dataset and update db according to it's changes
without passed dataset parameter/unknown/unset: fill TT_Test and return dataset to client for editing
Is there any way to create a proxy like this? Easy solution would be to separate the get and insert,modify,delete to 2 own proxy files, so the client would always first get the dataset and then pass it for for the second one. However, I'd like to implement this functionality into this one file.
The key is to use the datasets, so the changes made to the data can be updated almost automatically.

Instead of using the dataset itself as the parameter, use a dataset handle. You can then make it null for your 2nd condition. Adding on to your example, procedure testProc will display a message "yes" when the dataset is passed in via the handle, and "no" when null is passed in.
DEFINE TEMP-TABLE TT_Test NO-UNDO
BEFORE-TABLE TT_TestBefore
FIELD fieldOne LIKE MyDBTable.FieldOne
FIELD fieldTwo LIKE MyDBTable.FieldTwo
FIELD fieldThree LIKE MyDBTable.FieldThree
.
DEFINE DATASET dsTest FOR TT_Test.
PROCEDURE testProc:
DEFINE INPUT-OUTPUT PARAMETER DATASET-HANDLE phDataSet.
MESSAGE VALID-HANDLE(phDataSet) VIEW-AS ALERT-BOX.
END.
DEFINE VARIABLE hTest AS HANDLE NO-UNDO.
/* Pass in a dataset. */
hTest = DATASET dsTest:HANDLE.
RUN testProc (INPUT-OUTPUT DATASET-HANDLE hTest).
/* Pass in null. */
hTest = ?.
RUN testProc (INPUT-OUTPUT DATASET-HANDLE hTest).

Related

Selecting variables in a dataset according to values in another dataset

I want to create a subset for a dataset which has around 100 variables and I wish to KEEP only those variables that are present as values of another variable in another dataset. Can someone pleae help me with a SPSS Syntax.
This is what it should look like:
DATASET ACTIVATE basedataset.
SAVE OUTFILE ='Newdata.sav'
/KEEP Var1.
Var 1 is the variable in the other dataset which contains all the values based on which i want to perform the subsetting.I am not sure if vector should be involved or if there is an easier way to do this.
The following will create a macro containing the list of variables you require, to use in your analysis or in subsetting the data.
First I'll create some sample data to demonstrate on:
data list free /v1 to v10 (10f3).
begin data
1,2,3,2,4,7,77,777,66,55
end data.
dataset name basedataset.
data list free/var1 (a4).
begin data
"v3", "v5", "v6", "v9"
end data.
dataset name varnames.
Now to create the list:
dataset activate varnames.
write out="yourpath\var1 selection.sps"
/"VARIABLE ATTRIBUTE VARIABLES= ", var1, " ATTRIBUTE=selectVars('yes')." .
exe.
dataset activate basedataset.
VARIABLE ATTRIBUTE VARIABLES=all ATTRIBUTE=selectVars('no').
insert file="yourpath\var1 selection.sps".
SPSSINC SELECT VARIABLES MACRONAME="!varlist" /ATTRVALUES NAME=selectVars VALUE = yes .
The list is now ready and can be called using the macro name !varlist in any command, for example:
freq !varlist.
or
SAVE OUTFILE ='Newdata.sav' /KEEP !varlist.

How do you retrieve a date value from a buffer-field in Progress Openedge?

I've got a buffer which contains a mix of data, number and character fields. I am getting the displaying the values of the fields, but for some reason date fields return "?" when I try to add them to a string.
I still get ? even if I do
ASSIGN lvString = lvString + STRING( hField:BUFFER-VALUE ).
I've also tried assigning the BUFFER-VALUE to a local DATE variable, and converting that to a string, but that doesn't work either - still ?.
However if I use the STRING-VALUE attribute, it works fine.
How do I get the value out as a date field, rather than just a string?
There are two ways that you can use to achieve your needs. One is to use directly the table buffer and the other is to use an QUERY handle.
First example using a buffer directly from a table (or a TEMP-TABLE, doesn't matter):
DEF VAR dateVar AS DATE NO-UNDO.
FIND FIRST job NO-LOCK.
dateVar = DATE(BUFFER job:BUFFER-FIELD('dt-job'):BUFFER-VALUE).
MESSAGE dateVar
VIEW-AS ALERT-BOX INFO BUTTONS OK.
Second example using a query handle:
DEF VAR dateVar AS DATE NO-UNDO.
DEF QUERY qrJob FOR job.
OPEN QUERY qrJob FOR EACH job.
QUERY qrJob:GET-FIRST().
dateVar = DATE(QUERY qrJob:GET-BUFFER-HANDLE(1):BUFFER-FIELD('dt-job'):BUFFER-VALUE).
MESSAGE dateVar
VIEW-AS ALERT-BOX INFO BUTTONS OK.
As Tim Kuehn said you can substitute 'dt-job' by # of field in the query if you know its position inside the query. I could used BUFFER-FIELD(2) in substitution of BUFFER-FIELD('dt-job') because dt-job is the #2 field in my query. Keep in mind that use the FIELDS clause in a FOR EACH or in an OPEN QUERY statement changes the order of fields in query. Generally, for browsers only available the columns fields specified in FIELDS section, in order.
These might work for you. It's important to say that BUFFER-VALUE always returns a CHARACTER data type and because of this you need to use DATE statement for data conversion.
Hope it helps.
The standard form for getting a data of the field's data type is
buffer table-name:buffer-handle:buffer-field("field-name"):buffer-value.
for arrays it's:
buffer table-name:buffer-handle:buffer-field("field-name"):buffer-value[array-element].
You can also substitute a field # for "field-name" to get the buffer field handle.

How to instantiate local variables in decision tables

I am pretty new to drools and am given the below task.
I am inserting a few POJO into my KieSession object and am retreiving them into variables in my decision table as follows.
CONDITION CONDITION CONDITION ACTION
abc: classABC xyz: classXYZ lmn : classLMN
var1 == $param var2 == $param
1 2 3
As far as I understand, the above table would yield the following rule
when
abc:classABC(var1==1)
xyz:classXYZ(var2==2)
lmn:classLMN(var3==3)
then
some action
What I want is to get the following.
when
abc:classABC(var1==1)
xyz:classXYZ(var2==2)
lmn:classLMN(var3==3)
fgh:classFGH($var:var4) // I think this step is creating a new variable to hold value of var4
then
some action
How do I get this on a decision table ?
I tried just adding a condition column with the variable declaration as fgh :classFGH, but since there is no data to be provided in the data row, this column would be ignored. If I do, give some data, there is an error at compile time "no code sinppet at xyz column". All I need is to declare a variable that can hold the value of the object that I have passed in my main method and use that object later in a different column of my decision table.
I'm not sure I get the requirement around the decision table, but you can 'use' the firing of a rule to create new facts and insert them, with parameters from the original events. These can then be used to trigger further rules, like so (assuming var4 is boolean):
declare AllMoonsInAlignmentEvent
#role (event)
extraCheese : boolean
end
rule "Some Rule"
when
$abc:classABC(var1==1)
$xyz:classXYZ(var2==2)
$lmn:classLMN(var3==3)
$fgh:classFGH($var:var4)
then
... some action using `$var`, `$abc` etc
AllMoonsInAlignmentEvent myEvent= new AllMoonsInAlignmentEvent();
myEvent.extraCheese = $var;
insert(myEvent);
rule "With Extra Cheese"
when
$moonsAligned:AllMoonsInAlignmentEvent(extraCheese == true)
then
...
rule "Without Extra Cheese"
when
$moonsAligned:AllMoonsInAlignmentEvent(extraCheese == false)
then
...
You can get X($y:y) into a spreadsheet in two ways. First, in column 4
X($y:y /*$param*/)
and fill the column with any character you like. The other way might be in column 3 (!)
fgh:classFGH($var:var4) lmn:classLMN
var3==$param
These tricks are always a bit iffy. Rules requiring the simple "grab" of a fact aren't typical for spreadsheets and could be the first indication that you aren't pursuing the best approach.
CONDITION
fgh:classFGH
$param:var4
Comment cell
$var

BIRT - using report variable to pass data from outer to inner nested data set

Hoping someone can tell me what is wrong with this BIRT report. I am trying to use a nested scripted data set, where the outer data set passes data to the inner data set through a report variable.
I find that the report isn't acting as I thought it would. It seems as though the report variable is outputting the last value it has for every row. For the below report I am seeing output such as:
key0
value[9][0]
value[9][1]
value[9][2]
value[9][3]
value[9][4]
key1
value[9][0]
value[9][1]
value[9][2]
value[9][3]
value[9][4]
....
key9
value[9][0]
value[9][1]
value[9][2]
value[9][3]
value[9][4]
Whereas I would expect to see this:
key0
value[0][0]
value[0][1]
value[0][2]
value[0][3]
value[0][4]
key1
value[1][0]
value[1][1]
value[1][2]
value[1][3]
value[1][4]
....
key9
value[9][0]
value[9][1]
value[9][2]
value[9][3]
value[9][4]
My (fully self contained) example report is here: click to see report xml in pastebin.
The key idea is that in the outer data set's fetch, I set the report variable:
vars["values"] = value;
And the inner data set's fetch will grab it:
values = vars["values"].iterator();
and the inner data set's fetch will take data from the report variable:
row["value"] = values.next();
You should be able to use dataSet parameters, to do this. In your example, you'd set up an output parameter in the outer data set's dataset editor. You'd set the value of this parameter to be your values you're passing to the other dataSet.
In the inner dataSet, you'd create an input parameter to take the values. In your layout, you'd need to refresh the bindings on the outer list, so that the output parameter is a binding. Then, you'd go to the binding tab, for the inner list, and choose to pass the outer list's output parameter binding to your input parameter.
Hope this helps.

Text input through SSRS parameter including a Field name

I have a SSRS "statement" type report that has general layout of text boxes and tables. For the main text box I want to let the user supply the value as a parameter so the text can be customized, i.e.
Parameters!MainText.Value = "Dear Mr.Doe, Here is your statement."
then I can set the text box value to be the value of the parameter:
=Parameters!MainText.Value
However, I need to be able to allow the incoming parameter value to include a dataset field, like so:
Parameters!MainText.Value = "Dear Mr.Doe, Here is your [Fields!RunDate.Value] statement"
so that my report output would look like:
"Dear Mr.Doe, Here is your November statement."
I know that you can define it to do this in the text box by supplying the static text and the field request, but I need SSRS to recognize that inside the parameter string there is a field request that needs to be escaped and bound.
Does anyone have any ideas for this? I am using SSRS 2008R2
Have you tried concatenating?
Parameters!MainText.Value = "Dear Mr.Doe, Here is your" & [Fields!RunDate.Value] & "statement"
There are a few dramatically different approaches. To know which is best for you will require more information:
Embedded code in the report. Probably the quickest to
implement would be embedded code in the report that returned the
parameter, but called String.Replace() appropriately to substitute
in dynamic values. You'll need to establish some code for the user for which strings will be replaced. Embedded code will get you access to many objects in the report. For example:
Public Function TestGlobals(ByVal s As String) As String
Return Report.Globals.ExecutionTime.ToString
End Function
will return the execution time. Other methods of accessing parameters for the report are shown here.
1.5 If this function is getting very large, look at using a custom assembly. Then you can have a better authoring experience with Visual Studio
Modify the XML. Depending on where you use
this, you could directly modify the .rdl/.rdlc XML.
Consider other tools, such as ReportBuilder. IF you need to give the user
more flexibility over report authoring, there are many tools built
specifically for this purpose, such as SSRS's Report Builder.
Here's another approach: Display the parameter string with the dataset value already filled in.
To do so: create a parameter named RunDate for example and set Default value to "get values from a query" and select the first dataset and value field (RunDate). Now the parameter will hold the RunDate field and you can use it elsewhere. Make this parameter hidden or internal and set the correct data type. e.g. Date/Time so you can format its value later.
Now create the second parameter which will hold the default text you want:
Parameters!MainText.Value = "Dear Mr.Doe, Here is your [Parameters!RunDate.Value] statement"
Not sure if this syntax works but you get the idea. You can also do formatting here e.g. only the month of a Datetime:
="Dear Mr.Doe, Here is your " & Format(Parameters!RunDate.Value, "MMMM") & " statement"
This approach uses only built-in methods and avoids the need for a parser so the user doesn't have to learn the syntax for it.
There is of course one drawback: the user has complete control over the parameter contents and can supply a value that doesn't match the report content - but that is also the case with the String Replace method.
And just for the sake of completeness there's also the simplistic option: append multiple parameters: create 2 parameters named MainTextBeforeRunDate and MainTextAfterRunDate.
The Textbox value expression becomes:
=Parameters!MainTextBeforeRunDate.Value & Fields!RunDate.Value & Parameters!MainTextAfterRunDate.Value.
This should explain itself. The simplest solution is often the best, but in this case I have my doubts. At least this makes sure your RunDate ends up in the final report text.