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

You are a genius and I have no excuse for not thinking of this before calling. Our customer is good with cutting the tops and bottoms for the booklets to get under 16 ounces. Thank you for getting me out of a jam and thank you even more for offering your help with this project! I decided to switch to AccuZIP after speaking with Steve at the Minuteman Show. I was impressed with his idea of customer service and you have totally proven him right.
M.M., Petaluma, CA