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"

Friday, January 22, 2010

Basic Framework of JCL

Q. My head’s spinning around the 3 JCL Statements : JOB, EXEC and DD. Could you tell me something more about them?
So, you’ve got the gist of the concept behind JCL, all the JCL that you going to write from hereon, maybe for the next 10-20 years, would be composed of three main statements :

//name JOB parameters...
//name EXEC parameters...
//name DD parameters...

Each of this JCL Statements have a label – a symbolic name assigned to them. Its like naming kids. Well, there could be so many boys in your area, but how do distinguish them? Of course, by their names.

In the same way, a JCL may contain a bunch of DD Statements, one for Input file, one for the output file, one for the error file. How do you tell them apart, by naming them. As a good practice, we always give names to all our JCL Statements. Names kinda help you to refer back to these statements in the future. You want to point out a particular JCL Statement to your friend, just spell out its name.

But, notice carefully, each label(name) is preceded with two slashes //. The two slashes are a JCL Statement’s signature. They indicate that the statement is a JCL Statement(one of JOB, EXEC, DD). Every JCL Statement wear the two slashes //. A naked statement without // won’t be treated as a JCL Statement.

Now, every JOB, EXEC and DD Statement has got these whole lot of parameters. What you’ll be learning throughout these tutorials is mostly the parameters. Parameters add stuff and meaning to the JCL Statement. 

Now, let me give you a booster, that’s going to help you organise the way you think about this JCL.

- JCL is made up of mainly JOB, EXEC and DD.
- JOB is easy to learn and use.
- EXEC is easy and fun to use.
- DD Statements take three forms
   1. DD Statements to read a file.(easy)
   2. DD Statements to write to the logs.(easy)
   3. DD Statements to create a new file(hard!); you’d have to learn parameters such as DISP, UNIT, DCB, SPACE and several others to code this.

Have a good look at this chart :

Image99[1]
Q. Let’s set this straight. You’ve got to give me an overview of the JOB Statement.
You code the JOB Statement at the start of any JCL you write. It tells the MVS Operating system, who’s the guy requesting the program to be sent to MVS for execution, where MVS should send the print output, how much reporting(level of detail) should MVS provide, and how important is the Job as opposed to other competing jobs.

You can even indicate things like memory and processing time limits on the JOB Statement.

You write the JOB statement starting with a name, which becomes the JOB Name. JOB Names are a big deal, because MVS keeps track of thousands of Jobs using Job Names.

The most general form of the JOB Statement is this :
//AGY0157A JOB ...other parameters

As a programmer or developer, when you code some jobs for executing the programs that you’ve written, the job-name that follows the slashes, is your TSO-userid followed by a single letter. Like my TSO-userid happens to be AGY0157, so I’ve coded the job-name as AGY0157A. By doing so, anyone who happens to look at these jobs will deduce, all Jobs of the format AGY0157* belong to(are owned by) the TSO User-id AGY0157. It becomes so much each easier to trace back/revert back to the owner. God forbidding, should your job fail for some reason, the operator can immediately find out, to whom the job belongs and contact the respective owner.

The content of your JOB Statement usually very stable. Once, you have established a JOB Statement, you can use it for most of your work. Sometimes, your project leader or client Manager may give you an account-number to use, so that the resources used to run your job, maybe charged to an appropriate account.(The example, I have written is going to use the Account-no A123)

You are going to use other parameters like CLASS, MSGCLASS, MSGLEVEL, NOTIFY, REGION, TIME, and PRTY in you JOB Statements. Hey wait, don’t hit on the gas right now, hold on for a while, I am going to discuss the JOB Statement at length in the next tutorial.

In the figure below, I’ve reproduced the JCL, I wrote to copy one file to another using IEBGENER Utility program. Notice, the two different styles of coding the parameters. You can code just one parameter on each line to make it more readable.

Image101[1] 
(a) You can code JCL with a compact JOB Statement and put several parameters on the same line (b) An easier to read-style, is to code one parameter on each line, leaving room for comments.
Q. Could you give me a brief idea about EXEC Statement too..?
The EXEC Statement is the engine of your JOB. The EXEC statement tells the MVS, which program to run. So, you use EXEC JCL Statement, to announce to the MVS, which program, you want to run.

//STEP01 EXEC PGM=IEBGENER

Like any other JCL Statement, you write the EXEC Statement starting with two slashes //. You assign a name/label to the EXEC Statement, for unique identification like STEP01, which is called Step-name.

Let us make no mistake in understanding that -
1. The step-name is just a name given to the EXEC Statement. The step-name could be omitted as well. However, its always good to name all your EXEC steps, so that you can always refer back to step later. This would count a lot, pretty important stuff, when you write multi-step jobs.

2. AS Shakespeare has said, what’s in a name? A step-name is just a name given to the EXEC Step. The name could be possibly anything at all, it doesn’t need to always start with //STEP prefix. You could also name your step as //QUASAR or //BARABARA or //COPYSTEP or any name of your choice. But most people would use a step-name which is meaningful, and conveys the meaning of the step.

3. The executable program that you want to run, should be specified after PGM.

You can code a lot of extra things on the EXEC Statement, such as REGION, TIME, COND, PARM and ACCT. I’ll give many more inputs to my readers, about these extra parameters, as you progress through the tutorials.

Image102[1]

In the above JCL, to copy the contents of a file to another file, using IEBGENER, when you take a glance at the JOB Statement, you would find that I’ve coded REGION and TIME Parameters on the JOB Statement. REGION and TIME specify memory space limit and time limit on the JOB. But guess what, if you code the REGION and TIME Parameter on the EXEC Statement, that allows you to specify a memory limit and time limit for that program or step only.
Q. Could you give me a brief overview of how DD Statement refers to files?
A program executed at a step can access zero, one or more Files(Datasets). For each dataset, the program accesses, you must code a DD Statement.

MVS frees and relieves the programmer/developer, from having to know the actual(real) name of the file, and other details about the files, while writing a COBOL or PL/I Program. The programmer is unaware of the real file. Instead in COBOL, he refers to the input file(s) and output file(s) only by their symbolic DD-names. COBOL Program refers to files by their smbolic dd-names. It is through the DD Statement in JCL, that assign actual physical files to these symbolic dd-names. Thus, the dd-names serve as an indirect reference to the actual file.

How symbolic dd-names are associated with actual, physical files, is explained in the diagram below.

Image104[1]

The COBOL Program refers to the files as INPUT-FILE and OUTPUT-FILE. In the JCL, you specify the actual(real) files in the DD-Statement, AGY0157.INPUT.DATA and AGY0157.OUTPUT.DATA. The common connecting link/bridge between them is the dd-name INPUTDD and OUTPUTDD.

In the COBOL Program, the INPUT-FILE and OUTPUT-FILE shall represent the file whose dd-names are INPUTDD and OUTPUTDD. In the Job JCL, the ddnames //INPUTDD and //OUTPUTDD are set to point to the files AGY0157.INPUT.DATA and AGY0157.OUTPUT.DATA. Thus, this helps establish a relationship. Thus, the COBOL Programmer and the one who writes the JOB; there should be common agreement amongst them, with regards to the dd-names. If the COBOL program expects an input file, with dd-name INPUTDD, which is not supplied in the JCL, this would be a JCL-Error.

The same applies to the IBM-supplied Utility programs like IEBGENER, SORT, IEBCOPY etc. The developers of IEBGENER assumed dd-name of input file as SYSUT1, and output file as SYSUT2. The //SYSUT1 and //SYSUT2 DD Statements must appear in your JCL. Thus, for built-in IBM Utility programs, there are some pre-defined dd-names, which you have to stick to.
Q. Could you give me a short description of the 3 different types of DD-Statements?
As I mentioned before, the 3 general categories of DD Statements are :
1. A DD Statement for reading a file/dataset
2. A DD Statement for recording/writing to the log(diary). MVS operating System keeps a log, a diary of notes of how each job ran, whether it was successful or a failure. With this DD Statement, you can scribble and write anything you wish to the log
3. A DD Statement for creating a new dataset, and writing to the file(dataset).
 
Let me explain this, with a concrete example. Click here to download this Job-Listing and try it out on your PC. -

Image105[1]
Reading a file or Dataset
The IEBGENER program expects to read the records from the Input file at the //SYSUT1 DD Statement. There’s nothing much to it, DD statement for reading records from an Input file is damn easy.

Creating a new Dataset, and writing records to it(Hard!!)
The IEBGENER program expects to write the records to the output file at the //SYSUT2 DD Statement. To create a new file/dataset in JCL, as you can observe, you need to code a lot of extra parameters like SPACE, UNIT, DCB etc.

Writing to the log
To make note in the logs(diary), to write any text to the logs, you code a parameter on the DD Statement called SYSOUT=*.  Logs are indicated by coding the parameter SYSOUT=* on the DD Statement.
 
While running your job, ,MVS keeps prepares a status report about how your program is running, its status, whether it succeeded or failed. Thus, this status report report messages are important, because they tell you whether the Job ran fine.

The MVS OS expects to write status report messages to the output file at //SYSPRINT DD Statement. By coding the SYSOUT=* parameter on //SYSPRINT DD statement, you redirect all MVS Messages to be recorded in the logs.

Image106[1]

Thursday, January 21, 2010

The Structure of JCL


Q. What is Job Control Language?
Job Control Language(JCL) is used to tell the computer what programs to run, which files these programs will use, to read input data and write output data. 

Mainframes are different from your Windows PC, where you give an input command, and the computer  produces some output, then you give some more input, the computer produces another output and so on, this interactive input-process-output cycle continues, until all the processing is done and your task is completed. On the Windows PC, programs run in an online interactive mode. Generally there is only 1 user to a PC, and it provides immediate response(output) to a user Input.

On the other hand, millions of people send request, feed inputs to a Mainframe. Thus, Mainframes don’t like to talk to people interactively. Instead, Mainframes process your data in Batch Mode

Batch Mode means, that you need to tell the Mainframe, right at the start, what is the program you want to run, in which file the input data is stored, what will be the output files, everything right at the beginning, even before the Mainframe starts with your task. Specify the program, the input source files, the output destination files, before the program commences to run.

Once the Mainframe knows all the details about your task – Program to be run, Input files, Output files(to store results), error files etc., it accepts the task.  The task may take an indefinite amount of time to complete, the Mainframe schedules the task for a particular time, depending on which time-slot is available. Just like you, there would be millions of other guys, whose tasks have to be completed. On Mainframes, you would not get immediate output results(immediate service) on the spur of the moment(on the go). Instead, the Mainframe performs the task as per its convenience, and notifies you, alerts you, once your task is completed.
Q. Isn’t TSO/ISPF interactive? I give some input, and it immediately displays some output screen.
You might be tempted to think so, because you used TSO to deal interactively with a Mainframe via a 3270 terminal or PC. However, what you need to realize, is that, TSO itself is a program that’s being run on the Mainframe. It’s actually a Giant Word-Processor, that lets you key in(type in) your programs and Job Control Language into the computer. It actually converts your programs and JCL, into machine-readable form, an internal format which the MVS Operating System can understand. Thus, TSO is just a messenger/carrier to the MVS Operating System.

If you want to talk to the MVS Operating System, your messages, instructions or commands must be in a language called Job Control Language(JCL). JCL is the only way to talk and give instructions to the MVS Operating System!
Q. How does JCL execute Programs? 
A Program is sequence of instructions to the computer, that performs some task/function. A Program is usually written in a High-Level language like Assembler, COBOL, PL/I, C, C++, Java etc. Your program statements are then translated into binary machine language, which IBM Mainframes understand. These machine language programs are stored as members in Partitioned datasets. The Partitioned Dataset(PDS), whose members are Machine Language Programs is called Load Module Library, and each such binary program, or member is called Load Module.

To execute a program, you specify which Load Module, and load library in the JCL.
Q. How does MVS Operating System think about Programs?
MVS Operating system doesn’t know about the internals of your COBOL Program. It simply looks at it as a Black-box, which expects some inputs and produces some outputs(without bothering about what’s there inside the box).

Just as you write your own COBOL Programs, to perform some tasks, IBM provides some pre-written ready-made programs, that you can directly lift and use in order to perform some common, basic functionalities. For example, when YOU want to create a copy of a file, you want to sort the contents of a file, there are ready-made programs supplied by IBM, which can do these tasks for you. Such pre-written, ready-to-use programs shipped along with Mainframe computers are called Utility Programs.

One of the ready-made utility programs provided by IBM is IEBGENER. IEBGENER is used to copy the contents of one file to another. It basically creates a shadow copy of a file.

All COBOL programs(whether your own program, or pre-written & ready-made utility) refer to the input and output files that they access, not by the actual(physical) file name, but using a short symbolic name. The short (alias) symbolic name merely refers to the actual file name values. Through JCL, you will be attaching the actual physical file-names to the symbols. 

The IBM Utility – IEBGENER expects 4 files :
Symbolic file name     Description
1. SYSUT1              Where IEBGENER expects to read Input Data
2. SYSUT2              Where IEBGENER expects to write Output Data
3. SYSIN               Where IEBGENER expects to receive any special and optional instructions
4. SYSPRINT            Where IEBGENER expects to write a simple report, about the task it’s done for you, whether it got completed successfully or not, and much more.

Thus, IEBGENER reads input from //SYSUT1 file, and copies it to //SYSUT2 file. It is a simple copy utility.

Image97[1]
Q. What are the different statement types in JCL?
JCL is very simple and easy to master. There are only eight different JCL statement Types. JCL is is actually a piece of cake, because you use only three of these JCL statements most often – JOB, EXEC and DD.

You’ll use these very often!

//name JOB parameters ...
//name EXEC parameters ...
//name DD parameters ...

You’ll use these to “gift-wrap” and pack your JCLs into PROCs

//name PROC parameters ...
//name PEND parameters ...

These are [optional] -
//* comment
/* delimiter
// null ending statement

Now, I shall focus mostly on the 3 important statement types – JOB, EXEC and DD first, so that you can start to write JCL’s and become productive soon. In the later course of this tutorial, I shall also explain to you how to pack JCLs into Procedures using PROC and PEND.

The next figure shows how I use JOB, EXEC and DD Statements to copy a file using IEBGENER Program. Below you shall find a stripped down, bare-bones version of the same.

General format:
//AGY0157A JOB parameters..
//*    
//STEP01 EXEC parameters..
//SYSUT1 DD parameters..
//SYSUT2 DD parameters..
//SYSPRINT DD parameters..
//SYSIN DD parameters..
//    

I hope you recognized this pattern – JOB, EXEC followed by one or more DD Statements. The JCL for all you Batch Jobs will start with one JOB Statement. Following this, the EXEC statement tells which program to run. And, then you code several DD(Data Device) statements, for specifying the input and output files being used by the program. The DD Statement, would assign a symbolic name to an actual dataset name.

Given below is the JCL that executes the IEBGENER Program to copy the contents of the Physical sequential(PS) file AGY0157.INPUT.DATA to AGY0157.OUTPUT.DATA. Click here to download this Job-listing on your box.

Image98[1]

Saturday, January 16, 2010

Mainframe Information Representation and Storage


Q. How do Mainframe Computers store Data?
On computers, data is stored in the form of bits - 0’s and 1’s(binary). Characters like A,B,C,...,Z are formed with 8 bits called as Bytes. When you press a key on the keyboard, the key emits out eight bits from the cable.

Every key is represented with a unique combination of 0s and 1s. Because, we use 8 bits to store a character, a total of 2^8 = 256 patterns are possible. IBM Mainframe’s designers assigned a unique 8-bit pattern to each character. This scheme of representing characters and data in Mainframe Computers is called Extended Binary Coded Decimal Interchange Code(EBCDIC).
Q. What are Fields, Records, Files and Datasets?
Data such as Customer Name, Customer Address, Phone-numbers are nothing but, just a sequence or group of characters. A group of characters that represent a data-item is called a Field. For example, Customer-name is one field, Customer Address is another such field and so on.

When you group fields like Customer’s name, address and phone-number together, to represent all the information about 1 single customer, it is called a Record. A record can contain of any number of fields. Thus, you can have a record which 100 bytes long, 200 bytes long,..., but records of length 80-byte are common in Mainframes, as in early, input data was fed to Mainframes using Punched Cards which had 80-columns.

When you store a group of records, say 1000 customer records of a Bank, it is called a File. A File is then, just a sequence of records.

IBM Mainframes use the term Dataset instead of File.

Generally, Datasets(Files) are stored on Computer Storage Devices. In Mainframes, there are two popular storage devices – Disk and Tape.


Image81[1]
               
                         INFORMATION STORAGE HIERARCHY
Q. How do you form Dataset Names?
In a Mainframe computer, there would be thousands of files(datasets). It is obvious, to name each Dataset differently. Mainframes support very large dataset names. In Mainframes, a dataset name can be 44 characters long in this format :
XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

You can form a dataset name by taking groups of upto 8 characters. Each of the group must start with a capital letter(alphabet).

Generally, it is a good practice to give meaningful names to your dataset. For example, if you are storing Employees data in a file, you can name it as EMPLOYEE.DATA

The MVS Operating System keeps track of groups of datasets by referring to their names, which are called Qualifiers. The first part of the dataset name is called High-level Qualifier(HLQ).

Generally, when you access or log-in to Mainframes, you are given a USER-ID, just as on Windows PC, you need a userid to login. Most professionals or software engineers who work in Mainframe Projects would have a TSO user-ID. When you use a TSO-id, a special requirement applies to most datasets(files) that belong to you.

Suppose your TSO-id is AGY0157, then all your datasets should have the High-level qualifier AGY0157. Thus, the files that belong to you should start with AGY0157. For example, the name of Employees file would be

AGY0157.EMPLOYEE.DATA

You must understand that, mostly in projects, you can identify the files that belong to you, your application or your system by seeing the High-level Qualifier.

In fact, Mainframes are also installed with Security Software(like RACF), that controls access to files by seeing the High-Level Qualifiers. Thus, although you can see your buddy’s files on a Mainframe, you cannot make any changes to it.
Q. What are Sequential Datasets?
You can think of sequential datasets as a Music cassette, on which music songs are stored one after the other. When you play the cassette, you listen to the music, one song and then the next song and so on.. till you reach the end of the cassette. You cannot directly jump to, or fly to the 5th song, or last song. Thus, a music cassette is accessed sequentially.

On the same lines, records in Sequential files are stored after the other in a series. In a sequential file, you need to read through all the records one by one, step-by-step till you reach the desired record.

Thus, a sequential dataset is the simplest form of dataset. In Mainframes MVS Operating System, sequential dataset is known as PS Dataset, PS stands for Physical Sequential.

Image83[1] 
Q. How do you create a file in ISPF?
ISPF organises most common functionalities that you need to perform on Mainframes – like creating a new file/folder, editing a file, searching for files, taking backup etc. in the form of menus, just like a Nokia Cellular Phone.

To create a new file, you have to go to the menu 3.2 in ISPF. You enter the dataset name here on ISPF Screen.

Image82[1] 
Q. What is a Partitioned Dataset(PDS)?
When you create a sequential dataset(PS), it occupies a large amount of storage space(minimum 50,000 bytes). Sometimes for doing trivial tasks,  storing only a few records, you would not be utilising the entire space available in a sequential file. Thus most of the space in the Sequential file is wasted and is blocked.

IBM provides a way to split or partition up the space in a sequential data-set. IBM Software engineers invented the Partitioned Dataset, often called PDS. Each part is called a Member. A Partitioned Dataset can have many members(parts). Each member behaves like a sequential file on it own.

How does the PDS then keep track of its members? A Partitioned Dataset(PDS) includes a directory(like a telephone directory), which is a diary or journal, where MVS Operating system keeps track of the members in a PDS. The members of a PDS can be scattered haphazardly anywhere in the vast computer storage space. Well-then, you consult the directory to find out the members in the PDS. Just like in a book, the index tells you, the keyword you are looking for, and the page no. where it can be found, the same way, the directory tells you the member name, and the computer memory address where you can find it. Thus, the directory maintains the list of member-names and pointers to the actual physical place in Computer Memory where they are stored.

Not just this, but the directory also keeps track of its statistics, like when each member was created, when was it last changed/viewed by somebody, how much space it occupies, which TSO-userid created it and bla bla..

On the Windows Operating System, we generally keep related files together in a folder. On the same lines, you keep related members together in one PDS. Thus, a Partitioned Dataset is Mainframes-counterpart of Folders on Windows Operating System. Folders contain many related files. A PDS contains many related members.

When create this special type of partitioned sequential file – Partitioned Dataset, you need to decide, how big its directory is going to be. The bigger the directory, the more no. of partitions(members) it will support. You express this in terms of Directory Blocks. Generally, 1 directory block can store information about 5 members. The directory always remains fixed, can’t grow bigger on the fly, so you need to careful when specifying the directory blocks, and you have to do it in advance.

Image84[1]

To sum up, a Partitioned Dataset(PDS) is a specialised type of sequential file, which is divided into members, each member being a sequential dataset by itself. Thus, a PDS acts like a library which houses several related files.
Q. While creating a new file in ISPF, how do I specify whether is Sequential file(PS), or a Partitioned Dataset(PDS)?
A sequential PS File doesn’t have any partitions or members(0 members). So, it doesn’t have a directory to look upto. Thus, the space allocated to a directory, in terms of Directory Blocks for a Sequential PS File is 0.

On the other hand, for Partitioned Dataset(PDS), it can contain 1 or more members. So, it needs a directory to record the whereabouts(location) of its members, which are scattered throughout the memory randomly. You need to allocate space in terms of Directory Blocks to a Directory in Partitioned Dataset(PDS). Thus, Directory Blocks for a PDS should be some finite number, say 5 blocks, or 10 blocks.

Suppose you are creating a new File AGY0157.EMPLOYEE.DATA. You specify the Directory Blocks on the ISPF Menu 3.2 screen, as follows -

1. If you want the file AGY0157.EMPLOYEE.DATA to be a Physical Sequential File(PS), then fill the Directory Blocks field = 0.

Image85[1]

2. On the other hand, if you want the file AGY0157.EMPLOYEE.DATA to be a Partitioned Dataset(PDS), having 1 or many members, and a directory, specify Directory Blocks field = 1,2,3 or ...(any finite value) blocks. In the figure below, I have put Directory Blocks = 5 Blocks.

Image86[1]
Q. How do I find the file I want on Mainframes? How do you find/list files in ISPF?
You want to search and locate a file. Finding the file on MVS Operating System is done using, ISPF Menu 3.4, called Dataset List Utility. Go to ISPF Menu 3.4 screen, and type the name of the dataset that you want to search and hit Ctrl.

For example, if you want to search for the file AGY0157.EMPLOYEE.DATA, then type AGY0157.EMPLOYEE.DATA in Dsname field.

Image87[1]

Upon hitting the Ctrl button, you would find list of files displayed before. Note that, Dataset List Utility(DSLIST) works by searching for all files that match a pattern. So, when you type AGY0157.EMPLOYEE.DATA, what you actually specify is a pattern.

All files matching this pattern will be displayed. So, if there is a file – AGY0157.EMPLOYEE.DATA.MASTER, it also matches the pattern. Thus, it will also be listed.

Image88[1]

In fact, if you don’t know the exact name of your file, you can just specify the pattern followed by a wild-card. Say, for example, if you want to search for all the files starting with AGY0157.DEMO.something, then you can specify it as AGY0157.DEMO.*

Image89[1]

When you hit Ctrl, you would get the list of all datasets(files), whose names start with AGY0157.DEMO.

Image90[1]
Q. What if the file is Partitioned Dataset? How do you search the directory for the members in the PDS Library?
To see the directory of a PDS Library, you need to type M against the name of the Partitioned Dataset(PDS). The M Command tells the MVS Operating System to display the directory of the Partitioned Dataset(PDS).

Suppose, you want to see the directory(List of all the members) of the Partitioned Dataset(Library) AGY0157.DEMO.SRCLIB. Then, type an M against its name in the DSLIST Utility ISPF Menu 3.4 screen.

Image91[1]

Upon hitting the Ctrl Button, you get to see the directory of the Partitioned Dataset(PDS) AGY0157.DEMO.SRCLIB – you can see the entire list of members in the PDS.

Image92[1]

Generally, you will keep your program, jobs, REXX scripts assorted in Libraries or Partitioned Datasets(PDS). Here, I have stored all my COBOL Programs in this library.
Q. How do code member names of a Partitioned Dataset in JCL?
To refer to a member of a Partitioned Dataset in JCL, you code the dataset name with the member name in parenthesis. Here, is how you code my dataset name in JCL, when I have to refer to a job named PROGRAM1 in my SRCLIB (Source Library).

AGY0157.DEMO.SRCLIB(PROGRAM1)
Q. How do you store some data in file? How do open and edit the contents of a file?
In the next few tutorials, I’ll show you how to use JCL to run programs, read file, send output to printer, create and delete files. But, before this you need to key in some data into your computer system. This data consists of 80-byte records.

After creating a file, you need to an ‘E’ against the file-name to edit the file. Let’s assume that you wanted to key in Employee Data in Physical Sequential file – AGY0157.EMPLOYEE.DATA. Here goes. After you’ve found the file using ISPF Dataset List Utility 3.4, just type E against that dataset, and hit Ctrl.

Image93[1] 

Just as on Windows, the default editor in Notepad, typing E against the dataset name, causes the file AGY0157.EMPLOYEE.DATA to open in the editing mode. The editing mode allows you to change the contents of the file – add new data, modify the data, or delete the data. On the other hand, you can also open the file in View Mode (type V) or Browse Mode (type B). View Mode or Browse mode is a read-only mode(You cannot change the contents).

Generally, when you open Production Files(Files which are being used, when the Mainframe application is running live), it’s always a good practice to open them in read-only mode.

Initially, the file AGY0157.EMPLOYEE.DATA is empty. When you open it, in Editing mode, it looks like this -

Image94[1]

You can now key in your data in the file, and save it by typing the SAVE Command on the command line field.

Image95[1]

Friday, January 15, 2010

What on Earth is a Mainframe


Tutorial Name Things you can try at home
Introduction to Mainframes  
Mainframe Information Representation and Storage  
Get your hands wet on a Mainframe  
TSO/ISPF Commands  
Structure of JCL A JOB tells which Program to run, what's the Input-File and what's the Output-File. Click here for a simple Job-Listing that illustrates the Structure–of-JCL.
Basic Framework of JCL DD Statement comes in 3 flavours, to read data from a Dataset, Create a New dataset and store output, and Print information to the Log. Click here for a Job-listing, that demonstrates the kinds of DD-Statements.
Multi-step Job Streams A multi-step job is made up of a chain of several inter-linked steps. Each Step runs a Program, takes input from preceding step, processes the Data, and produces output to be fed to the next Step. Click here, to play around with a 3-Step Toy Job .
Submitting a Job For This exercise, here are the artifacts
1. The Data Input File – referred to as 'AGY0157.DATA.INPUT'. Click here. You'll need this, before you try to run the 3 step-Job.
2. The JESMSGLG Message Log Listing – After submitting the job, this is what the Message-Log in the SPOOL looks like. Click here.
3. The JESJCL Listing – This will contain the original source-JCL. Click here.
4. The JESYSMSG Listing – This will contain any allocation/deallocation messages. Click here to see how it looks.
5. The Sorted Output SYSPRINT Listing – After running the 3-step toy-job, the Output Data is present in the SYSUT2 Listing of //STEP03. Click here to see it.

Thursday, January 14, 2010

Table Handling

Q. What is table in COBOL? How do you define a Table?

In COBOL, you’ve learnt how to store a simple integer number, real number, text-strings etc. in Computer Memory. A simple variable can hold only one, single data-item. For example, a PIC X(10) variable can store the text-string ‘HELLOWORLD’, a PIC 9(03) variable can store the integer number 125, and so on.

However, in your day-to-day life, you often come across a list of items, say your shopping list, your phone-book(list of contacts), your favourite books(list of books) etc. What if, you want to store a list of data-items in Computer Memory? Say, for example like a collection of 5 PIC X(10) text-string’s, or 100 PIC 9(03) numbers.

Table can be used to store a list of data-items. An table is a list, a collection of similar data-items. So, Tables store multiple data-items of the same type. Take data-items, which are logically-related to each other, and put them together, in a table. For example, a table of integer numbers = {1, 2, 5, 8, -6}. Thus, in essence, a table is a set of data-items of the same type.

A table must be assigned a unique name. Say, for example, you can take a table, a set of PIC 9(04) numbers {1000, 2000, 5000, 8000, 6000} and assign it the name INCOME-TABLE. Then INCOME-TABLE = {1000, 2000, 5000, 8000, 6000}. The table INCOME-TABLE is said to have five members – 1000, 2000, 5000, 8000 and 6000. These are called elements of the Table. The number of elements in an table is called the size of the table, or table length.

Q. How do you refer to individual elements of a table?

Consider the table INCOME-TABLE = {1000, 2000, 5000, 8000, 6000}. You access the elements of a table, by specifying the position. The element at the 1st position is 1000, 2nd position is 2000, 3rd position is 5000 and so on... So, if you were to ask a question, “Give the element at position 4”, the answer would be 8000.

Q. Could you demonstrate via an example, how to create a simple table and retrieve data from it?

Suppose you want to store the names of you 5 friends in a COBOL Table. To create a table in COBOL, you must understand 3 important things -

Q1. Assigning a unique name to the table
A. FRIENDS-TABLE is the unique name of the table

Q2. What is the data being recorded in this table, and how many data-items it contains?
A. The data generally stored in this table represents your friends information. So the name of the record should be FRIEND-RECORD. The FRIEND-RECORD should store information about 5 friends. So, it contains 5 cells.

3. What is the specification/PICTURE clause for each such data-item?
Each such cell contains FRIEND-NAME, which is textual-string and can be 20 characters long.

In COBOL, you would write

01  FRIENDS-TABLE
    02 FRIEND-RECORD OCCURS 5 TIMES
       03 FRIEND-NAME PIC X(20)

Understand that the OCCURS Clause is used to specify, how many items(cells) are contained in the record.

Image73[2]

Now, you can access the elements of this table as follows :

To access your first friend’s name, you write FRIEND-NAME(1)
To access your second friend’s name,you write FRIEND-NAME(2)
...
To access your fifth friend’s name, you write FRIEND-NAME(5)

The COBOL Definition of the above friend’s table, would look
like this :

Image74[1]

Given below is a simple COBOL Program, that shows how to store data in the Friends table, and display the contents of the table.

Image75[1]

Upon running the above COBOL Program, you should get the following output -

Image76[1]

Note: Since, FRIEND-RECORD is a group consisting of only one sub-item, you can use FRIEND-RECORD and FRIEND-NAME interchangeably. Which means,
FRIEND-RECORD(1) and FRIEND-NAME(1), both would work.

Q. Can the elements of the table be more complex group-items?

The elements of a table can be simple data-items like a number PIC 9(04), or a text-string PIC X(10). On the other hand, they may also be complex group-data-items, like 01 EMPLOYEE item, which in turn consists of a 02 EMP-NAME PIC X(20) text-string and 02 SALARY PIC 9(04) number. So, you can have a table of 50 numbers, 100 text-strings or 3 employees.

In the example, given here, I have created a table, that stores the data of 3 employees. The temporary variables defined in the Working Storage Section of the COBOL Program.

Image68[1]

Now, the table EMPLOYEE-TABLE can contain the data of 3 employees. Now, you can write a COBOL Program, to store some data in the Employee Table, and then display its contents.

Look at the sample COBOL Program, given below.

Image69[1] 

Upon running the above COBOL Program, you get the following output -

Image70[1]

Q. What are two-dimensional tables? How do you create them?

A table is a collection/list of data-items. Each data-item can be a simple data-item, or a complex group-item. What if the data-item is a table? Thus, you have a “Table of tables”. A 2-dimensional table looks like a matrix of cells, consisting of rows and columns. To access any cell at the intersection of a row and column, you need to know the row-no and the column-no.

Suppose, we wish to setup a table, which will represent the below statistic. The table below gives the class-wise and year-wise breakup of the spending capacity of an Indian Household.

Spending of an Average Indian Household annually in Rs.

Image71[1] 

First let me show, how to create Working-Storage definition for this table in COBOL. You need to create a 5 x 4 table(5 rows, each having 4 cells)

1. You need to assign a unique name to the table, so say the name of the table is AVERAGE-INDIAN-SPEND-TABLE.

01  AVERAGE-INDIAN-SPEND-TABLE.

2. Next, we have collected statistics for 5 different classes. So, the table will contain 5 records – one for each class.

01  AVERAGE-INDIAN-SPEND-TABLE
    02 SOCIAL-CLASS OCCURS 5 TIMES

3. Next, each of the classes, Upper, Upper-Middle, Middle-Middle, Lower-Middle and Lower class give the year-wise breakup of the money spend for 4 years (2007,2008,2009,2010). So, each row contains 4 cells.

01  AVERAGE-INDIAN-SPEND-TABLE 
    02 SOCIAL-CLASS 5 TIMES 
       03 YEAR OCCURS 4 TIMES

4. Moreover, the actual data in each cell is the money spend in Rupees. So, in general, each cell has the format PIC 9(4)V99.

01  AVERAGE-INDIAN-SPEND-TABLE 
    02 SOCIAL-CLASS OCCURS 5 TIMES 
       03 YEAR OCCURS 4 TIMES
          04 AMOUNT  PIC 9(5)V99

In COBOL, you can in-fact go a level further, and create 3-dimensional cubes, 4,5,.. upto 7-dimensional tables as per COBOL-85 Standard.

Q. Can you suggest any general formula for creating two-dimensional tables in COBOL?

Consider the following working-storage definition of a table

    02 A OCCURS r TIMES
       03 B OCCURS c TIMES
          04 CELL PIC p (p = field size)

In general, the above formula holds to create a table of size r rows x c columns, where each cell has PICTURE Clause PIC P.

The PICTURE Clause is used at the lowest hierarchical level of a table.

Q. Could you show me a complete example of how to store data and retrieve data from 2-dimensional tables?

Let’s take the example of the AVERAGE-INDIAN-SPEND-TABLE. The COBOL Definition of this table is shown below -

Image77[1]

The below COBOL Program, shows how to fill up AVERAGE-INDIAN-SPEND-TABLE with values. You can refer to any cell of this 2-dimensional table by using (row,col). For example, to refer to the amount in 2nd row, 4th column, you would write AMOUNT(2,4).

The COBOL Program is divided into 2 parts :-
1) Filling(Initialising) the Table
2) Displaying the contents of the Table

Image78[1]

The next COBOL Paragraph displays values in the AVERAGE-INDIAN-SPEND-TABLE on the screen.

Image79[1]

Upon running the above COBOL Program, you get the contents of the table
displayed on the screen.

Image80[1]

Thursday, January 7, 2010

EVALUATE Statement – Part II


Q. What values the Subject and Object in the EVALUATE and WHEN Clauses can take?
In the EVALUATE Statement, the subject and object may equate to one of the below -
1) TRUE or FALSE – The subject or object may contain TRUE/FALSE constant. Also, if the Subject or object is condition, then its value would be either true or false.

2) A Value – The subject or object may specify an expression(A + B – C) or variables like AGE, whose result is a definite value. Moreover, it may also specify a literal-data value directly like 35.

3) A range of values – The object may also be specified as a range of values, for example, to specify a range or values (3,4,5,..,7), you could simply write 3 THRU 7.
Q. Could you explain the above idea simple and easy-to-remember example?
Suppose you want to write a COBOL Program, to calculate your income-tax payable in India for the financial year 2009-10, as per the slab in which your income falls.

RATE-OF-TAX
STATUS TAX-SLAB
0 percent MALE 0-1,60,000
  FEMALE 0-1,90,000
  SENIOR-CITIZEN 0-2,40,000
10 percent MALE 1,60,001-3,00,000
  FEMALE 1,90,001-3,00,000
  SENIOR-CITIZEN 2,40,001-3,00,000
20 percent ANY 3,00,001-5,00,000
30 percent ANY 5,00,001 and above

The necessary working-storage variables for the above COBOL Program are as shown below-
Image65[3]

The EVALUATE statement in COBOL, which calculates the Income-tax according to the above given rules, is as follows :

Image66[2]

In the above COBOL Program, I have assumed that the taxable income of the individual is 2.5 lacs, and she is female. 2.5 lacs salary for a female falls into the second tax slab, where the income tax rate is 10 percent. Upon running the above COBOL Program, you should get the following output :

Image67[2]

Wednesday, January 6, 2010

EVALUATE Statement – Program Flow Control

Q. What is the EVALUATE Statement used for? How does it work?
When there are multiple options to choose from, the EVALUATE statement works best. When there are several choices to be made, IF-ELSE logic can become very complicated. To avoid writing complex nested IF Conditionals(condition-within-condition), the EVALUATE Statement can be used. The EVALUATE statement is the COBOL equivalent of switch-case in most conventional programming languages.

The general format of the EVALUATE Statement is as follows :

Syntax:

EVALUATE <expression>
   WHEN condition-1
     Statement-1
     ...

   WHEN condition-2
     Statement-2
     ...


   WHEN OTHER
     Statement-n
     ...

END-EVALUATE
STATEMENT-X

Interpretation:

The EVALUATE computes the value of the main expression.

1. If the value satisfies condition-1, then Statement-1 is performed, and after execution, control jumps to STATEMENT-X(Outside the EVALUATE Block).

2. Else If the value satisfies condition-2, then Statement-2 is performed, and after execution, control jumps to STATEMENT-X(Outside the EVALUATE Block).

...

n. If the values satisfies none of the above conditions, then by default WHEN OTHER case is executed(Statement-n), and then the control jumps to STATEMENT-X.(Outside the EVALUATE Block)

Thus, at each level of the EVALUATE block, the condition is checked, if it holds true, the case is executed, if it doesn’t hold true, you descend to the next lower level and so on... This is called a fall-through.

Example:

Image60[1] 
Upon running the above COBOL Program, you should get the following output-

Image61[1] 
Q. What are subjects and objects in the EVALUATE Block? How are they used?
Generally, the expression being tested, specified by EVALUATE Clause is called the subject. The values against which it is tested, specified by the WHEN Clause is called the object. Thus, you test a subject expression against an object value using the EVALUATE case structure.

The EVALUATE Block allows you to specify the multiple subjects and objects. Each subject in the EVALUATE Clause would be tested against the corresponding object-value in the WHEN Clause.

Example:
Suppose you want to write a simple COBOL Program to decide the pay of an employee. The pay of the employee is calculated as per this table.

CONDITION
DESIGNATION  LEVEL-OF-EXP  FLEXIBLE

Salary

            ACCOUNTANT    EXPERIENCED   WILLING-TO-TRAVEL 2000
            ACCOUNTANT    INEXPERIENCED WANTS-TO-STAY-PUT 1000
     COMPUTER-SCIENTIST   ANY           ANY 3000
     SYSTEMS-ANALYST      EXPERIENCED   ANY 4000
     ANY                  EXPERIENCED   ANY 500

There are 3 subjects that you need to evaluate in above table, to decide the salary of the employee. The variables for the above data in COBOL are as shown below:

Image62[1] 
To calculate the salary of the employee according to the above decision chart, I have written the following code in COBOL :

Image63[1]
Now, in the above COBOL Program, I have set ACCOUNTANT flag to true, and he is INEXPERIENCED, and wants to STAYPUT. For such a condition, the salary should be 1000. Upon running the above COBOL Program, you should get the following output :

Image64[1] 

Friday, January 1, 2010

Program Flow Control


Q. What does one mean by ‘Program Flow Control’? Why is it important?
COBOL allows programmers to write computer programs in a systematic manner. You can divide and organize your programs into sections and paragraphs. Each section or paragraph is dedicated to perform a specific task or function. While writing a particular section or paragraph, you can focus and put all your energy, towards the task you want to perform, without bothering about the rest of the program.

When the control first enters into the Program, depending upon what task is to be performed, you accordingly just direct/transfer the control to the appropriate section or paragraph, jump to the relevant para. This idea is called Program Flow Control.

You have written the program, in a well-organised manner. If an error occurs in particular task/functionality, you only need to search and rectify the error in that section or paragraph corresponding to this functionality(You don’t need to search the whole program).
Q. How do you write SECTION’s and PARAGRAPH’s in COBOL?
Just as DIVISION’s start in Area A(Columns 8-11), Section names and Paragraph names should begin in Area A. Every Section name and paragraph name should end with a period.

Moreover, it is customary to follow a naming-convention for paragraph-names. Generally, the naming convention for COBOL Para’s used by most programmers(in different shops) is to prefix the paragraph name with a number. For example, if your program has 2 paragraphs INDIA and CHINA, then name them as 0100-INDIA and 0200-CHINA. This way, it becomes easier to identify them.

Given below is simple example of a typical COBOL Program that is divided into two sections READ-FILE-SECTION and WRITE-FILE-SECTION, each of them containing one paragraph.

Example:

Image52[1]

Think what if, you executed this COBOL Program. The starting point of the program is the PROCEDURE DIVISION. Each statement is executed by the computer one-by-one sequentially. It is terminated at STOP RUN. Thus, the output on the screen(SYSOUT Dataset) should be

Image53[1]
Q. What is PERFORM Statement used for? How does it control the program flow?
One of the statements in COBOL, to control the flow of the program is PERFORM Statement. The PERFORM Statement basically transfers control(jumps) to the specified paragraph or section.

The general syntax of PERFORM Statement is :
PERFORM <procedure-name>

The procedure-name refers to the name of the paragraph or section that, you want jump to.

Example:
Consider the following COBOL Program, that consists of a 0100-MAIN-PARA and 0200-INDIA-PARA.

Image50[1]

The starting point is PROCEDURE DIVISION.
1. The DISPLAY ‘START OF PROGRAM’ statement causes START OF PROGRAM to be displayed.
2. PERFORM 0200-INDIA-PARA causes transfers the control(jumps) to the 0200-INDIA-PARA. All the statements in this paragraph are executed one-by-one. DISPLAY ‘INDIA’ prints INDIA to the output. After the 0200-INDIA-PARA is complete, the control returns back to the point(0100-MAIN-PARA) from where it had left off.
3. The next statement DISPLAY ‘END OF PROGRAM’ causes END OF PROGRAM to be printed to the output. The program terminates at STOP RUN.

Upon running the above COBOL Program, you should get the following output -

Image51[2]

The procedure to which the PERFORM statement transfers control, can be a 1 single para, or multi-paragraph procedure.

The general syntax to perform a multi-paragraph procedure is:
PERFORM paragraph-A THRU paragraph-Z

Suppose you have written a sequence of paragraphs : PARAGRAPH-A, PARAGRAPH-B, PARAGRAPH-C,...,upto PARAGRAPH-Z. The above PERFORM Statement transfers control(jumps) to the starting point – PARAGRAPH-A, then all the intermediate paragraphs B,C,D,...,Y between A to Z are also executed. Then, the last paragraph PARAGRAPH-Z is executed, before the control returns back to the point from where it had left off.

Example:

Image54[1]

Upon running the above COBOL Program, you should get the following output -

Image55[1]

The PERFORM statement can also be used to execute a complete SECTION consisting of several paragraphs.

Example:

Image56[2] 
Upon executing the above COBOL Code, you should get the following output -

Image57[1] 
Q. Is it possible to execute a procedure repetitively over and over again? Can PERFORM statement be used to loop through a procedure?
PERFORM Statement can be used to execute a procedure(set of paragraphs) 1 time, 2 times, 3 times, and so on.. repetitively. Performing the same task over and over again, can be done using PERFORM Statement.

When you write a PERFORM Statement to loop/repeat a task again and again, you need to specify, how many times you want to perform the task. Now, specifying how many times, you want to do something – once, twice,thrice, 5 times, 10 times... is sometimes difficult.

For example, assume that you want to read data from a file.

Read 1st record
Read 2nd record
Read 3rd record
...
Read last record

To Read a record is the task to be performed again and again. So, you can write a PERFORM Statement to do the task - READ a record, again and again till, you reach the end of the file(all the data-records have been read).

PERFORM as (i=1,2,3,..,??) 
  READ ith record

How many read’s would you do? You don’t know this upper-bound, as you don’t know the exact no. of records in the file before-hand. Instead, you could type a boundary-condition, saying that, Stop reading when you reach End-of-file.

Thus, you can specify exactly how many no. of times to perform a loop, or you may specify a boundary(termination) condition.

1. To specify the no. of times, you want to perform a loop, you use TIMES option.
2. To specify a boundary(termination) condition for a loop, you use UNTIL option.

The general syntax for the PERFORM Statement used to do a task again and again many times is,

PERFORM <procedure-name> <n> TIMES

Example-

Image58[1]

Upon executing the above COBOL Code, you should get the following output -

Image59[2]
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