Omnis Technical Note TNDF0002

Segment Issues with Omnis data files

for Omnis 7 and Studio
by Rudolf Bargholz and Tom Hume

Introduction
Notation [$root.$datas.]DATAFILE.$slots.SLOTNAME.Attribute

A datafile can consist of up to fifteen separate files called segments, each of which can be up to 256 megabytes. To add a new segment use DATAFILE.$segments.$add(path,size) where size is the number of bytes required (e.g. 512000 to add one segment).

Properties

Property Description
$pathname path name of the data file segment on disk
$disksize total disk size of the data file segment in bytes

Segment Related FAQs

Q1. How do I extend the Datafile?
A1. The DF1 is automatically extended, i.e. the number of blocks in the DF1 will grow to a maximum of 512000 blocks, which is about 256 MB. From the second segment onwards the blocks are not automatically extended. You have to do this manually. Another point to note is that no segments are created automatically. This also has to be done by hand. You can either use the 'Utilities/Data File Tools/Examine Data File' and then the menu 'Data file/Change Data File Size' to add a new segment and increase the number of free blocks in that segment. Remember that creating a new segment will not create enough free blocks, so you will always need to create a new segment AND create new free blocks. Another option is to use notation to create a new segment and to increase the number of free blocks in the datafile:

Increasing the number of free blocks:

Test for only one user
or
Calculate #F as $cdata.$shared.$assign(kFalse)
If flag true
  If $cdata.$freesize<1000000 ;less than 1 MB free space
    Yes/No message (Do you want to expand the datafile ca 1MB ?)
    If flag true
      Calculate %DATAFILESIZE as $cdata.$disksize
      Calculate $cdata.$segments.1.$disksize as %DATAFILESIZE+2000
    End if
  End if
End if
Calculate #F as $cdata.$shared.$assign(kTrue)

Adding a New segment:

Calculate #F as $cdata.$shared.$assign(kFalse)
If flag true
  Set reference REF to
      $cdata.$segments.$add(path_to_datafile,512000)
End if
Calculate #F as $cdata.$shared.$assign(kTrue)
; creates a new segment with the maximum size of ~256 MB

Note the 'Test for only one user' command. The above methods will only work if you are the only user logged on to the datafile. If you are not, a Flag false will be returned and the code will not be executed.

You must remember to set the working directory to the path of the DF1:
1) before adding new blocks,
2) before creating a new segment, and
3) before logging on to the datafile

You can use the 'Change working directory {Path}' command to ensure that Omnis will find any other segments.
The above code will work for both Omnis 7 and Omnis Studio. A small tip for Omnis 7, the line of code:
Calculate #ER as 12400
will install the 'Data file' menu which is needed to open the 'Change Data File Size' window.

Q2. I had a datafile that consisted of two segments but the second segment was accidentally deleted. Now when I try to access my data it will not allow me into the datafile because Omnis cannot locate the second segment. Is there anything I can do to get my data back?
A2. The way to gain access to the datafile is to create a brand new datafile with a different name. Then with this new datafile you add a second segment. When you have done this you then quit out of Utilities and return to the desktop. The new datafileÕs second segment is then renamed to correspond to your original datafile. For example, if your original datafile is called STOCK, you would create a new datafile with the name STOCK2.DF2 which you rename to be STOCK.DF2. It is then possible to delete STOCK2 and you will be able to use your original datafile without any problem. You may lose some of your records depending on how many were placed in the original second segment.

Q3. I recently segmented a data file and now when users start up the Omnis application it always prompts them for the data file.
A3. You will need to ensure that Set Omnis= 'path to the segment folder' is in your autoexec.bat file and that the path is also set.