Read the content of a text file (ANSI or UTF8 without BOM) opened by the FILEOPEN command.
Syntax
CHGVAR |
VAR(&CMD) VALUE('FILEREAD') |
CHGVAR |
VAR(&PARM1) VALUE('StartBegin=true/false') |
CHGVAR |
VAR(&PARM2) VALUE(' ') |
CALL |
PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 + &PARM2 &RESULT) |
Parameters
Parameters |
|
Parm1 |
StartBegin
:
Each
FILEREAD command returns each line ended by CR LF (Carriage Return Line
Feed).
|
|
Example
In this example, the « C:\temp\test.txt » file is opened by the FILEOPEN command, and each line is returned by the FILEREAD command (into &RES).
The content of &RES is displayed by the NOP command.
We know that we went through the entire file as soon as the FILEREAD command returns% EOF%.
PGM
DCL VAR(&RES) TYPE(*CHAR) LEN(2000)
LNCOPEN
LNCCMD CMD(FILEOPEN) +
PARM1('File="c:\temp\test.txt"')
LNCCMDR CMD(FILEREAD) PARM1('StartBegin=true') +
RESULT(&RES)
LNCCMD CMD(NOP) PARM1(&RES)
DOWHILE COND(&RES *NE '%EOF%')
LNCCMDR CMD(FILEREAD) PARM1('StartBegin=false') +
RESULT(&RES)
LNCCMD CMD(NOP) PARM1(&RES)
ENDDO
LNCCMD CMD(FILECLOSE)
LNCCLOSE
ENDPGM
See also