as P = Index_Primary_Put([C tagname|P index])
as P = Index_Primary_Put( index_object_pointer as P )
Pointer to an index.
The name of an index or a query.
Set the primary index for the table, using either name or Index object.
The .INDEX_PRIMARY_PUT() method sets the primary index for a table referenced by to the specified index tag or query list. You can specify the index tag name, or the query list using either a pointer, or the tag/query list name. For example, the following statements are identical:
dim tbl as P tbl.index_primary_put("Lastname") indx = tbl.index_get("Lastname") tbl.index_primary_put(indx)
To set the primary index to record number order, you can use the .INDEX_PRIMARY_PUT() method without any arguments (e.g., TABLE.INDEX_PRIMARY_PUT(), or you can use the <TBL>.INDEX_RECORD_GET() method. If a query list and an index have the same name, this method will choose the index, not the query list. If you specify a Tag_Name that does not exist, Alpha Anywhere will choose the closest matching Tag_Name that has the same first letter as the Tag_Name you specified. If there is no Tag_Name with the same first letter, Alpha Anywhere will generate an error message. Note : If you set the index with .INDEX_PRIMARY_PUT()
tp = table.open("MyTable") tp.index_primary_put("Last_name_")
but there is no index named Last_name_ and there is an index named Labor_ID_ (same first letter), the system will set the index to Labor_ID_ without warning you.
This statement sets the primary index of the current table to record number order:
dim tbl as P tbl = table.current() indx = tbl.index_primary_put()
This script can be attached to a FIND button on a form to find a customer by last name.
dim tbl as P tbl = table.current() find_name = ui_get_text("Find","Enter person's last name:") indx = tbl.index_primary_put("Lastname") tbl.fetch_find(find_name) parent.resynch()
The following commands in the Interactive window indicate how Alpha Anywhere behaves if an index and query have the same name
dim t as P dim i as P t = table.open("customer") i = t.index_primary_put("customer") ? i.type_get() = 2.000000 'indicates that an index is active. query.description = "customer" query.filter = ".T." i = t.query_create() ? i.type_get() = 6.000000 'indicates that a query list is active i = t.index_primary_put("customer") ? i.type_get() = 2.000000 'indicates that an index is active
Assume that a table has tags called customer_id, lastname and zip.
i = t.index_primary_put("Customer_Id") ? i.name_get() = "Customer_Id" i = t.index_primary_put("Firstname") ERROR: Tagname not found. (because no index tag has name starting with "F") i = t.index_primary_put("L") ? i.name_get() = "Lastname" (because first letter matches "lastname" tagname) i = t.index_primary_put("zop") ? i.name_get() = "Zip" (because first letter of "zop" matches "zip" tagname)
The following example finds the maximum field value in a character field.
dim idx as P dim tbl as P dim last_city as C tbl = table.open("customer") table.index_create_begin("City", "ship_city") table.index_add("city", "ship_city") idx = table.index_create_end("city") table.index_primary_put("city") tbl.fetch_last() last_city = tbl.Ship_city ? last_city = "Newburyport"