Accessing a datatable via a string variable - variables

This is probably one of those that is so simple I can't see it. I have a string variable called Market. The variable is user chosen and is the exact same name as one of many tables in my dataset. Basically I am having the user choose which table they want in a combobox, then I want to use that variable to access the table. So if the user picks "Market1" then I want to open the table named Market1.
I am simplifying here, but need to know how to open:
For ds.<variable here>.rows.count - 1
'perform steps
Next
How do I inject the variable correctly? Thanks ahead of time!

Dataset has Tables property, which accepts table name as a parameter. So in your case if string variable Market holds table name, you can access the table by referring to ds.Tables(Market)

Related

How to put the values of a column of an internal table into a variant?

Can somebody help me figure out if there is a way for the query below:
I have an internal table with one column with 69 records.
I want all these 69 records to be populated into a variant and get saved so that with this variant and the values saved in it I can run a particular program
How can I populate these values ?
Your question is a bit unclear for me.
Do you speak about two programs or one program?
What's the parameter you want to fill in the variant?
I'll just give you some hints - depending on your situation you must pick the correct parts.
I have an internal table with one column with 69 records.
How is the internal table filled?
I want all these 69 records to be populated into a variant and get saved so that with this variant and the values saved in it I can run a particular program
You have a program and you want to save a selection in a variant. So you need some parameters for the selection screen.
You want a table, so you need a SELECT-OPTION.
To define a SELECT-OPTION you need a DDIC-reference (you must say, what kind of field you want.). In the following example I use a material number (MARA-MATNR).
So you program contains something like:
TABLES mara.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
With this you would get:
You can define ranges (from-to) and list of values. As you want only single values, you need something like:
SELECT-OPTIONS: s_matnr FOR mara-matnr NO INTERVALS.
Now you get:
When you push (1) you can enter values.
With (2) you can load from an external file,
with (3) you can load values from clipboard.
So you can fill your values and store the selection in a variant.
When you execute your program, the data is stored in a ranges table:
Now you can loop on this table and copy the S_MATNR-LOW value into your internal table for further processing.
If I misunderstood you question and you want to create a variant dynamically, then take a look on function module RS_VARIANT_ADD (or RS_VARIANT_COPY,RS_VARIANT_CHANGE...)
You could always put the values in TVARVC, either manually or via code. Then specify the TVARVC variable in the variant definition.

Using variable in transformations

I have a requirement where a particular Kettle transformation (ktr) needs to be run multiple times.
This is the scenario:
A transformation has a table input which pulls user details belonging to a particular country.
I have almost 5 countries and this is saved in a separate table.
Can i make a variable and assign the country name to it and run the same transformation in a loop of five times, where every time the variable gets updated to the next country name.
I need the variable to be used in the table input query and in the column name also.
This is how i mentioned the variable in the table input.
When i am giving the variable as value, in the output i am getting '${COUNTRY
}' instead of the value of the variable
PDI allows you to do multiple iteration using a variable. You need to use "copy rows to result" in kettel step. I have a blog written on this topic.
Blog Link : https://anotherreeshu.wordpress.com/2014/12/23/using-copy-rows-to-result-in-pentaho-data-integration/
Please check if it helps you. :)

Access 2010 Database Clenup

I have problems with my records within my database, so I have a template with about 260,000 records and for each record they have 3 identification columns to determine what time period the record is from and location: one for year, one for month, and one for region. Then the information for identifying the specific item is TagName, and Description. The Problem I am having is when someone entered data into this database they entered different description for the same device, I know this because the tag name is the same. Can I write code that will go through the data base find the items with the same tag name and use one of the descriptions to replace the ones that are different to have a more uniform database. Also some devices do not have tag names so we would want to avoid the "" Case.
Also moving forward into the future I have added more columns to the database to allow for more information to be retrieved, is there a way that I can back fill the data to older records once I know that they have the same tag name and Description once the database is cleaned up? Thanks in advance for the information it is much appreciated.
I assume that this will have to be done with VBA of some sort to modify records by looking for the first record with that description and using a variable to assign that description to all the other items with the same tag name? I just am not sure of the correct VBA syntax to go about this. I assume a similar method would be used for the backfilling process?
Your question is rather broad and multifaceted, so I'll answer key parts in steps:
The Problem I am having is when someone entered data into this
database they entered different description for the same device, I
know this because the tag name is the same.
While you could fix up those inconsistencies easily enough with a bit of SQL code, it would be better to avoid those inconsistencies being possible in the first place:
Create a new table, let's call it 'Tags', with TagName and TagDescription fields, and with TagName set as the primary key. Ensure both fields have their Required setting to True and Allow Zero Length to False.
Populate this new table with all possible tags - you can do this with a one-off 'append query' in Access jargon (INSERT INTO statement in SQL).
Delete the tag description column from the main table.
Go into the Relationships view and add a one-to-many relation between the two tables, linking the TagName field in the main table to the TagName field in the Tags table.
As required, create a query that aggregates data from the two tables.
Also some devices do not have tag names so we would want to avoid the
"" Case.
In Access, the concept of an empty string ("") is different from the concept of a true blank or 'null'. As such, it would be a good idea to replace all empty strings (if there are any) with nulls -
UPDATE MyTable SET TagName = Null WHERE TagName = '';
You can then set the TagName field's Allow Zero Length property to False in the table designer.
Also moving forward into the future I have added more columns to the
database to allow for more information to be retrieved
Think less in terms of more columns than more tables.
I assume that this will have to be done with VBA of some sort to modify records
Either VBA, SQL, or the Access query designers (which create SQL code behind the scenes). In terms of being able to crunch through data the quickest, SQL is best, though pure VBA (and in particular, using the DAO object library) can be easier to understand and follow.

Generate unique name everytime like "Windows folder structure" behaviour

I want to create folder structure logic like windows.I am using SQlite database for that. I want to generate a unique name everytime. For e.g. if user enters text with name "New". And if again he enter same name "New" then it should be New(1). if again he enter same name "New" then it should be "New(2)". If user delete "New(1)" entry and enter "New" then "New(1)" should be placed in between "New" and "New(2)".
Could anyone suggest logic for that? Any help is appreciated?
Thanks in advance
Tejas
I consider you will have a database with id and foldername as fields. You just need to retrieve all records from database. In where of query use like operator. Once you get list go in a loop and add add new entry by comparing number. Try this.
Here's the logic I use to do something similar in an app:
Declare an NSString called prefix and an NSInteger called number.
Check if your name has a number on the end of it:
If it does, set number to the value of that number and prefix to the name without the number.
If it does not, set number to 1 and prefix to the name.
Loop from 1 up to some maximum number, doing the following:
Construct a proposedName from base and number:
If number is 1, use the bare prefix.
Otherwise, concatenate the prefix and number in the format you're looking to generate.
Check if proposedName is already in use.*
If it is in use, increment number and loop again.
If it is not in use, proposedName is your new name.
Given that you're using a SQLite database, you can probably speed this up a bit by pre-fetching names that begin with your prefix and loading them into an NSMutableSet. That'll be faster than performing a query for each individual name.
* When you do this test, you should probably exclude the object you're already looking at. This will allow you to try to "uniquify" the name of an existing object without actually changing it.

Placing variable number of variables into fields in table

I am trying to make a generic notInList function that is called when the user types a value in a combobox that is not part of the list. In middle of that function, I want to insert the new value(s) into a table.
For some of the combo-boxes, more than one field has to be filled out in the table. (The user is asked a follow-up question about the not-in-list value, and the answer to the follow-up also has to be put into the table). The values that have to be inserted in the table are stored in variables in the code.
The way I have been dealing with this so far is through a table that has one record for each combo-box id, field, and variable name (the name of the variable that contains the value to be inserted into the field) combination. The code loops over all the records that relate to this combo-box and builds one list of field names and one list of variable names to be used in a SQL statement (Insert...values...).
However, I can't figure out how to use the name of the variable (retrieved from the table) to get the value stored in the variable. AddVar is the column in the recordset that contains the name of the variable I am trying to get the value of. I tried eval(rs!AddVar) but that doesn't work.
I am able to get the name of the variable from the table, but then I am stuck. How can I get the value (a string) stored in that variable?
You might be interested in the Dlookup() function. Basically, you just pass it a field name, a table name, and some optional criteria, and it will give you the first result it finds.
Consider the example:
=DLookUp("[LastName]", "Employees", "[EmployeeID] = 7")
This will go into the "Employees" table, find the first record where "[EmployeeID] = 7", and return to you the [LastName]. Hope this helps.
http://support.microsoft.com/kb/208786