How To: handle files with AML


How can I set up a loop to read records from a file?


Reading files is a 4 step process:

1. Verify that the file exists before you try to read it (optional).
2. Open the file for reading.
3. After the file is open, you can read the file one record (line) at a time.
4. Close the file when you finish reading it.
Here is an example block of code which demonstrates opening and reading records
from a system file:

&if [exists %file%] &then &do
&sv amlunit = [open %file% openstat -READ]
&if %openstat% = 0 &then &do
&sv record = [read %amlunit% readstat]
&do &while %readstat% = 0
/* Do something with the record
&sv record = [read %amlunit% readstat]
&type Error in opening file, error code: %openstat%
&type File %file% doesn't exist
&sv shut = [close %amlunit%]