Closes a file that has been opened by the OPEN Function (File).
- Type: File Specifies the file.
If the file is not open, a run-time error will occur.
The following example determines whether the specified file exists. If it exists, the WRITEMODE Function (File) allows the file to be open for writing. The OPEN Function (File) opens the file, the WRITE Function (File) writes the text “Hello World” to the file, and then the CLOSE function closes the file. If the file does not exist, an error message is displayed. This example requires that you create the following variables in the C/AL Globals window. This example assumes that you have created the following file C:\TestFolder\TestFile2.txt.
FileName := 'C:\TestFolder\TestFile2.txt'; IF EXISTS(FileName) THEN BEGIN TestFile.WRITEMODE(TRUE); TestFile.OPEN(FileName); TestFile.WRITE('Hello World'); TestFile.CLOSE; END ELSE MESSAGE('%1 does not exist.', FileName);