I am using Progress 4GL
I have a spreadsheet of data containing several columns called data1....50.
I have created a temp table which holds all the values.
Now I would like to loop through the temp table columns and do various calculations
So I need something like this:
for each record loop thru cols_in_temp_table .
if col_value = "XYZ" then
do calcs and stuff
end.
So how do I reference the temp_table cols ?
Ok, didn't resolve the original query, but found a workaround. Split the data up and put into separate tables, long winded, but does the trick.
Depending on your version, this is one way to do it:
DEFINE VARIABLE h-cols AS HANDLE NO-UNDO.
h-cols = tt-cols:BUFFER-HANDLE.
FOR EACH tt-cols
NO-LOCK:
IF h-cols::col-name = "some value" THEN
RUN do-something.
END.
For versions that can't do the "::" operator, do this:
FOR EACH tt-cols
NO-LOCK:
IF h-cols::buffer-field("col-name"):buffer-value = "some value" THEN
RUN do-something.
END.
Related
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.
I have a crystal report I need to change the select criteria on. Currently criteria compare's a database field to the parameter I created in the report.
{MaterialCR.MaterialId} = {?MaterialId}
I am now have a field that has comma delimited data in it I need to make sure the parameter includes any of the other ids in the new field.
Materialused has this data in it. "MA0161 ,MA0167" (No double quotes) . This doesn't work
{MaterialCR. MaterialUsed} = {?MaterialId}
I have tried to create a function to compare the two but it does not seem to work. It does not see the parameter as a string array.
My material match function that does not work
Function MaterialMatch (MaterialUsed as string,v1 () As String)
dim MyArray() as string
MyArray = Split (MaterialUsed,"," )
dim Match as boolean
Match = false
dim x as number
For x = 1 To count(v1) Step 1
IF "ALL" in v1 then
Match = true
x = count(MyArray)
end if
if MyArray(x) in v1 then
Match = true
x = count(MyArray)
end if
Next x
MaterialMatch = Match
End Function
This is what the data I am looking at looks like. We have many materials with a Material ID in it. We also have associated time that we need to select. It does not have a material id as it is a many to one situation. I need to retrieve all the records associated with the material including the time. Getting the material with ids is not the issue. I need to get the Time records also. I modified the view this report uses to include the material that overlaps the time. This is where I am stuck.
This is what my select expert formula looks like now. I do know the material used part is wrong.
(
{JobTimeMaterialCR.MaterialId} = {?MaterialId}
or
(
{JobTimeMaterialCR.Type} = "Time"
and
{JobTimeMaterialCR.MaterialUsed} = {?MaterialId}
))
I was able to write a formula that worked for me using the logic I described in my comment. Use this formula as your Record Selection Formula. In Formula Workshop these are found in Selection Formulas > Record Selection.
Local StringVar array values := Split({?Search Values},",");
Local NumberVar indexCount := Count(values);
Local BooleanVar found := false;
Local NumberVar counter;
For counter := 1 to indexCount Step 1 Do
(
If InStr({ARINVT.DESCRIP}, values[counter]) > 0 Then
found := true
);
found;
It's rough, but a good start. The search is case sensitive, so you may need to tweak it with some Lower() functions if you want case insensitive searches. Also, if there is a space between the delim character and the search string in your CSV string, then the space is included in the search. A Replace() function can help you get around this, but that would prevent you from using spaces in the search strings. If you need to use spaces in searches, then just take care when building your CSV String that there are no spaces before or after the comma that is your delim character.
If you need any help understanding the syntax of my formula feel free to comment and I will answer any questions.
I used a parameter field called {?Search Values} to simulate the CSV string data. {ARINVT.DESCRIP} is a field name from my test database I used to search thousands of records for key words I typed into my parameter field. You will want to replace these field names in the formula with your field names and you should be able to get this working without much trouble.
DEFINE TEMP-TABLE tt_pay_terms NO-UNDO
FIELD pt_terms_code LIKE payment_terms.terms_code
FIELD pt_description LIKE payment_terms.description.
DEFINE VARIABLE htt AS HANDLE NO-UNDO.
htt = TEMP-TABLE tt_pay_terms:HANDLE.
FOR EACH platte.payment_terms
WHERE (
active = true
AND system_id = "000000"
)
NO-LOCK:
CREATE tt_pay_terms.
ASSIGN
pt_terms_code = payment_terms.terms_code.
pt_description = payment_terms.description.
END.
htt:WRITE-JSON("FILE", "/dev/stdout", FALSE).
I have written this query and it returns data like this
[pt_terms_code] => 0.4%!N(MISSING)ET46
[pt_description] => 0.4%! (MISSING)DAYS NET 46
While I believe (from using a SQL query) that the data should be
0.4%45NET46
0.4% 45 DAYS NET 46
I'm making an assumption that the % is probably some special character (as I've run into similar issues in the past). I've tried pulling all the data from the table, and I get the same result, (ie, not creating a temp table and populating it with all the only the two fields I want).
Any suggestions around this issue?
I'm still very new to 4gl, so the above query might be terribly wrong. All comments and criticisms are welcome.
I suspect that if you try this:
FOR EACH platte.payment_terms NO-LOCK
WHERE ( active = true AND system_id = "000000" ):
display
payment_terms.terms_code
payment_terms.description
.
END.
You will see what the query actually returns. (WRITE-JSON is adding a layer after the query.) You will likely discover that your data contains something unexpected.
To my eye the "%" looks more like formatting -- the terms are likely 0.4%.
You then seem to have some issues in the contents of the description field. My guess is that there was a code page mismatch when the user entered the data and that there is gibberish in the field as a result.
Some context before the question.
Imagine file FileA having around 50 fields of different types. Instead of all programs using the file, I tried having a service program, so the file could only be accessed by that service program. The programs calling the service would then receive a DataStructure based on the file structure, as an ExtName. I use SQL to recover the information, so, basically, the procedure would go like this :
Datastructure shared by service program :
D FileADS E DS ExtName(FileA) Qualified
Procedure called by programs :
P getFileADS B Export
D PI N
D PI_IDKey 9B 0 Const
D PO_DS LikeDS(FileADS)
D LocalDS E DS ExtName(FileA) Qualified
D NullInd S 5i 0 Array(50) <-- Since 50 fields in fileA
//Code
Clear LocalDS;
Clear PO_DS;
exec sql
SELECT *
INTO :LocalDS :nullind
FROM FileA
WHERE FileA.ID = :PI_IDKey;
If SqlCod <> 0;
Return *Off;
EndIf;
PO_DS = LocalDS;
Return *On;
P getFileADS E
So, that procedure will return a datastructure filled with a record from FileA if it finds it.
Now my question : Is there any way I can assign the %nullind(field) = *On without specifying EACH 50 fields of my file?
Something like a loop
i = 1;
DoW (i <= 50);
if nullind(i) = -1;
%nullind(datastructure.field) = *On;
endif;
i++;
EndDo;
Cause let's face it, it'd be a pain to look each fields of each file every time.
I know a simple chain(n) could do the trick
chain(n) PI_IDKey FileA FileADS;
but I really was looking to do it with SQL.
Thank you for your advices!
OS Version : 7.1
First, you'll be better off in the long run by eliminating SELECT * and supplying a SELECT list of the 50 field names.
Next, consider these two web pages -- Meaningful Names for Null Indicators and Embedded SQL and null indicators. The first shows an example of assigning names to each null indicator to match the associated field names. It's just a matter of declaring a based DS with names, based on the address of your null indicator array. The second points out how a null indicator array can be larger than needed, so future database changes won't affect results. (Bear in mind that the page shows a null array of 1000 elements, and the memory is actually relatively tiny even at that size. You can declare it smaller if you think it's necessary for some reason.)
You're creating a proc that you'll only write once. It's not worth saving the effort of listing the 50 fields. Maybe if you had many programs using this proc and you had to create the list each time it'd be a slight help to use SELECT *, but even then it's not a great idea.
A matching template DS for the 50 data fields can be defined in the /COPY member that will hold the proc prototype. The template DS will be available in any program that brings the proc prototype in. Any program that needs to call the proc can simply specify LIKEDS referencing the template to define its version in memory. The template DS should probably include the QUALIFIED keyword, and programs would then use their own DS names as the qualifying prefix. The null indicator array can be handled similarly.
However, it's not completely clear what your actual question is. You show an example loop and ask if it'll work, but you don't say if you had a problem with it. It's an array, so a loop can be used much like you show. But it depends on what you're actually trying to accomplish with it.
for old school rpg just include the nulls in the data structure populated with the select statement.
select col1, ifnull(col1), col2, ifnull(col2), etc. into :dsfilewithnull where f.id = :id;
for old school rpg that can't handle nulls remove them with the select statement.
select coalesce(col1,0), coalesce(col2,' '), coalesce(col3, :lowdate) into :dsfile where f.id = :id;
The second method would be easier to use in a legacy environment.
pass the key by value to the procedure so you can use it like a built in function.
One answer to your question would be to make the array part of a data structure, and assign *all'0' to the data structure.
dcl-ds nullIndDs;
nullInd Ind Dim(50);
end-ds;
nullIndDs = *all'0';
The answer by jmarkmurphy is an example of assigning all zeros to an array of indicators. For the example that you show in your question, you can do it this way:
D NullInd S 5i 0 dim(50)
/free
NullInd(*) = 1 ;
Nullind(*) = 0 ;
*inlr = *on ;
return ;
/end-free
That's a complete program that you can compile and test. Run it in debug and stop at the first statement. Display NullInd to see the initial value of its elements. Step through the first statement and display it again to see how the elements changed. Step through the next statement to see how things changed again.
As for "how to do it in SQL", that part doesn't make sense. SQL sets the values automatically when you FETCH a row. Other than that, the array is used by the host language (RPG in this case) to communicate values back to SQL. When a SQL statement runs, it again automatically uses whatever values were set. So, it either is used automatically by SQL for input or output, or is set by your host language statements. There is nothing useful that you can do 'in SQL' with that array.
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