File Handling PLI Training Class8 Data Sets Dataset

  • Slides: 24
Download presentation
File Handling PL/I Training Class-8

File Handling PL/I Training Class-8

Data. Sets § Dataset: A named collection of data in an IBM mainframe operating

Data. Sets § Dataset: A named collection of data in an IBM mainframe operating system. A data set in an IBM mainframe is the equivalent of a file in other operating systems § A dataset is typically stored on Direct Access Storage Disk (DASD) or magnetic tape. § These Dataset are of two types: § PDS (Partitioned Dataset ) § PS (Physical Sequential Dataset )

Partitioned Data Set & Physical Sequential Dataset § PDS or Partitioned Data Set is

Partitioned Data Set & Physical Sequential Dataset § PDS or Partitioned Data Set is a dataset containing multiple partition’s each of which may contain a members § § Members are PLI Programs, JCL Programs, Load Modules etc. § PS or Physical Sequential Data Set is a dataset that contains records § Records like employee details, customer details etc. , The Partitioned Data Set can only allocate on a single volume with the maximum size of 65536 tracks.

Introduction § Data sets are stored on a variety of auxiliary storage media, including

Introduction § Data sets are stored on a variety of auxiliary storage media, including magnetic tape and direct-access storage devices (DASDs). § The organization of a data set determines how data is recorded in a data set and how the data is subsequently retrieved so that it can be transmitted to the program. § Records are stored in and retrieved from a data set either sequentially on the basis of successive physical or logical positions, or directly by the use of keys specified in data transmission statements.

The data set organization § Consecutive PL/I supports the following types of data set

The data set organization § Consecutive PL/I supports the following types of data set organizations: § Consecutive § Indexed § Relative § Regional § In the consecutive data set organization, records are organized solely on the basis of their successive physical positions. § When the data set is created, records are written consecutively in the order in which they are presented. The records can be retrieved only in the order in which they were written.

Indexed Relative Regional § Indexed : In the indexed data set organization, records are

Indexed Relative Regional § Indexed : In the indexed data set organization, records are placed in a logical sequence based on the key of each record. A character string key identifies the record and allows direct retrieval, replacement, addition, and deletion of records. Sequential processing is also allowed. § Relative: In the relative data set organization, numbered records are placed in a position relative to each other. The records are numbered in succession, beginning with one. § Regional: The regional data set organization is divided into numbered regions, each of which can contain one record. The regions are numbered in succession, beginning with zero. A region can be accessed by specifying its region number, and perhaps a key, in a data transmission statement.

Files § To allow a source program to deal primarily with the logical aspects

Files § To allow a source program to deal primarily with the logical aspects of data rather than with its physical organization in a data set, PL/I employs models of data sets, called files. § These models determine how input and output statements access and process the associated data set. § Unlike a data set, a file data item has significance only within the source program and does not exist as a physical entity external to the program. § A name that represents a file has the FILE attribute

Programming steps Any file that need to be accessed in the PL/I program have

Programming steps Any file that need to be accessed in the PL/I program have to follow the below steps. 1. 2. 3. 4. Define the file Open the file Process information in the file Close the file

SYSPRINT and SYSIN § § Two files are provided that can be used by

SYSPRINT and SYSIN § § Two files are provided that can be used by any PL/I program. § These files need not be declared or opened explicitly. For SYSIN, the default attributes are STREAM INPUT, and for SYSPRINT they are STREAM OUTPUT PRINT. § Both file names, SYSIN and SYSPRINT, have the default attribute EXTERNAL. One is the input file SYSIN, and the other is the output file SYSPRINT.

Declaration of file File declarations: The set of records in the file is referred

Declaration of file File declarations: The set of records in the file is referred to in a PL/I program by the file name The file name may be 1 to 8 character long. DCL EMPFILE INPUT SEQUENTIAL BUFFERED ENV(CONSECUTIVE FB RECSIZE(100) BLKSIZE(500) BUFFERS(3)); ATTRIBUTES FB RECSIZE BLKSIZE BUFFERS means file access properties means fixed record length, blocked means length of the record in bytes means length of the block in bytes means number of buffers

Environment attribute § Environment attribute describes the physical properties of a data set (e.

Environment attribute § Environment attribute describes the physical properties of a data set (e. g. Record length, blocks) and the method of processing them. § Default value for the type of organization is consecutive. This type of organization can be processed only sequentially. DCL PURCHASE RECORD SEQUENTIAL INPUT ENV(CONSECUTIVE); OPEN FILE(PURCHASE); § Record is an attribute in the declaration. Stream is default for the transmission type.

Attributes Type Alternative Attributes Default Attribute Usage STREAM or RECORD STREAM Function INPUT or

Attributes Type Alternative Attributes Default Attribute Usage STREAM or RECORD STREAM Function INPUT or OUTPUT or UPDATE INPUT Access SEQUENTIAL or DIRECT SEQUENTIAL Buffering BUFFERED or UNBUFFERED § BUFFERED (for SEQUENTIAL files); § UNBUFFERED (for DIRECT files) Scope EXTERNAL or INTERNAL EXTERNAL

Stream transmission § Two types of transmission are there between internal & external storage

Stream transmission § Two types of transmission are there between internal & external storage : - STREAM I/O WITH GET & PUT : - Data item is transmitted singly. Advisable for small quantities i. e. Screen & card readers. RECORD I/O WITH READ & WRITE : - Complete record of data items is transmitted and copy of the record is usually kept in internal storage. It is preferable for larger quantity of data. STREAM -> GET FILE(INPUT) LIST(A, B, C); RECORD -> READ FILE(INPUT) INTO(INAREA);

RECORD and STREAM attributes § The RECORD and STREAM usage attributes specify the kind

RECORD and STREAM attributes § The RECORD and STREAM usage attributes specify the kind of data transmission used for the file. § STREAM RECORD Default indicates that the file consists of a collection of physically separate records, each of which consists of one or more data items in any form. Each record is transmitted as an entity to or from a variable. § A file with the STREAM attribute can be specified only in the FILE option of the OPEN, CLOSE, GET, and PUT input/output statements. § A file with the RECORD attribute can be specified only in the FILE option of the OPEN, CLOSE, READ, WRITE, REWRITE, LOCATE, and DELETE input/output statements.

Difference between Record/Stream § In record I/O, the data in a data set is

Difference between Record/Stream § In record I/O, the data in a data set is considered as a collection of record. In stream I/O, data is considered as a continuous sequence. § Record I/O transmits records just as they are stored. In stream I/O data conversion is possible. § In record I/O, there are no standard files. SYSIN and SYSPRINT are valid standard files for stream I/O. § Record I/O allows various forms of data set organization. Stream I/O allows only sequential form of data set.

INPUT, OUTPUT, and UPDATE § The INPUT, OUTPUT, and UPDATE function attributes specify the

INPUT, OUTPUT, and UPDATE § The INPUT, OUTPUT, and UPDATE function attributes specify the direction of data transmission allowed for a file. § INPUT specifies that data is transmitted from a data set to the program. § OUTPUT specifies that data is transmitted from the program to a data set, either to create a new data set or to extend an existing one. § UPDATE, which applies to RECORD files only, specifies that the data can be transmitted in either direction. A declaration of UPDATE for a SEQUENTIAL file indicates the update-inplace mode.

SEQUENTIAL and DIRECT attributes § The SEQUENTIAL and DIRECT access attributes apply only to

SEQUENTIAL and DIRECT attributes § The SEQUENTIAL and DIRECT access attributes apply only to RECORD files, and specify how the records in the file are accessed. § DIRECT attribute specifies that records in a data set are directly accessed. The location of the record in the data set is determined by a character-string key. Therefore, the DIRECT attribute implies the KEYED attribute. The associated data set must be on a direct-access storage device. § The SEQUENTIAL attribute specifies that records in a consecutive or relative data set are accessed in physical sequence, and that records in an indexed data set are accessed in key sequence order.

BUFFERED & UNBUFFERED § The BUFFERED attribute specifies that during transmission to and from

BUFFERED & UNBUFFERED § The BUFFERED attribute specifies that during transmission to and from a data set, each record of a RECORD file must pass through intermediate storage buffers. This allows both move and locate mode processing. § The UNBUFFERED attribute indicates that a record in a data set need not pass through a buffer but can be transmitted directly to and from the main storage associated with a variable. This allows only move mode

Opening and Closing files § Before a file can be used for data transmission,

Opening and Closing files § Before a file can be used for data transmission, by input or output statements, it must be associated with a data set. § Opening a file associates the file with a data set and involves checking for the availability of external media, positioning the media, and allocating required operating system support. When processing is completed, the file must be closed. Closing a file dissociates the file from the data set. § DCL MASTER FILE RECORD SEQUENTIAL; . . OPEN FILE(MASTER) OUTPUT; . . CLOSE FILE(MASTER);

OPEN statement Implicit opening § The OPEN statement associates a file with a data

OPEN statement Implicit opening § The OPEN statement associates a file with a data set. It merges attributes specified on the OPEN statement with those specified on the DECLARE statement. It also completes the specification of attributes for the file. § PL/I provides two statements, OPEN and CLOSE, to perform these functions. However, use of these statements is optional. If an OPEN statement is not executed for a file, the file is opened implicitly during the execution of first data transmission statement for that file. § An implicit opening of a file occurs when a GET, PUT, READ, WRITE, LOCATE, REWRITE, or DELETE statement is executed for a file for which an OPEN statement has not already been executed.

Data transmission statements § The data transmission statements that transmit records to or from

Data transmission statements § The data transmission statements that transmit records to or from a data set are READ, WRITE, LOCATE, and REWRITE. The DELETE statement deletes records from an UPDATE file. § READ statement The READ statement can be used with any INPUT or UPDATE file. It either transmits a record from the data set to the program variable or sets a pointer to the record in storage. § WRITE statement The WRITE statement can be used with any OUTPUT file, DIRECT UPDATE file, or SEQUENTIAL UPDATE file. It transmits a record from the program and adds it to the data set.

REWRITE statement § REWRITE statement The REWRITE statement replaces a record in an UPDATE

REWRITE statement § REWRITE statement The REWRITE statement replaces a record in an UPDATE file. § For SEQUENTIAL UPDATE files, the REWRITE statement specifies that the last record read from the file is rewritten; consequently a record must be read before it can be rewritten. § For DIRECT UPDATE files, any record can be rewritten whether or not it has first been read. § DELETE statement The DELETE statement deletes a record from an UPDATE file.

CLOSE statement § The CLOSE statement dissociates an opened file from its data set.

CLOSE statement § The CLOSE statement dissociates an opened file from its data set. § Closing a file that was previously closed has no effect. A closed file can be reopened. If a file is not closed by a CLOSE statement, it is closed at the termination of the program. § Implicit Close PL/I will close it during the termination process.

Thank You Polsani Anil Kumar

Thank You Polsani Anil Kumar