READ DATASET

READ - Read a file

Addition:

... LENGTH len

Effect

Reads a record from the sequential file specified in dsn (a field or a literal) and stores it in the field f (usually a field string).

If the specified file is not open, READ DATASET attempts to open the file dsn (IN BINARY MODE FOR INPUT or with the specifications of the last OPEN command for this file). Any errors result in the termination of the program.
To read all the records in a file, you are recommended to place READ DATASET in a DO loop that you leave with EXIT.

DATA: BEGIN OF REC, 
		TEXT(30), 
		NUMBER TYPE I, 
	END OF REC. 

Read the file "/usr/test":

DO. 
  READ DATASET '/usr/test' INTO REC. 
  IF SY-SUBRC <> 0. 
	EXIT. 
  ENDIF. 
  WRITE: / REC-TEXT, REC-NUMBER. 
ENDDO.

If the file is opened with the READ statement, the system automatically performs an authorization check. If the user does not have the appropriate authorization, a runtime error occurs. You can check the existence of the authorization with the function module AUTHORITY_CHECK_DATASET.

Effect

Stores the length of the record read from the file in the field len.

Related

OPEN DATASET, TRANSFER, CLOSE DATASET