Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how systemId is being used. 1

Status
Not open for further replies.

tripp2222

Technical User
Nov 30, 2004
32
US
I am new to VPF and just trying to understand how to read the code.

lnSelect = SELECT() && Store alias number to variable

SELECT Systemids
SET EXACT ON

LOCATE FOR UPPER (ALLTRIM (tTablename))=UPPER (ALLTRIM (Systemids.tablename))
IF NOT FOUND ()
APPEND BLANK
LOCK()
REPLACE Systemids.tablename WITH tTablename
lIDValue=Systemids.idvalue
lIDValue=lIDValue+1
REPLACE Systemids.idvalue WITH lIDValue IN Systemids
UNLOCK IN Systemids
 
This appears to be a simple way to maintain a unique value (primary key?) for any table. If the table requested is found (in the tablename field), then the idvalue is increased by one. If the table name isn't found a new record is added, and then a new idvalue of one is returned.

I assume that the rest of the code is something like:
Code:
  IF NOT FOUND ()
        APPEND BLANK
        LOCK()
            REPLACE Systemids.tablename WITH tTablename
            lIDValue=Systemids.idvalue
            lIDValue=lIDValue+1
            REPLACE Systemids.idvalue WITH lIDValue IN Systemids
        UNLOCK IN Systemids [red]
  ELSE
        LOCK()
            lIDValue=Systemids.idvalue
            lIDValue=lIDValue+1
            REPLACE Systemids.idvalue WITH lIDValue IN Systemids
        UNLOCK IN Systemids 
  ENDIF[/red]

For a similar routine see the NextID routine in the sample code, or for more information, see Craig's "Primary Keys -
Concepts behind a primary key and code you can use to create and maintain them." article at
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top