Version (internal function): Difference between revisions
(edit) |
No edit summary |
||
Line 37: | Line 37: | ||
The above code would convert a data file from whatever version the data file was to the most current. Whenever a file layout is changed, you would simply add the conversion routine to the end of this program. | The above code would convert a data file from whatever version the data file was to the most current. Whenever a file layout is changed, you would simply add the conversion routine to the end of this program. | ||
<noinclude> | |||
[[Category:Internal Functions]] | |||
</noinclude> |
Revision as of 16:56, 18 January 2012
The VERSION function returns or optionally resets a file version number for the opened file number specified. This feature allows you to Verify that data files have been updated to match the current program release.
The filenbr parameter represents the number of an open internal file. If the file is not an internal file or the file is a key file opened as an internal file, a 0721 (I/O conflicts with OPEN) error will result.
The new version parameter can be used to reset the version number of the specified file. When newversion is specified, the file must be opened for OUTIN or a 0721 error will result. The newversion number is not written to the disk until the file is closed. The newversion specified can be any number from 0 to 32000.
File VERSION capacity was increased to allow use of dates as version numbers.
The VERSION function is designed to be used in conjunction with the VERSION= parameter for OPEN internal statements. VERSION= should be used to set the version number on newly created data files and to trap situations where the data files are not current for the program being run. This would stop the program from processing faulty data before any data could be processed. It is up to the programmer to maintain the version numbers in the programs.
Not every program should check for version numbers, as every time the version changed, all the VERSION= parameters would need to be changed. Posting and file maintenance programs would be the most likely candidates to use VERSION=.
The VERSION function is intended to be used in a "data file update program." The update program should contain code to convert each successive version. For example:
00100 OPEN #1:"NAME=CUSTOMER.DAT",INTERNAL,OUTIN 00110 IF VERSION(1)=1 THEN ! record length increased for C 5 00120 CLOSE #1: 00130 EXECUTE "COPY CUSTOMER.DAT WORK[WSID] -160 -N" 00140 EXECUTE "FREE CUSTOMER.DAT -N" 00150 EXECUTE "RENAME WORK[WSID] CUSTOMER.DAT -N" 00160 OPEN #1:"NAME=CUSTOMER.DAT",INTERNAL,OUTIN 00170 LET VERSION(1,2) ! update to version 2 00180 LET CUSTOMER=1 ! Changed flag 00190 END IF 00200 IF VERSION(1)=2 THEN ! change field length 00210 RESTORE #1: 00220 FORM1: POS 80,C 10,C 3 ! C 3 was C 5 00230 FORM2: POS 80,C 12,C 3 00240 LOOP1: READ #1,USING FORM1: A$,B$ EOF ENDLOOP1
00250 REWRITE #1,USING FORM 2: A$,B$ 00260 GOTO LOOP1 00270 ENDLOOP1: VERSION(1,3) ! update complete to version 3 00280 LET CUSTOMER=1 00290 END IF 00300 IF CUSTOMER THEN PRINT "CUSTOMER.DAT UPDATED TO CURRENT VERSION."
The above code would convert a data file from whatever version the data file was to the most current. Whenever a file layout is changed, you would simply add the conversion routine to the end of this program.