What’s new at MAINFRAMES 360
(Updates May '11)...
- We are a cosmopolitan community of 400 members, from around the globe.
- Working on writing and publishing articles on CICS.
- Special article on "How do I learn Mainframe Programming"

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

image
Q. How to code the IDENTIFICATION and ENVIRONMENT DIVISION of the COBOL Program?
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.

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

image

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 :

image
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 -

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

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

image


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 -

image

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.

image

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

image

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

image
Related Posts Plugin for WordPress, Blogger...

Note :

Protected by Copyscape Online Copyright Protection
© Copyright – Quasar Chunawalla, 2010.
Note : The copyrights of all the material, text and pictures posted in this website belong to the author. Any instance of lifting the material from this website, shall be considered as an act of plagiarism. For any clarifications, please drop me a line at
 
back to top