Mainframes 360
The one stop destination for System Z professionals

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]

Friday, January 15, 2010

What on Earth is a Mainframe


Tutorial Description
What is a Mainframe Computer? Mainframe computers are used companies to process their business data. They offer Reliability, Availability and Serviceability(RAS). Learn about mainframe hardware, the peripheral devices you connect to a mainframe.
Operating system concepts, TSO and ISPF General Motors(GM) first started using operating systems. Multi-programmed and Time-sharing operating systems evolved. Learn about TSO as a command-processor, and how it achieves time sharing. ISPF is a menu-driven interface.
Mainframe Information Representation and Storage Learn about fields, records, files and datasets. Mainframe computers store data on Physical sequential datasets. Programs, Load-modules, User-procedures are stored in libraries called Partitioned Datasets.
Extents and z/OS file allocation  The mechanics of how z/OS allocates space to a new dataset. The location of a dataset is entered in the disk catalog. Know about B37, D37 and E37 space issues.
Get your hands wet on a Mainframe Get started, log on to a mainframe computer, allocate, edit and delete datasets.
ISPF Editor Commands The ISPF editor has built-in line commands and block commands. Learn how to edit a file in the ISPF Editor, move, copy, find and change data.
Structure of JCL A JOB tells which Program to run, what's the Input-File and what's the Output-File. Know, what’s the skeleton of a JCL like.
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.
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.
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 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]

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.