POS Function (File)

Gets the current position of the file pointer in an ASCII or binary file.

Position := File.POS

Parameters

  • File
    Type: file Use this variable to refer to the file.

Property Value/Return Value

Type: Integer

This show the current position of the file pointer in bytes.

Remarks

This function is often used with LEN Function (File) and SEEK Function (File).

Example

The following example opens a text file that is named C:\TestFolder\TestFile.txt. The WRITEMODE Function (File) enables the file to be open in write mode. The POS function retrieves the position of the file pointer and stores it in the Position variable. When the file is open, the position of the pointer is 0 because a pointer is not set. The SEEK Function (File) function sets a file pointer at position 5. After the SEEK Function (File) is executed, the POS function returns 5 as the file pointer position. This example assumes that you have created a text file named C:\TestFolder\TestFile.txt. This example requires that you create the following variables in the C/AL Globals window.

Variable name DataType

TestFile

File

Position

Integer

TestFile.WRITEMODE(TRUE);
TestFile.OPEN('C:\TestFolder\TestFile.txt');
Position := TestFile.POS;
MESSAGE('Pointer position before SEEK: %1', Position);
Testfile.SEEK(5);
Position := Testfile.POS;
MESSAGE('Pointer position after SEEK: %1', Position);

See Also

Reference

File Data Type