Hello, I am new to learning how to develop sqr programs within PeopleSoft. I've been going through some programs we are utilizing and wanted to see if someone could help provide clarification with what the below snippet of code is doing in this While loop.
if $path != ''
let $Archive_File = $path || 'ARCHIVE\' || $filename || $Curr_Date || '.dat'
open $Out_File as 1 for-reading record=450:vary status=#fileread
open $Archive_File as 2 for-writing record=450:vary status=#filewrite
While 1
if #END-FILE
break
else
read 1 into $Current_Line:999
write 2 from $Current_Line
end-if
End-While
close 1
close 2
end-if
I'm trying to understand if the WHILE statement is evaluating the "$Out_File as 1" as the logical expression, or is 1 being evaluated as the value of the variable #END-FILE (As I understand this variable is set to either 0 or 1).
In addition to the file name, the open command takes a number as a parameter which it uses as a handler for the file. In your example, two files are being opened.
The WHILE 1 statement doesn't have anything to do with file 1. Here 1 means true, instead of 0 for false. So 1 is always true, creating an endless loop unless something within the loop breaks out if it, which in this case is the BREAK command.
The #END-FILE variable contains FALSE when the file cursor is not at EOF, and a TRUE when the the file cursor is at EOF.
An alternative, which uses less lines of code and is easier to understand might look like this: