Mainframes 360
The one stop destination for System Z professionals

Friday, December 25, 2009

Decision-making constructs

Q. What are business rules?
A business-rule is a representation of a decision-making logic. For example in a bank, the loan-officer decides to issue you a personal loan based on your credit-rating and your annual pay. This simple business rule could be described as,
Business rules can get complex. Every house-hold has an electricity, water and gas connection. I hail from Mumbai city, where Reliance Energy is responsible for electricity distribution. Here is a picture of my electricity bill.

  Bill-01  Bill-02

The energy company has divided the tariff into slabs. The ceiling for the first slab is 100 units. Say, you’ve consumed 150 units this month. The Energy charge for the first hundred units will be at the rate 296 paise/unit. The energy charge for the excess fifty units will be at the rate 556 paise/unit. The business rule employed by the energy company to calculate the bill could be described as, In India, the government authorities(RTO) issues a driver’s license. The minimum age is 18 years for all vehicles. The driver must pass the driving test. This business rule could be described as,
In a nutshell, any industry or business has conditions or constraints based on which decisions are made, for example issuing a bank loan, under-writing an insurance policy, billing of a customer etc. These are called business conditions or rules.
Q. How to code business rules in Cobol?
When companies started automating their business processes and computerization took place, business rules started being written in software applications. The two control structures
IF-THEN-ELSE and EVALUATE are used to code business rules in the Cobol language.

Saturday, December 19, 2009

COBOL Tutorial – USAGE Clause

Q. What is USAGE Clause? Could you cite an example, where one would employee USAGE Clause?

USAGE Clause signifies, how the computer internally stores or represents DATA. Memory space calculation is done by the computer, on looking at the USAGE Clause. Thus, USAGE Clause answers the question, How much storage space does a data-item occupy? 1 byte, 2bytes, 4 bytes,… well how much? Depending upon the type of data – whether alphabetic or numeric, you should choose a USAGE(internal representation) that suits your purpose.


DISPLAY When you want to work with characters, manipulate them, work on textual string data
COMPUTATIONAL More appropriate, when you want to perform arithmetic computations, specially on numbers – integers and fractional numbers

When there is no explicit USAGE clause, it defaults to USAGE IS DISPLAY.

Q. How do computers internally store data?

Computers store data in Binary digits 0 and 1. Thus, all the data you enter into the computer is represented as 0’s and 1’s. The computer is said to understand and speak binary language.

Text data such as ‘HELLO’, ‘I HOPE YOU ARE IN THE PINK OF HEALTH’,’QUASAR CHUNAWALA’ are stored using a collating sequence(ASCII or EBCDIC). The collating sequence assigns a unique code number to each character. For example, A is assigned ASCII code 65, B = 66, C = 67, and so on. Now, when you type A on the computer, the computer interprets it as ASCII Code 65, which gets stored as 0100 0001.


Numeric data can be held as Text Digits(ASCII Digits), or as pure Binary numbers, or as Binary Coded Decimal(BCD), or as Real Numbers(IEEE Format).

Q. What is the USAGE IS DISPLAY Clause?

USAGE IS DISPLAY is mainly used with Text Data such as ‘HELLO’,’HOW ARE YOU’ and numeric data, which is not used in computation such as Street no. ‘2530’, phone numbers like ’17654094509’.

Text-data(strings) are made up of several characters. For example, the text-string ‘HELLO’ is composed of the characters ‘H’,’E’,’L’,’L’ and ‘O’. When you apply USAGE IS DISPLAY, the text-data is stored as ASCII/EBCDIC Characters.

Generally, when Text-data is stored on PC, the collating sequence used is ASCII. On Mainframes, Text-Data is stored in EBCDIC Format.



Here, ‘H’, ‘E’, ‘L’, ‘L’ and ‘O’ are stored ASCII/EBCDIC Characters. A picture of how they look is shown below :


Each ASCII/EBCDIC Character requires 1 byte. So, the text-data ‘HELLO’ occupies 5 bytes of storage.

Q. Is there any problem, if I store numeric data, which is used in computations with a USAGE IS DISPLAY?


Since no USAGE clause is explicitly specified, it defaults to USAGE IS DISPLAY.

When numeric data is specified with USAGE IS DISPLAY, these text-digits of the number are stored as ASCII/EBCDIC digits. Thus, the Text-digit 2 would be stored in computer memory as shown below -


Each text-digit is stored in ASCII/EBCDIC Form, so it will occupy 1 byte. Hence, if you store 12345.67 with USAGE IS DISPLAY, it will occupy 7 bytes.

Imagine a scenario, where you want to read and process a data-file containing 1 million phone-numbers, each phone-number being a PIC 9(10). Each phone number occupies 10 bytes of storage.

For processing 1 million phone numbers,

1 MILLION x(multiplied by) 10 bytes for each phone number = 10 million bytes.

This is quite computationally expensive in terms of storage space, time and bandwidth. Reading and processing a file as large as 10 million bytes(10 MB) takes time. This is why,
USAGE IS DISPLAY is not good choice for storing numeric data.

USAGE is DISPLAY, is more suited to working on a character-by-character level on Text data-items. When you want to perform character-level manipulations, use DISPLAY.


USAGE IS COMPUTATIONAL is more appropriate when you are dealing with integer numbers. USAGE IS COMPUTATIONAL indicates that the data-item shall be stored as pure binary numbers.


USAGE IS COMPUTATIONAL indicates that 1327 is stored in pure binary form. A picture of how 1327 is stored, is given below :


The pure binary equivalent of 1,327 occupies 2 bytes.

The memory space calculation is done by the computer, as follows:

Integer Number Range PICTURE Clause Storage Space

-32,768 to +32,767

S9(01) to S9(04) 2 Bytes
-2 billion to +2 billion S9(05) to S9(09) 4 Bytes
-1.8 x 10^19 to +1.8 x 10^19 S(09) to S9(18) 8 Bytes

For numbers upto 32,767, 2 bytes of memory space is reserved. What if, you wanted to store an even larger integer number like 50,000? The pure binary equivalent of such numbers would then not fit into 16 bits(2 bytes). A 2-bytes bucket would not be large enough to accommodate it. They would spill over. They would need a big tumbler(say 4 bytes capacity). So, automatically 4 bytes of memory space would be reserved. What if, you store a mammoth number like a hundred billion? A hundred billion would have a picture clause S9(11), so it would occupy 8 bytes.

As you may observe on the table, based on the ranges, we can draw a correlation between the PICTURE Clause of the data-item and the Storage space.

Consider the following simple example, in which the variables WS-VAR-1 and WS-VAR-2 are declared as COMPUTATIONAL. As the USAGE IS COMPUTATIONAL, the numbers 10 and -12 are stored internally in binary format.


Upon the addition Of these two integers, 10 and -12, the COBOL Code shows the following output. 10 added to –12 gives a sum of –2. Note, that sign is stored as part of the rightmost digit. K stands for minus(-ve) 2. So, 1K means –12 and 0K means –2.


Q. What is the USAGE IS COMP-1/COMP-2 Clause?

When you want to work with fractional numbers, numbers containing a decimal point, you must employ USAGE IS COMP-1. USAGE IS COMP-1 is used to store floating point numbers(real numbers). COMP-1 occupies 4 bytes of memory space. Floating point(real numbers) are divided into 2 parts : mantissa part and exponent. For example, 123.456 can be represented as mantissa = 123456 e -3. The mantissa part is occupies 3 bytes. The exponent part occupies 1 byte.

On the other hand, if you have an extremely huge number like a googol, 1 e +100, you would need more space. Moreover, you a number 23 e -50 is a extremely tiny number(quite close to zero, but not zero), to store it require lot of precision and accuracy. For such numbers, you would use COMP-2. COMP-2 is used for real fractional numbers which are extremely large, and very small. COMP-2 occupies 8 bytes of memory space.

Q. What is the USAGE IS COMP-3 Clause?

As most references quote, COMP-3 is used mainly for packed decimal values(BCD Format). I would say, on most computer systems, running COBOL Applications, COMP-3 is the general standard. The reason behind this is, COMP-3 packs, two digits in 1 single byte. This is really cool, and it saves a lot of space.

Let me show ya, how COMP-3 achieves this remarkable feat. In the decimal number system, any digit can take a value ranging from 0-9, there are in all 10 possibilities. Thus, you can represent any digit with 4 bits(16 possibilities, 4 bits = 1 nibble). So, in COMP-3 format, each digit occupies only 4 bits. You must find the binary representation for each digit separately. For example, the number

  4    5    9    8    1    2 .  5    6   would be stored as
0100 0101 1001 1000 0001 0010 0101 0110.

One can infer, in COMP-3 format, two digits are packed into a single byte. So, 459812.56, a number, which is composed of 8 digits would take only 4 bytes of computer storage. There’s a general formula for memory space calculation, in COMP-3 format -
S9(4) COMP-3 would occupy 2 bytes.
S9(6) COMP-3 would occupy 3 bytes.
S9(7) COMP-3 would occupy 4 bytes.
S9(n) COMP-3 would occupy (n+1)/2 bytes.

Saturday, December 12, 2009

VSAM Tutorial 04 – Loading Records in VSAM KSDS

Q. How do you load data into VSAM KSDS Dataset?
Storing data in a VSAM KSDS file, is known as Loading. Initially, to begin with the KSDS File is empty, it doesn’t contain any records. Based on, the Control Interval Size, that you’d have specified, while creating the KSDS File, the MVS Operating System books and reserves empty Control Intervals of that size in the KSDS Cluster. These are yet to be filled up,populated with data-records.

To actually load data-records into a VSAM KSDS file, you use IBM Supplied Utility IDCAMS. Instruct the IDCAMs utility, what’s the task you would like to perform by providing an appropriate control statement(as instream data). The IDCAMS utility picks up the Control Commands, and acts accordingly. So, the control command used to Load Data records in VSAM KSDS File is REPRO Command. In this tutorial, effectively, you are going to REPRO in the data records from a plain Sequential file into a KSDS Dataset. At the same time you’ll also learn, how to unload the contents KSDS Dataset back to a plain sequential file.

Q. Hey, tell me what’s the syntax for the REPRO Command? How do I write a Batch Job/JCL with IDCAMS and REPRO Command?
The REPRO Command in it’s simplest form looks like this -

REPRO INFILE(input-ddname)

In the above syntax, the input-ddname is DD Card for the Input Dataset, which happens to be the Physical Sequential(PS) Dataset, the source which currently holds the data-records. The output-ddname is the DD Card for the Output Dataset, which should be the destination VSAM KSDS File. So, let me quickly put together an example, that’ll show how to load records in a dataset. I am going to create a KSDS Dataset, to store the data of Employees working in an Organisation. I would like to store their ENo, EName, Salary, JDate(Joining Date). Assume that, you’ve stored the following Employees Data in a sequential file -



As you can observe, all the data-records have a length = 23. Moreover, the Employee ID, is 2 digits. This can be used to uniquely identify each employee. Hence, this will acts as a Key in the VSAM KSDS Cluster. Note that all the Input Data Records are increasing(ascending) order of the Key(EMPLOYEE ID). If the records are out of order, it will throw an error. When you load data records in KSDS Dataset, it should always be Sequential Load.

Given below is the definition of the VSAM KSDS File : AGY0157.KSDS.EMPLOYEE, which will be used to store the Employee Records -


Notice, that the name of the VSAM KSDS Cluster is AGY0157.KSDS.EMPLOYEE. It has RECORDSIZE 23, and the Key values begin from column 0(offset) and are 2 columns wide. The word INDEXED is used to create KSDS.

To load or REPRO IN the Employee Data from PS Sequential File, AGY0157.SEQ.EMPLOYEE to VSAM KSDS File AGY0157.KSDS.EMPLOYEE, you would use the REPRO Command of the IDCAMS utility as follows :


Upon submitting this Job, the records are loaded successfully, and this can be verified by seeing the JOB SYSOUT Dataset.


You can see in bold that the NUMBER OF RECORDS PROCESSED WAS 6. This implies all the 6 records were successfully loaded into the VSAM KSDS File with Maximum Condition Code 0.

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.