Support 805.461.7300
Sales
Our Technology. Your Success.

Add a field to the beginning of a database

*********************************************
comNewFieldName="newfield"
comNewFieldSize=10
comNewFieldType="C"

*********************************************
*Get current database path
comDatabasePath=DBF()
*Construct New Field
comFieldString=comNewFieldName+" "+comNewFieldType+"("+allt(STR(comNewFieldSize))+")"
*Create temporary working file
comTempDbf1=FORCEEXT("t"+SUBSTR(SYS(2015),2),'dbf')
comTempDbf2=FORCEEXT("t"+SUBSTR(SYS(2015),2),'dbf')
*Make copy of current database structure
COPY STRUCTURE EXTENDED TO (comTempDbf1)
*Open structure database
USE (comTempDbf1) ALIAS "_stucture"
*Add new field
ALTER TABLE "_stucture" ADD COLUMN recnum N(3)
REPLACE ALL recnum WITH RECNO()
*Add blank record to structure database
APPEND BLANK
REPLACE field_name WITH comNewFieldName, field_type WITH comNewFieldType, field_len WITH comNewFieldSize
*Write new structure with new field at top
SORT TO (comTempDbf2) ON recnum FIELDS EXCEPT recnum
USE (comTempDbf2) ALIAS "_stucture"
SELECT * FROM "_stucture" INTO ARRAY _newdatabase
USE
*Create new database
CREATE TABLE (FORCEEXT(comDatabasePath,"")+"t.dbf") FROM ARRAY _newdatabase
*Append records from original database
APPEND FROM (comDatabasePath)
*Close new database
USE
*Rename original database with unique name
RENAME (comDatabasePath) TO (FORCEEXT(comDatabasePath,"")+SYS(2015)+".dbf")
RENAME (FORCEEXT(comDatabasePath,"")+"t.dbf") TO (comDatabasePath)
*Cleanup
DELETE FILE(comTempDbf1)
DELETE FILE(comTempDbf1)
*Open new database as original database name
USE (comDatabasePath)

« Back to Commands

I have been working in pretty much all areas of senior-level IT and Data Processing for many years and have had countless hours of experience engaging with customer support. I’ve never had better support than what I receive from Accuzip! Seriously, any time I call, email, or go to the online chat, someone responds in less than a minute, is always very patient and pleasant, and resolves my issue quickly. Aside from just fixing the problem, your support team always takes the time to explain what the problem was and how to prevent it. It is very refreshing and encouraging to see that real support still exists. Thanks to the Accuzip Team!  I look forward to many more years of engagement with your Team.
M.M., Scottsdale, AZ