Sort column

6 posts / 0 new
Last post
leandrorezende
Offline
Joined: 04/06/2017 - 13:44
Sort column

Hi.
I need to search through a column at an IDEA base by a value. In order to easy my work, I would like to sort this column first, the same way when you create an index just by clicking at the header of the column.
My question, is there a way to create an "Index" using ideascripting or any other way to sort the columns's rows?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi leandrorezende,

There are two ways to sort an IDEA file, the first and probalby most popular is the Index, this allows you to index up to 8 columns in the order you decided.  An index is attached to the file being indexed.  You can also perform a sort that recreates the file but in the order you have selected, again you can select up to 8 columns to sort on.

Here are some example scripts for performing an index and sorting on a file.


Function IndexDatabase
	Set db = Client.OpenDatabase("My File.IMD")
	Set task = db.Index
	'can add up to 8 columns (keys)
	task.AddKey "COLUMN A", "A" 'A is for ascending
	task.AddKey "COLUMN B", "D" 'D is for descending
	task.AddKey "COLUMN C", "A"
	task.Index FALSE 'Set to true if you want to reindex
	Set task = Nothing
	Set db = Nothing
End Function

Sorting example


Function SortDatabase
	Set db = Client.OpenDatabase("My File.IMD")
	Set task = db.Sort
	'can add up to 8 columns *keys)
	task.AddKey "COLUMN A", "A" 'A is for ascending
	task.AddKey "COLUMN B", "D" 'D is for descending
	dbName = "Sorted database.IMD"
	task.PerformTask dbName
	Set task = Nothing
	Set db = Nothing
	Client.OpenDatabase (dbName)
End Function

If you are reading through an entire file record by record you can also use an index.  This is a bit more technical so let me know if you want that information also.

Brian

leandrorezende
Offline
Joined: 04/06/2017 - 13:44

Thanks Brian for helping me!
With your answer I can already compleaty my task. But as you mentioned another solution, maybe this one is even better, I don't know if it matchs perfectly with my situation.
My goal is only find if there is duplicated records at one column.
So, if you think it's usefull, I would be gratefull to hear

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi leandrorezende, I am just wondering, since you are looking for duplicate why you aren ot using the duplicate key detection?  This will pull off all the transactions that have duplicates within your selected column (you can select up to 8 columns to perform the duplicate test on).

leandrorezende
Offline
Joined: 04/06/2017 - 13:44

It's because this logic of compare by duplicate records is a short cut for the real goal of task, that will optimize my process. Anyway, it is a little hard to explain, but what i know so far is that the duplicate key detection doesn't do the same efect.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Ok, let me know if I can help anymore.  Also if you want to message me with more information please feel free.