Record I/O Structures

Record I/O

ON ENDFILE more_records = no
more_records = yes

READ first record

DO WHILE more records
	WRITE record
	READ next record
END;

Example:

LINECNT: PROC OPTIONS(MAIN);

	DCL DATAIN  FILE INPUT RECORD ENV(F RECSIZE(80));
	DCL DATAOUT FILE OUTPUT RECORD ENV(F RECSIZE(80));
	
	DCL DATA_AREA                   CHAR(80);
	DCL MORE_RECORDS                BIT(1) INIT('1'B);
	DCL NO                          BIT(1) INIT('0'B);
	
	ON ENDFILE(DATAIN)
		MORE_RECORDS = NO;
		
	OPEN FILE(DATAIN)
	     FILE(DATAOUT);
	     
	READ FILE(DATAIN) INTO (DATA_AREA);
	DO WHILE(MORE_RECORDS);
		/* do some processing like validation */
		WRITE FILE (DATAOUT) FROM (DATA_AREA);
		READ FILE (DATAIN) INTO (DATA_AREA);
	END;
END LINECNT; 
	

Structures
A Structure in a collection of data idems requiring storage for each idem to be in a particular order and having a logical relationship to one another.

MAJOR STRUCTURE
MINOR STRUCTURE

The LIKE attribute is used to indicate that the name being declared is to be given the same structuring as the major structure name following the attribute LIKE.

Structure to structure assignment is possible, when the structure fields are similar.

Structure assignment BY NAME

DCL 01 DATE,
	02 MM				CHAR(2),
	02 DD				CHAR(2),
	02 CCYY				CHAR(4);
	
DCL 01 DATE_ED,
	02 MM				CHAR(2),
	02 FILLER1			CHAR(1) INIT('-'),
	02 DD				CHAR(2),
	02 FILLER2			CHAR(1) INIT('-'),
	02 CCYY				CHAR(4);
	
DATE_ED = DATE, BY NAME;
As per above assignment, only MM, DD and CCYY will be moved.

Back

Hosted by www.Geocities.ws

1