PreviousNext
Help > Programming with LAUNCHER Office > LNCCMD commands > Commands list > FILEREAD command
FILEREAD command

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 :
- True: start reading at the beginning of the file.
- False : start reading at the beginning of the line following the line returned by the last FILEREAD command.

Each FILEREAD command returns each line ended by CR LF (Carriage Return Line Feed).
If %EOF% is returned by the FILEREAD command, it means that you reach the end of the file, or the file is empty.

 

 

 

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

Command FILEWRITE

Command FILECLOSE