Entries in tabfile (2)

Tuesday
Jul292008

Adding a row to a tabfile table

The following code adds a row to an existing tabfile table:

CONNECT TABFILE updates FILENAME 'UPDATES.TBF' WRITE
PROGRAM
c
c program to access update details tabfile and addrow for the update being undertaken.
c
c write cohort, current database update level, date, time, user and update comment
STRING*140 COMMENT
COMPUTE UPDLEVELNOW=UPDLEVEL(0)
NEW ROW IS UPDATES.TABLE1 TUPDATE INDEXED BY UPDLEVDESC(UPDLEVELNOW)
. COMPUTE UPDDATE=TODAY(0)
. COMPUTE UPDID=SIRUSER('')
. COMPUTE COMMENT="Details of the data to be saved on the tabfile"
. PUT VARS UPDDATE UPDID COMMENT
END ROW IS
IFTHEN(SYSTEM(28) <>1)
. WRITE '*** ERROR IN WRITING TO UPDATES TABFILE - ROW NOT WRITTEN ***'
ENDIF
END PROGRAM
DISCONNECT TABFILE updates

We use a version of this program as a member, calling it everytime we do an update, providing us with a handy log of all our updates and schema modifications.

Tuesday
Jul292008

Creating tabfiles, tables and indexes in DBMS

We wanted to use a tabfile to keep a track of all our updates. So every update retreival or schema modify has a call to a member which updates a tabfile with details of the update, the retrieval etc and does a couple of checks to make sure we havent missed out an update level

Step One Create tabfile,

DROP TABFILE UPDATES
CREATE TABFILE UPDATES
FILENAME 'G:/DB/DATABASES/UPDATES/UPDATES.TBF'

Step Two Create tables and indexes

CREATE TABLE UPDATES.NCDS (UPDLEV INT, UPDDATE DATE ('DDMMMYY'), UPDID STRING (20) COMMENT STRING (140))
CREATE UNIQUE INDEX UPDLEVDESC ON UPDATES.NCDS (UPDLEV DESC)

This does not currently work (and should be fixed soon) a workaround (thanks to David Baxter for this) is:

PROGRAM
INTEGER UPDLEV
DATE UPDDATE ('DDMMMYY')
STRING*20 UPDID
STRING*140 COMMENT
PERFORM PROCS
SAVE TABLE UPDATES.NCDS REPLACE BOOLEAN (0)
END PROGRAM

CREATE UNIQUE INDEX UPDLEVDESC ON UPDATES.NCDS (UPDLEV DESC)