Steps in PL/1 file program.
Define File( Declaring a file in PL\1)
Explanation for the attributes.
Type of transmission “STREAM’ or “RECORD”
If you are using structures like group variables in cobol in your programm to handle the data you have to use the “RECORD”
Direction of the transmission “INPUT” “OUTPUT” and “UPDATE”
Physical environment( Attributes of physical dataset)
This specifies the attributes of the dataset. It can also be mentioned in jcl.
env(F recsize(80)
Above statement says that the data set is fixed block and the logical record length is 80.
OPEN FILE
Syntax:
open file(file_name);
eg. open(inp-file);
open(inpfile1,user_file);
we can also specify input/output , stream/record, print, pagesize, linesize.
List directed IO in PL/1
You can use list directed I/O method to read/write datasets if you used stream while declaring the file ( dcl outreport output stream env(F blksize(80)); )
GET
get file(file_name) list(variable list);
get file(file_name) edit(variable list);
PUT
put file(file_name) list(variable list);
put file(file_name) edit(variable list);
RECORD INPUT/OUTPUT
Provides extreme flexibility for file handling. Widely used in many science and business application.
You must use RECORD type of transmission while declaring the file.
eg. dcl report_input file record env(F recssize(80));
RECORD I/O Statements
read file(file_name) into(record_area);
e.g. read file(user_data) into(user_structure);
write file(file_name) from(record_area);
e.g. write(user_data) from(user_structure);
FILE I-O program in PL\1
FILEIO:PROCEDURE OPTIONS(MAIN);
/*
PROGID. FILEIO
AUTHOR. SHIBU THANNIKUNNATH
DATE . 2011-FEB-12
COMMENT
*/
/*DECLARE */
DCL 1 USER_DETAILS,
2 NAME CHAR(15),
2 AGE CHAR(02),
2 ADDR CHAR(15),
2 STREET CHAR(15),
2 CITY CHAR(15),
2 COMMENT CHAR(18);
%PAGE;
DCL INP_CTR FIXED DEC(2) INIT(00);
DCL INP_FILE_EOF BIT INIT('1'B);
DCL USERFLE FILE INPUT RECORD ENV(F
%SKIP; RECSIZE(80));
/*OPEN FILE*/
OPEN FILE(USERFLE);
ON ENDFILE(USERFLE) INP_FILE_EOF='0'B;
READ FILE(USERFLE) INTO(USER_DETAILS);
/*DO UNTIL EOF*/
DO WHILE(INP_FILE_EOF);
INP_CTR=INP_CTR+1;
PUT SKIP LIST('REC#'||INP_CTR);
PUT SKIP LIST('NAME '||NAME||'AGE '||AGE||'ADDR1 '||ADDR||
'STREET '||STREET||'CITY '||CITY||'COMMENT '||
COMMENT);
READ FILE(USERFLE) INTO(USER_DETAILS);
END;
END FILEIO;
OUTPUT