home *** CD-ROM | disk | FTP | other *** search
- PROCEDURE MAKETABL
- *****************************************************************************
- * SYNTAX: DO MAKETABL WITH "Alias", "Key", "TABLE-FILENAME" *
- * AUTHOR: Thomas G. Pantazi *
- * VERSION: 1.2 *
- * LAST MOD: 7/1/87 - TGP *
- * *
- * PURPOSE: Create a table of every unique 'Key' in a database. This is *
- * frequently necessary when doing data entry validation. *
- * *
- * MEMVARS: Alias - The Alias name assigned to the work area containing *
- * the USEd database to be searched. *
- * Key - The field name to be searched. File is not required *
- * to be indexed, but if it is the index is assumed to *
- * be opened. Each INDEXKEY is checked to find a match. *
- * if no match is found an index is created. *
- * TablName - The name to be given to the result database. *
- * *
- * NOTES: This routine uses work area number 10, therefore if you have *
- * files open in this area, you should modify the work area used *
- * here. It is also assumed that you will reopen any indices that *
- * were open prior to execution of this routine. *
- * *
- *****************************************************************************
-
- PARAMETERS Alias,Key,TablName
- KeyName = Key
- KeyField = &Alias->&Key
- KeyLen = LEN("KeyField")
- KeyType = TYPE("KeyField")
- KeyFound = .F.
- I = 1
-
- SELECT &Alias
- DO WHILE .NOT. KeyFound
- IF INDEXKEY(I) = ""
- INDEX ON &Key TO TEMP$$$$
- KeyFound=.T.
- ENDIF
- IF INDEXKEY(I) = Key
- KeyFound=.T.
- SET ORDER TO I
- ENDIF
- I = I + 1
- ENDDO
- SELECT 10
- CREATE TABLE$$$
- APPEND BLANK
- REPLACE FIELD_NAME WITH "&KeyName", FIELD_TYPE WITH KeyType, FIELD_LEN WITH KeyLen
- USE
- CREATE &TablName FROM TABLE$$$
- SELECT &Alias
- MKey=&Key
- DO WHILE .NOT. EOF()
- DO WHILE MKey = &Key
- SKIP
- ENDDO
- SELECT 10
- APPEND BLANK
- REPLACE &Key WITH MKey
- SELECT &Alias
- MKey = &Key
- ENDDO
- DELETE FILE TABLE$$$.DBF
- SELECT &TablName
- USE
- SELECT &Alias
- RETURN
-