Mainframes 360
The one stop destination for System Z professionals

Sunday, April 24, 2011

Working Storage

Q. Can the Mainframe computer do Math?
My Math professor at school taught me, how to calculate the Simple Interest on a Principal amount. The formula for Simple-Interest is I = P x R x T.

Mainframe Computers are good at Math. I am going to feed this formula into the Mainframe Computer. Then, I’ll have my computer calculate the Simple-Interest.
Q. Could you draw a Flow-diagram on how to calculate the Simple-Interest?
I have to calculate the Simple Interest to be charged for ten customers, who have borrowed money from the bank. The Input-file contains a list of ten records, one record for each customer, and each record specifies the Principal, Rate-of-Interest and Time.

Now, here's a flow-chart that outlines the steps, to calculate the Simple-Interest to be charged. First, the Input-File is opened for reading data. The Output-File is Opened for writing Output results. The Input File contains the Principal(P), Interest Rate(R), and Time(T). The program has to calculate the Interest(I), and write this answer to the Output File. The Input File contains ten records. The records from the file are read one-by-one sequentially. In each record, the P,R and T values are taken as input. The P value is multiplied by R, and stored in an intermediate Product. This Product is then further multiplied by T, and the final output interest is obtained. This output interest is written(stored) to the output-file. This process is repeated over and over again, ten times, until all the records have been

The Program-id is PROG14. This COBOL Program accesses two Flat-Files – the Input File with Data-records and an Output File to store the results. The SELECT statement in the FILE-CONTROL Para, of the INPUT-OUTPUT SECTION under the ENVIRONMENT DIVISION, declare the internal COBOL File-name INPUT-FILE and OUTPUT-FILE. The symbolic DD-Names of the two files are INFILE and OUTFILE.

Q. What is the data in the Input-File? What is its Format?
The Physical Mainframe Dataset SYSADM.DEMO.INPUT contains the Data-records to be processed by the Program. The contents of SYSADM.DEMO.INPUT are shown below.

Every Record in the File has a Fixed Record Length(LRECL) of 80 Bytes. Thus, in the COBOL Program, the File Buffer for the INPUT-FILE should be 80 Bytes large.


But, every INPUT-RECORD in the Input File, can be broken down into three parts – Principal(P), Rate-of-Interest(R), Time(T). For example, in the first record, P=001000.00, R=.0150, T=05 Years. In the second record, P=000700.00, R=.0275 and T=05 Years. Every record has this format; the first 8 Bytes are P(Principal) value, the next 4 Bytes are R(Rate-of-interest) value, the next two bytes are T(Time) value and the last 66 Bytes don’t contain any data. Thus, I am going to break-up INPUT-RECORD as follows :

Q. What the Output File looks like? What is its format?
I shall use the Mainframe Dataset SYSADM.DEMO.OUTPUT to store Output Results, after calculating the Simple Interest. The contents in SYSADM.DEMO.OUTPUT look like this -

The first twelve Bytes in the Output-File will be used to store the Simple Interest Answer. The next 68 Bytes do not contain any data. I am gonna define a File Buffer for the Output-File as follows -

Q. What are Working Storage Areas?
As a kid, when you took your Math examinations, you'd usually pick up the Input data-values supplied in the Question Paper, take a rough sheet, or a scratchpad, apply the Math formula, work out the problem in rough-work sheet. When arrive at the final answer, you jot it down on the answer-sheet. Think of the INPUT-FILE to be your Math Question Paper, that supplies the PRINCIPAL, RATE-OF-INTEREST and TIME-PERIOD Values. The OUTPUT-FILE is your Answer Sheet, where you put down the final answer in the SIMPLE-INTEREST Field. For working out the problem, you need memory space. Storage Areas which are merely used to do Rough-Work, and store intermediate results of processing, before you arrive at the final answer are call Rough-Work Areas or Working Storage Areas.
Q. How Rough-work areas can help me out here?
To begin with, I shall copy over all the data from the Question Paper(Input File) to my Rough Work Sheet. How is this done? Just as in algebra, there are algebraic variables like P,R and T, similarly in COBOL you can have rough-work variables like P,R and T. Since, they are being used for Rough-Work(Working-storage), I am prefixing their names with 'WS-', so they become WS-P, WS-R and WS-T.

Now, I am gonna put down all the data supplied in the Question-paper, onto the Rough Work Sheet. I am gonna copy over value 1000 from the PRINCIPAL Field of the INPUT-FILE, into the WS-P variable in the Rough-Work area. Like-wise, I shall copy over the value 0.150 from RATE-OF-INTEREST Field of the Input File, to WS-R in Rough-Work area. I copied over the value 05 from the TIME-PERIOD Field of the INPUT-FILE into the WS-T Variable on the Rough-Work Sheet. Now, I have all the data on the rough-work sheet.


Since, WS-P, WS-R and WS-T are meant for rough-work, I should also declare them under the WORKING-STORAGE SECTION of my COBOL Program. Generally, the WORKING-STORAGE SECTION is coded right after the FILE SECTION of a COBOL Program. So, here's how the WORKING-STORAGE would look -


The WORKING-STORAGE SECTION declares(announces) the list of all Variables(Storage-Areas) which are used only for Rough-Work. While coding the COBOL Program, I am gonna keep adding more to list of WORKING-STORAGE Variables, as and when I need them.

Back to working out the Problem. Now that, I have all the data on the Rough-Work Sheet in WS-P, WS-R and WS-T. I know, that the formula for Simple Interest is I = P x R x T. Let's move ahead one step at a time. I would first multiply P with R, and store this result in a Rough-Work variable WS-PRODUCT.


I would have to add WS-PRODUCT to list of WORKING-STORAGE Areas. Here, you go.


Well, I now need to take the Intermediate WS-PRODUCT of P x R, and mutiply this with T, to get the Interest I.


To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"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.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.