AMT Help Files

File Functions

The following functions and properties can be used for text files.

Function/Property Description

ACCESSEDDATE

Returns the date when the file has been last accessed (readonly). The returned value is a numeric with the length 8 in the date format "yyyymmdd".

Use:

to place (for instance) the returned ACCESSEDDATE value in the specified variable:

<Variable> := <File id>.ACCESSEDDATE

ACCESSEDTIME

Returns the time when the file has been last accessed (readonly). The returned value is a numeric with the length 6 in the date format "hhmmss".

Use:

to place (for instance) the returned ACCESSEDTIME value in the specified variable:

<Variable> := <File id>.ACCESSEDTIME

ADDREC

Adds a record to an index or relative io file. It is not allowed to use the same <File id> both for this function and for a READFILE and/or WRITEFILE instruction at the same time.

Use:

<File id>.ADDREC (<Record layout>)

APPEND

Normally in a transaction the first call to the WRITEFILE command will overwrite an existing file with the same filename. If this first call is preceded by a call to <File id>.Append() this first call to WRITEFILE will append the record to an existing file. If no file exists beforehand the file will be created normally.

Use:

<File id>.APPEND ([Exclusive])

EXCLUSIVE Keep the file open 

Since the file will not be opened and closed perpetually when it is accessed, this statement improves the performance. Though, using this option also means that the concerned file cannot be used for other processes at the same time.
 

CLOSE

Closes the file.

It is recommended to use this option for closing a file before calling it inside the logic. The reason why you should do this is that that file might be in use (by another object/ end user/ ...), which would cause sharing conflicts.

Use:

<File id>.CLOSE (<Option>)

<Option> = <Space> | SAVE | DELETE | RENAME, <New file> | LOCK

<Space>

Save the file.

SAVE

Save the file.

DELETE

Delete the file.

RENAME

When closing the file, it will be stored as <New file>.

<New file>

New name to be assigned to the file.

 LOCK

Locks the file until the program has finished, and also flushes this file to disk (so that if there might be a crash the data won't be lost).

If the report crashes, and this report also contains a SAVERECOVERY, the file will be unlocked automatically.

 

CONTAINSCOMP

Forces the sort routine to treat the file as computational (reading a fixed number of bytes).

Use:

<File id>.CONTAINSCOMP ()

COPYFILE

Copies the file contents to the <Destination>.

Use:

<Fileid>.COPYFILE (<Destination>)

<Destination>

Expression that contains the path for the file to which the copy of the file that is specified through the <File id> must be assigned.
Nonexistent directories in the path will be created during the COPYFILE execurtion.

 

CREATE

Creates an empty file. If there is already a file with the same file name, then that file will be deleted.

Use:

<File id>.CREATE ([EXCLUSIVE]|[TEMP]) [RESULTOKTO <Result>]

EXCLUSIVE

Keep the file open.

Since the file will not be opened and closed perpetually when it is accessed, this statement improves the performance. Though, using this option also means that the concerned file cannot be used for other processes at the same time.

TEMP Create a temporary file.

A temporary file will be created with the filename set to the filename of the <FileId> used to wich a unique number has been added. The file will be created Exclusive and remain open for changing. When closed with <FileId>.Close() the temporary file will be deleted. When close with <FileId>.Close(SAVE) the file will be saved using the original filename of <FileId> overwriting any existing file with that name.

RESULTOKTO <Result>

Stores the ResOk result in the variable <Result>. 

 

CREATEDDATE

Returns the date when the file has been created(readonly). The returned value is a numeric with the length 8 in the date format "yyyymmdd".

Use:

to place (for instance) the returned CREATEDDATE value in the specified variable:

<Variable> := <File id>.CREATEDDATE

CREATEDTIME

Returns the time when the file has been created (readonly). The returned value is a numeric with the length 6 in the date format "hhmmss".

Use:

to place (for instance) the returned CREATEDTIME value in the specified variable:

<Variable> := <File id>.CREATEDTIME

CURRENTRECNO

Stores the current record number.

Use:

To move the last record that is read from the file to a <Variable>:

<Variable> := <File id>.CURRENTRECNO

DELETEFILE

Deletes the file.

Use:

<Fileid>.DELETEFILE ()

DELETEREC

Removes the current record from an indexed or relative IO file. The record will not be removed physically, but it will be set to SI-HIGHVALUE (ASCII 255). For a search through an index there will not be any results returned.

It is not allowed to use the same <File id> both for this function and for a READFILE and/or WRITEFILE instruction at the same time.

Use:

<File id>.LOCATE (<Index>, <Operator>, <Value>) | <File id>.LOCATE (POSITION, <Record no>)
<File id>.READ (<Layout> [, <Layout>])
<File id>.DELETEREC ()

EOF

Returns a boolean value that indicates whether the end of the file is reached (TRUE) or not (FALSE). The value changes from "FALSE" to "TRUE" when an attempt is made to read behind the last record in the file.

Use:

<File id>.EOF

EXISTS

Returns a boolean value that indicates whether the file exists (TRUE) or not (FALSE).

Use:

<File id>.EXISTS

FILENAME

Returns the current filename as a String value..

Use:

<File id>.FILENAME

GETFILECONTENT

Returns the total file content as a Realstring value as is. No conversion of any kind is perfomed on the content.

Use:

to place (for instance) the returned file content into the variable that is specified as <Destination>:

<Destination> := <Fileid>.GETFILECONTENT

GETFILESIZE

Returns the size of the file as an integer. When the file is not found -1 will be returned.

Through this function it is possible to check for instance if a file is (still) growing.

Use:

to place (for instance) the returned file size into the variable that is specified as <Destination>:

<Destination> := <File id>.GETFILESIZE

ISLOCKED

Returns "TRUE" if the file is currently locked or "FALSE" if the file is not locked.

Use:

<File id>.ISLOCKED

ISOPEN

Returns a boolean value that indicates whether the file is currently opened (TRUE) or closed (FALSE).

Use:

<File id>.ISOPEN

LOCATE

Searches for a record in the file. It will also set the system item RESOK ("TRUE" if the record was found). The record will not be placed into a buffer, but there will be an update of the property .CURRENTRECNO.

It is not allowed to use the same <File id> both for this function and for a READFILE and/or WRITEFILE instruction at the same time.

In case of indexed files with indexes with multiple key the .LOCATE command must also contain multiple keys. The number of keys and order of keys in the .LOCATE command must match the number and order of keys in the index.

Note: Older migrated code used a different syntax than described below which only allowed a single key, this older syntax required the operator to be entered in single quotes as a string literal. <File id>.LOCATE(<Index>, <Operator>, <Value>)

Use:

for indexed files:

<File id>.LOCATE (<Index>, <Operator> <Value>[, <Operator> <Value>[, ... ]])

<Index>

The name that is specified as identifier for the index.

<Operator>

One of the characters "<", "<=", "=", ">" or ">=" to be entered without quotes.

<Value>

The value to search for in the file

Examples:  Fid.LOCATE(Index_firstname, = 'Joanneke')
Fid.LOCATE(Index_customer, = 'Joanneke', = 'de Vrijer')  

for relative files:

<File id>.LOCATE (POSITION, <Record no>)

<Record no>

The record number. The record number for the first record is "1".

LOCKREC  Locks an individual record within a file.
Use: 
<File id>.LOCKREC (<Record no>) 

<Record no>

The record number to lock. The first record in the file is number "1". 
 

MODIFIEDDATE

Returns the date when the file has been modified (readonly). The returned value is a numeric with the length 8 in the date format "yyyymmdd".

Use:

to place (for instance) the returned MODIFIEDDATE value in the specified variable:

<Variable> := <File id>.MODIFIEDDATE

MODIFIEDTIME

Returns the time when the file has been modified (readonly). The returned value is a numeric with the length 6 in the date format "hhmmss".

Use:

to place (for instance) the returned MODIFIEDTIME value in the specified variable:

<Variable> := <File id>.MODIFIEDTIME

MOVEFILE

Moves the file to the <Destination>. In difference with the COPYFILE function, the file that is specified in the <File id> will not be retained in its original location.
If there is already a file with the same name in <Destination>, it will get overwritten.

Use:

<File id>.MOVEFILE (<Destination>)

<Destination>

Expression that contains the new path for the <File id> file.

 

OPEN

Opens the specified file for reading.

Use:

<File id>.OPEN ( [NOWAIT] [,] [EXCLUSIVE] )

NOWAIT

Continue when the file is not present.

EXCLUSIVE

Keep the file open.

Since the file will not be opened and closed perpetually when it is accessed, this statement improves the performance. Though, using this option also means that the concerned file cannot be used for other processes at the same time.

READ

Reads 1 line in the file and queues that line in a <Layout>. If there is no index specified, the records are read in the order in which they were entered.

It is not allowed to use the same <File id> both for this function and for a READFILE and/or WRITEFILE instruction at the same time.

Use:

To read in the order in which the records are entered:

<File id>.LOCATE (<Index>, <Operator> <Value>) | <File id>.LOCATE (POSITION, <Record no>)
<File id>.READ (<Layout> [, <Layout>])


Example:

To read all records and write them to a second file:

File_rel.create ()
File_cust.open ()
loop

    File_cust.read (Rec_customer)
    if not File_cust.eof
        File_rel.addrec (Rec_customer)
    else
        File_rel.close ()
        File_cust.close ()
        break
    endif
endloop
READMODE

With readmode the reading behaviour of the READFILE command can be changed.
In cases where AMT does not determine the correct record length for a text file, the read mode can be set to either always read the file by record size or set to read the file by the record ending character(s) (e.g. CR/LF) of the file id. To change the readmode of a file id, assign either a 0, 1 or 2 to the readmode propery of a file id. 

Note: readmode does not support files that have a file record ending of 'None' set.  

  • 0 = Fixed: Read the file by record size.
  • 1 = Dynamic: Read the file by the record ending character(s) set for the file id.
  • 2 = FindOut: Default, let AMT determine the read mode.
Use:

<File id>.READMODE := <0|1|2>

Example: File_cust.readmode := 1
 

SETFILECONTENT

Writes the content value to the file. If the file already exists then it will be replaced.

Use:

<File id>.SETFILECONTENT (<Content>)

<Content>

Expression (Realstring) that represents the content that must be written to the file.

 
STOREREC This commands perfoms a normal UpdateRec () command except when the filepointer is at the end of the file. In that case it will perform the AddRec () command and add e new record to the end of the file.
Use:
<File id>.STOREREC (<File record>)

<File record> 

The record to store in the file .
 
UNLOCKREC  Unlocks a previous locked record in a file. 
Use: 
<File id>.UNLOCKREC (<Record no>) 

<Record no> 

The record number of the previously locked record to unlock.
 

UPDATEREC

Updates the current record in an indexed or relative IO file.

It is not allowed to use the same <File id> both for this function and for a READFILE and/or WRITEFILE instruction at the same time.

Use:

<File id>.UPDATEREC (<File record>) 

<File record> 

The record to write in the file