|Q. What makes Mainframe Files so important?|
|Walk into a Mainframe Data center, and you'll find large amounts of Data being stored in Files – on DASD or Tapes. At Insurance Companies like AIG and AXA, your Insurance Policy Data, the premiums you pay, are stored on Files on Mainframe Systems. Banks like Bank of America, American Express record Credit Card Data, the transactions you make, in Mainframe Files. Companies like Ford, Visteon keep their Stock Data, Purchase Orders and Requisitions, their Supplier Database in Mainframe Files. |
As a Mainframe Programmer, it helps to learn a little about Files, and get the know-how of processing files by coding a COBOL Program.
|Q. What is a Line-Sequential File?|
|Remember those days, you loved listening to your favourite Michael Jackson numbers on the Music Cassette Tape. When you pop-in an audio cassette tape in your walkman, it plays the first song, then the second song, the third song and so on. The songs are played one-by-one. |
Just as the Music Cassette Tape has songs in sequence, Computer Files contain data-records in sequence. On each line, there is one record. Line-Sequential Files get their name owing to the fact, that when you read these Files, the first record is fetched, then the second record is fetched, and then the third record is fetched, and this goes on. If you want to access the 10th Record in the File, you cannot directly jump, skip to it. You must traverse the file in a Sequential manner, starting from the 1st record, then the 2nd record, the next successive record and so on, till you reach the desired(10th) record. This is called Sequential mode of Access.
|Q. How do COBOL Programs refer to a Mainframe File?|
|On a Mainframe Computer,File(s) are identified by a name. Say for example, I have stored the data about Employees working at a company, on a Mainframe Sequential-File called SYSADM.EMPLOYEE.DATA. |
COBOL Programs don't refer to Files, by their actual Physical File-Name. While writing a COBOL Program, I don't have to think about the real physical File-name, "Where's the data stored? Is it in SYSADM.EMPLOYEE.DATA or some other file-name? I don't care!" Instead, in the COBOL Code, I shall refer to the File by a short symbolic COBOL name, like EMPLOYEE-FILE.
The Big Idea is, you can attach or Bind, any Physical Mainframe File you like, say SYSADM.EMPLOYEE.DATA, or SYSADM.TEST.DATA or any other actual Mainframe file of your choice to the COBOL File-Name EMPLOYEE-FILE, at the time of running the Program.
|Q. How to declare a Sequential-File in COBOL?|
|Sequential-File(s) must be first declared in a COBOL Program. The SELECT Clause in COBOL, is used to declare a File. For example, if the COBOL Program processes the data in the EMPLOYEE-FILE, you should code SELECT EMPLOYEE-FILE Statement in the COBOL Program. |
Where should you code the SELECT Statement? One knows that, COBOL Programs are divided into four chunks – IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION. The ENVIRONMENT DIVISION of a COBOL Program contains a Section called the INPUT-OUTPUT SECTION. You code SELECT Statements under the FILE-CONTROL Paragraph of the INPUT-OUTPUT SECTION.
As an example, I will build a COBOL-Program, to process the data in the EMPLOYEE-FILE. In my COBOL Program, I wrote the SELECT Statement like this.
|Q.What setup is required to attach or hook-up a Sequential-File to a COBOL Program?|
|I have declared an internal COBOL file called EMPLOYEE-FILE in My COBOL Program. My COBOL Program processes this EMPLOYEE-FILE. This name EMPLOYEE-FILE is internal or private to My COBOL Program, and is unknown to the outside world, externally. |
However, the actual Employees Data resides in the Physical Mainframe File SYSADM.EMPLOYEE.DATA, on the Computer Storage. I wish to get this SYSADM.EMPLOYEE.DATA File processed using my COBOL Program. Somehow, I have got to establish a link between the Outside-World Mainframe File SYSADM.EMPLOYEE.INPUT and the COBOL Program's internal File-Name EMPLOYEE-FILE.
To run(Execute) My COBOL Program, I wrote a JOB. This job executes My COBOL Program PROG10. The DD Statements in the JCL, are used to specify Mainframe Files. I have keyed in a //DD Statement that refers to the Physical Mainframe Dataset SYSADM.EMPLOYEE.DATA.
To attach or hook-up this Physical Mainframe Dataset SYSADM.EMPLOYEE.DATA, to My COBOL Program PROG10, I shall first code a name on the DD-Statement, say EMPIN. //EMPIN is said to be an alias, a pet-name, the DD-Name for the Mainframe File SYSADM.EMPLOYEE.DATA. //EMPIN Pet-Name points-to, or refers to the actual Physical Mainframe File SYSADM.EMPLOYEE.DATA.
Back there in My COBOL Program, I shall take this DD-Name EMPIN and gel it with the Internal
File-name EMPLOYEE-FILE. Let's go ahead, and assign the private COBOL File-name EMPLOYEE-FILE to this DD-Name EMPIN. The EMPLOYEE-FILE internal-name is ASSIGN'ed TO EMPIN DD-Name, as follows.
Thus, the name of this File internal to the COBOL Program is EMPLOYEE-FILE. In the outside world, the actual physical name of the Mainframe File is SYSADM.EMPLOYEE.DATA. The DD-Name EMPIN, acts as the Syntactic Sugar, a bridge, a glue between the two. This is illustrated in the Schematic below.
|Q. What is a File Buffer?|
|A Factory or an Industry purchases Raw-Materials from Suppliers. When Raw-Materials are received, they are stored or kept in a Warehouse. Just as factories or industries get raw-materials from Suppliers, COBOL Programs get their Raw Materials - Bytes of Data from Files. When Bytes of Data dispatched from a File, arrive in the COBOL Program, they have got to be stored somewhere, for later processing. This storage space is called File Buffer. |
The picture above describes, How Buffers work. The COBOL Program READs the 1st record off the File. The Data 'QUASAR SHABBIR CHUNAWALA HOLY CR. MUMBAI 400103 91 2228941365' is read from the file, and gets stored in the Buffer INPUT-RECORD, inside the COBOL Program.
The gist of the concept then is, Buffer(s) are Memory locations, where you could store data. However, as you must have read in last tutorial, before you could store data in Computer Memory Locations, you must first declare them in the DATA DIVISION – tell how many bytes of space do you need, assign a name to the memory-location. The computer then reserves this buffer space, exclusively for your use. Take a look at the pictorial representation above and notice, I have assigned a name to my Buffer – INPUT-RECORD. My INPUT-RECORD buffer is 80 Bytes large. Why? Coz, the records in my Mainframe file have a Length=80 Bytes. The buffer in the Program should be large enough to accommodate the data fetched from the Mainframe File.
Look at the below snap, how I have written the COBOL Code for the INPUT-RECORD Buffer.
|Q. What is FILE SECTION? What is File Descriptor FD Paragraph?|
|File Buffers are declared in a special FILE SECTION of the DATA DIVISION. The File Descriptor FD identifies the COBOL Internal File-name, to which this buffer belongs. For example, if I want to declare a Buffer for the COBOL File EMPLOYEE-FILE, I’d have to code - |
|Q. How to write a simple COBOL Program to process the Employee File?|
|I have written a simple COBOL-Program, to read records from the Employee Sequential-File, and display this employee data on the computer-screen. The PROCEDURE DIVISION of the Program is illustrated below. |
On a Mainframe Computer, before you do any input or output operations on a File, you must first open the File. This sets a marker, pointing to the first record of the Employee File. The COBOL instruction OPEN, followed by the COBOL Internal file-name EMPLOYEE-FILE, opens the Employee file and readies it for processing. This is like the "On your marks, Get-Set, Go!" count-down, just before reading the file.
The COBOL instruction READ, reads one record from the Mainframe File, and stores this data into the File-Buffer in the COBOL Program. The READ operation, always fetches the Current-Record from the File. The marker currently points to the 1st Record, so the first-record from the file
'QUASAR SHABBIR CHUNAWALA ...' is fetched and stored in the buffer INPUT-RECORD. After a successful READ, the marker moves one position forward in the Sequential-File, and points to the 2nd Record.
The contents of the Buffer INPUT-RECORD are 'QUASAR SHABBIR CHUNAWALA ...'. The COBOL DISPLAY statement is used to display textual-characters on the Mainframe Computer Screen.
DISPLAY INPUT-RECORD displays, the contents or value of INPUT-RECORD buffer
'QUASAR SHABBIR CHUNAWALA ...' on the screen.
The marker currently points to the 2nd Record. Thus, the next COBOL READ Instruction, fetches the second-record 'DEEPIKA K SABNIS ...' from the EMPLOYEE-FILE, and stores it into the buffer INPUT-RECORD. After a successful READ, the marker is incremented and moves to the next record – the 3rd record in the File.
The COBOL DISPLAY Statement, displays the contents of the Buffer INPUT-RECORD,
'DEEPIKA K SABNIS...' on the Mainframe Terminal.
The marker now points to the 3rd Record. Thus, the last COBOL READ Instruction, fetches the third-record 'RAMA S JAKKANI ...' from the EMPLOYEE-FILE, and puts it into the buffer INPUT-RECORD. After a successful READ, the marker is incremented and moves beyond the last record.
The COBOL DISPLAY Statement, displays the contents of the Buffer INPUT-RECORD,
'RAMA S JAKKANI...' on the Mainframe Terminal.
Once the processing of the File is complete, the COBOL CLOSE instruction, closes the file. No input or output operations are allowed on the File now.
I ran the COBOL Compiler Software IGYCRCTL, and the Linker Software IEWL to translate my COBOL Source Program into a Load Module. Here's the Output-Listing in the Spool, when I run the Load.
"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.