Version (internal function)

From BR Wiki
Jump to navigation Jump to search

The Version internal function affects an open internal data file. It will return the version of that file. It can also be used to set the version.

Syntax

To read the version of an open internal file:

VERSION(<file_handle>)

To set the version of an open internal file:

VERSION(<file handle>[,new-version])

The file-handle parameter is 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 new-version is specified, the file must be opened for OUTIN or a 0721 error will result. The new-version number is not written to the disk until the file is closed. The new-version specified can be any number from 0 to 32000.

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 format change program." The change 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.