A useful feature of the record definition is that the record itself can contain a variable specification that can be used as a subscript later in the same record. In the following example, LineNum is specified as an integer constant, and is later used as the subscript for Lines:
integer FileID
string FileName_SV is "input.txt"
string Read_SV is "read-only"
integer LineNum_IV
integer Counter_IV is 1
string Lines[100]
record InputLine_REC is
LineNum_IV 2
filler 1
Lines[LineNum_IV] 40
end record
The following is the INPUT.TXT file.
02 This transaction applies to 2.
05 This transaction applies to 5.
08 This transaction applies to 8.
03 This transaction applies to 3.
01 This transaction applies to 1.
08 This transaction applies to 8.
04 This transaction applies to 4.
10 This transaction applies to 10.
11 This transaction applies to 11.
12 This transaction applies to 12.
...
The following example is ESL code that reads the first 10 lines of the input file:
action Read10 is
copy 1 to Counter_IV
call OpenFile(FileID,FileName_SV,Read_SV)
while (Counter_IV < 11) loop # read first 10 lines
call ReadNextRecord(FileID,InputLine_REC)
copy (Counter_IV + 1) to Counter_IV
end loop
call CloseFile(FileID)
The result is that:
Lines[1] contains the string beginning on line 5, starting at column 4, up to 40 characters. ("This transaction applies to 1.")
Lines[2] contains the string beginning on line 1 starting at column 4, up to 40 characters. ("This transaction applies to 2.") and so on.