Tech Tip - Reading/Writing OS files

Reading and writing OS files is very important in the new hybrid systems we have to write these days. Most of our applications are pretty self-contained,and don't need to interact with programs or applications outside the MV environment. But that is slowly changing.

We now have e-mail sending programs, printer overlay programs, SQL Command lines, and many, many other applications that use OS files. The need to read/write OS files continues to go up, and each programmer does it differently.

If you don't already do this on your own, we have compiled some SUBROUTINE (Stored Procedures) that will make it easier for you. If you already read and write OS files, then these subroutines will provide you with a comparison.

Since each MultiValue database implements writing to OS files differently, you have some options to choose from. It also makes it difficult to implement a common set of subroutines without creating limitations.

The major limitation of these subroutines is that they load the complete record into memory. This is not a problem with small OS files, but if you are working with large file (3MB, 4MB, or 10MB), it can become a problem. In these cases you will have to implement a means of reading and writing chunks from the file.

The general syntax for these subroutines is shown in figure 1. You'll notice in the example (fig. 2) that the directory is based on LINUX/UNIX file system structures. If you are writing windows files, you will need to us Windows file systems structures.

SUBROUTINE IS.READ.OS(DIRECTORY,DATA.ITEM,FILE.NAME,ERROR.ITEM)
DIRECTORY = the path/directory location in the OS file system to read the information from
DATA.ITEM = the information from the file with CR:LF/LF Replaced with AM
FILE.NAME = File name, without the DIRECTORY information.
ERROR.ITEM = Information about errors when reading the file
    <1> = 0 - Successful
    <1> = 1 - Item Not Found
    <1> = 2 - Access Denied
    <1> = 99 - Unknown Error


SUBROUTINE IS.WRITE.OS(DIRECTORY,DATA.ITEM,FILE.NAME,ERROR.ITEM)
DIRECTORY = the path/directory location in the OS file system to Wite the information to.
DATA.ITEM = the information for the file with AM.  AM will be replaced with CR:LF/LF
FILE.NAME = File name, without the DIRECTORY information.
ERROR.ITEM = Information about errors when reading the file
    <1> = 0 - Successful
    <1> = 1 - Item Not Found
    <1> = 2 - Access Denied
    <1> = 99 - Unknown Error

Fig. 1

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("/temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
END
Fig. 2

To access the code, go to the following link:

http://www.intl-spectrum.com/s/19xS1 IS

Do you have a Tech Tip to share? E-mail it to editor@intl-spectrum.com

NATHAN RECTOR

View more articles

Featured:

May/Jun 2011

menu
menu