Using Extract File Built-in Methods

Agile Business Suite provides the user with a number of extract file built-in methods for explicit file handling capability. The open method sets the category for the file, if the name parameter is used. The close method can be used to retain or discard the extract file regardless of the extract file’s category.

Refer to the Agile Business Suite Programming Reference Manual for more information on these methods.

Open Method

Invocation of the <glbfile>.open() method is a means of opening the file explicitly. There are three modes:

If the name parameter is blank when the <glbfile>.open() method is invoked for the first time, the category of the extract file is set to TEMPORARY. For example, this opens a temporary extract file in Write mode.

x.open("",1)

The exception to this is when the SetTitle command has been used or the file name has been assigned to the <glbfile>.Name built-in attribute. For example, this opens a permanent extract file called NEWFILE.

SetTitle <glbfile> "NEWFILE" 
x.open("",1)

Another exception to this is when the extract file has been file equated. If the extract file has been file equated, the invocation of the <glbfile>.open method is the same as when the name parameter is not blank. (Refer to File Equates).

If the name parameter is not blank when the <glbfile>.open() method is invoked, the category of the file is set to EXISTING for the Read and Append modes, and set to PERMANENT for the Write mode. The extract file is assigned the file name that was passed by the name parameter. For example, this opens an existing extract file called OLDFILE for reading.

x.open("OLDFILE",0)

If the name parameter is blank on subsequent invocations of the <glbfile>.open() method, the previous file name is used. In the next example, the final invocation of the <glbfile>.open() method opens NEWFILE for reading.

x.open("NEWFILE",1)
x.close(true,false)
x.open("",0)

If you are using file equates with your extract files and you want to retain them on termination of the report, use the <glbfile>.open() method with a blank name parameter to open the extract files. The name parameter must be blank to avoid overriding the file equated title. Code generated at the beginning of the report checks for file equates and passes filename from the file equate to the open method to be used as the name parameter.

Here are some examples of opening an extract file that has been file equated:

x.open("",0)

In this example, the file equated extract file is opened in read mode. The extract file is treated as existing.

x.open("",1)

In this example, the file equated extract file is opened in write mode. Any existing file is overwritten.

x.open("",2)

In this example, the file equated extract file is opened in append mode. The extract file is treated as existing.

Use the Open method with Read mode to check for the existence of a file. If the Open method was unable to open the file, it will set GLB.STATUS to “*****”.

x.open(“OLDFILE”,0)
If glb.status = glb.spaces
      Determine Actual x
            TotalAmount := TotalAmount + x.frame1.amount
      End   
Else   
      sm odt “OLDFILE does not exist”
End

Note: Do not use the SetTitle command with file equated extract files. It overrides the title that was file equated.

Close

Invocation of the <glbfile>.close() method is a means of closing the file explicitly. The extract file is closed as directed by the parameters, regardless of the extract file’s category. However, if you retain a temporary file, report termination processing still discards the file.

There are two parameters to the <glbfile>.close() method:

Retain

When true, retains the external file after the file closes.

Purge

When true, purges the contents of the external file when it closes.

To close a file and retain it, invoke the <glbfile>.close() method with the Retain parameter set to true and the Purge parameter set to false. For example,

x.close(true,false)

To close a file and discard it, invoke the <glbfile>.close() method with the Retain parameter set to false and the Purge parameter set to true or false. For example,

x.close(false,false)