Are you looking for an essay on ‘COBOL’ for class 9, 10, 11 and 12. Find paragraphs, long and short essays on ‘COBOL’ especially written for school and college students.

Essay on COBOL 


Essay Contents:

  1. Essay on the Definition of COBOL
  2. Essay on the Elements of COBOL
  3. Essay on the Coding Format Used in COBOL
  4. Essay on the Structure of COBOL Programs
  5. Essay on the Arithmetical, Verbs Used in COBOL
  6. Essay on the File Operation Using COBOL
  7. Essay on the Displaying on Monitor Using COBOL
  8. Essay on the Accepting from Keyboard Using COBOL
  9. Essay on the Compilation of Programs Using COBOL

Essay # 1. Definition of COBOL:

COBOL, which is the acronym for Common Business Oriented Language, is one of the first high level language which was initially developed in December 1959 to enable programs to be written for business data processing; where few computations and large volume of data is the general characteristic.

After several modifications over the years, a revised version was adopted by the American National Standards Institute [ANSI] in 1974. It was then further comprehensively revised in 1985. The language is continuously developed under CODASYL COBOL—Conference on Data System Language and so instead of using the word “field”, “data-names” are used to denote “fields”, which is the IBM style.

Unfortunately, to make this artificial language more like the natural English language, lot of detail? have to written—making the programs highly bulky compared to those written in later high level languages like BASIC. As it stands, COBOL is called a self-documented language, whereby one is supposed to understand a COBOL program easily.

It is no longer a popular programming language, its existence being mostly restricted to some mainframes where old programs are still used, only because it has a good library, that is, pre-developed packages of programs. In some quarters, it is being hoped that the latest revision will revive the language again! The language is mainly used for batch-processing jobs; being non- interactive to a great extent.

COBOL is a language where only compilers are available. A COBOL program is first written using a text-editor, like Edlin or Edit of MSDOS depending on the version of MS DOS, Norton Editor, Side-Kick, or the non-document mode of any word-processor.

Then it is compiled using a COBOL compiler to create the Object file, which is then linked using a Linker to create the Executable file under MS DOS operating system. The steps involved is same under other operating systems, which is writing the source-code, creating object-file, and lastly, the executable file.


Essay # 2. Elements of COBOL:

Characters and Words:

Each high level language specifies which characters and words can be used in what manner. COBOL permits use of the following 51 characters, a character being the basic unit for entering, storing, displaying, etc. different names, data values, etc.

A to Z — alphabets or letters [26 in number]

0 to 9 — numerical or digits [10 in number]

— blank space [1 character]

+ – * / — mathematical operators [4 in number]

().”$,;<>= — special characters [10 in numbers]

When the characters are used in a sequence, they form words, like say AMUL or A148 is a word. Words can be formed by using up to 30 characters, which may contain alphabets [letters], numbers [digits], and or a hyphen [-]. But the hyphen cannot be used at the end or beginning of a word. There must be at least one letter in the name. No other characters are allowed.

When a programmer uses a word made by him to denote something, it is called a user- defined word. There is one more restriction in forming the user-defined words, which is that the words defined in COBOL having special meaning, called reserved words, cannot be used by the user for different purposes.

The specification for using a reserved word is called its syntax, which specifies how the word is to be used in a COBOL program.

User-defined words are generally used as field-name or data-names.

Some examples of data-names are:

BAD BOY — incorrect. Blank spaces not allowed.

BAD-BOY — correct.

A685429 — correct.

7689540 — incorrect. There must be a letter.

BALANCE-OF-CLOSING-STOCK-OF-RAW-MATERIALS — incorrect. The length exceeds 30 characters.

Normally data names are defined in such a way that the name itself conveys some meaning of what it contains. For example, you can use FIRST-NAME as a data name to indicate that it will contain the first name of a person. You could also use N1; but that would not convey anything if you forget its meaning.

In a record, the data names [or field names] must be unique; duplication is not allowed, as otherwise, the program would not know to which data name you are referring to during a particular data manipulation. By this time, it must be clear that data names are synonymous with the variables used in algebra, which contain different data values at different stages of working.

Constants, whose value never changes, are also available in COBOL. In such a case the data name itself is the value given to the constant. For example, 084 as data name is a constant with a value of 84.

In such data names, decimal point can be used, but it must not be the last character—you can write 26.45 or 26.0 but not 26 only. This type of constants are called numeric literals. To summarise, Literals are actual values, naturally, whose values do not change.

The non-numeric literals are, as the name suggest, can contain letters in addition to numerical or only letters and other characters. These are equivalent to “strings” used in other high level languages like BASIC.

To differentiate them as non-numeric constants, the string is enclosed within quotation marks. For example “ACCOUNTANCY” is a non- numeric constant but ACCOUNTANCY is a data name. Lower case letters can be used within such strings.

Another type of constants, called Figurative Constants, are available in COBOL.

Some examples are:

ZERO, ZEROS, or ZEROES: to represent a numeric 0.

SPACE or SPACES: to represent a blank space.

QUOTE or QOUTES: to represent quotation marks.


Essay # 3. Coding Format Used in COBOL:

This high level language is extremely conservative about how the program is to be written. Unlike any other popular high level languages, the columnar position of the text is of utmost importance when writing the code, called source-code, of the program using a text editor.

Any change in spacing or not writing the code beginning from the position specified, results in error during compilation, even though the logic of the program is error-free.

Since the source document for COBOL used to be 80-column punched cards, a special printed sheet used for writing COBOL source code, called Coding Sheet has 80 column positions specified as detailed below. The source code is written on the coding sheet at clearly marked column positions. It was so required, because punch-card operators used to punch the cards looking at the respective code sheets.

Column Position Purpose

1 to 6: It is used to enter the page number and the line number of the text. The first three column positions are used to enter the page number of the coding sheet and the last three numbers for the line numbers in ascending order, which need not be consecutive. Presently these are not required and are left blank.

7: It is the Indicator position, where an asterisk “* indicates the presence of a comment line, where you can enter any remarks to improve the understanding of what the next codes are supposed to do and which are ignored by the compiler. A hyphen “-” in column 7 indicates to the compiler that the current line is a continuation of the previous line’s text.

8 to 11: It is called Margin A or Area A, where most of the text of the COBOL program begins, starting at column 8. The text can over­flow beyond these 4 columns to the next area.

12 to 72: Called Margin B or Area B. Some specified text begins in this area, starting at column 12. Actually, the column positions from 8 to 72 provide the area for writing program text, being called code area.

72 to 80: This is called Identification area.


Essay # 4. Structure of COBOL Programs:

Under the general format, every COBOL program has four distinct divisions, respec­tively written as:

i. IDENTIFICATION DIVISION,

ii. ENVIRONMENT DIVISION,

iii. DATA DIVISION, and

iv. PROCEDURE DIVISION

each division containing some specific areas of the total program. It is almost like different parts of a book.

i. Identification Division:

As the name suggests, it contains the details which identify the program, so that another programmer can know what the program is all about. It starts with the reserved word IDENTIFICATION DIVISION followed by a period, written from column 8 position. Incidentally all statements, sentences, paragraphs, divisions, etc. have to end with a period in COBOL and start at column 8, unless otherwise stated.

The division heading is followed by one paragraph titled as PROGRAM-ID., which is followed by the name of the program as given by you, if you are the programmer. There are some optional additional paragraphs also, as detailed below, which you may omit if you feel so.

Identification Division

PROGRAM-ID: Name-of-the-program.

AUTHOR: Written-by-such-and-such.

INSTALLATION: Some-details-about-hardware.

DATE-WRITTEN: When-it-was-written.

DATE-COMPILED: When-it-is-compiled.

Security: Details-about-security.

Depending on the COBOL compiler used, some more optional items can be entered, if required, but, only the Program-Id is a must. Each of the above paragraphs has to begin at column 8, also called Area A in a COBOL Coding Sheet. If a statement is to be continued to the next line, then it has to begin at column 12 [Area B] in the next line.

The name of the program as entered [a word] can only contain a maximum of 30 characters of which at least one has to be an alphabet; details for other paragraphs can be of any length, such as, the name of the author can contain 100 characters, overflowing to the next line.

A Paragraph consists of one or more sentences; a Sentence being a sequence of one or more statements, separated by a comma, the last one of which is terminated by a period. Actually a Statement is an executable code beginning with a reserved word of COBOL, which is generally a verb. As sentences are combined to form a Paragraph, similarly, Paragraphs are grouped to form Sections.

The Section names must be followed by the word SECTION to differentiate it from a Paragraph. Both must terminate with period and begin at column 8. Nothing else can be written on the line containing a Section’s name, but it is not so with a Paragraph’s name.

There must be a space after the period ending the Paragraph’s name, if something else is written on that line. In the Identification Division, all individual lines are called paragraphs.

ii. Environment Division:

When COBOL was developed, the computers used were all mainframe computers, whose hardware characteristics varied from computer to computers. The basic object of this division is to inform the compiler program what specific hardware is being used.

If a COBOL program written for a particular computer is to be operated on a computer of another make, the Environment Division has to be re-written, recompiled and linked, except for microcom­puters and hence no further entry is required to be made under this division for programmes written for use in microcomputers.

What follows is necessary for writing programs in non- PC computers. There are generally two sections under this division, named CONFIGURA­TION SECTION and INPUT-OUTPUT SECTION. The name and model of the computer used is written under the former section.

The latter section has a paragraph called FILE- CONTROL., where the details of files used, if any in the program, are to be specified, starting with the reserved word SELECT, as shown below:

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SOURCE-COMPUTER: Name and model of the computer used for compiling.

OBJECT-COMPUTER: Name and model of the computer used for linking.

SPECIAL-NAMES: It can be used to relate some hardware to names specified by the user. It can also be used to define a currency symbol, which is normally dollar.

INPUT-OUTPUT SECTION.

FILE-CONTROL.

SELECT file-name1-used ASSIGN TO device.

SELECT file-name2-used ASSIGN TO printer.

I-O-CONTROL.

The filename-used are the actual names of the files you are going to use in the program and each of these is assigned appropriately to a device like disk, tape, printer, etc. Generally output files are assigned to PRINTER to get the result printed.

You have to use a file in output mode to store data into it. The name of the file to be used is restricted to 12 unique characters. You can assign more than one filename to a device or different devices and or printers, as necessary.

The paragraph, File-Control is followed by a I-O-CONTROL paragraph. Some special clauses are entered under this paragraph, like, RERUN. This clause can be used to create rescue file as a backup measure, during data processing.

iii. Data Division:

This division specifies how much area in the RAM is to be reserved for the fields forming records and for other working. Generally it has two sections called, FILE SECTION and WORKING-STORAGE SECTION respectively. In the File Section, you have to give the details of the data files to be used in the program as mentioned under FILE-CONTROL of the INPUT-OUTPUT SECTION.

The details are:

a. Name of the File.

b. Name of the Record contained in the file.

c. Name of the Fields under the record, and

d. Size and Type of each field defined.

A typical example of the File Section, under Data Divisions given below:

 

 

 

 

 

 

 

 

 

 

 

 

As you can see from above, the first file used, called Student-file, has its record named as Student-record and it has three fields, namely, Student-name, Roll-no and Filler. The length of the record has been declared as 70 characters.

The Filler, a reserved word, is a special type of field to which no specific reference is made in the program—it is just what the name suggests. It fills up the remaining portion in the record to make it up to the declared record length, without the need for defining other unique field names.

The FD before the file name stands for File Description. The LABEL, depending on the type of file and the system, contain data that identify the file. The 01 and 02 indicate the respective level numbers in the storage place.

The level numbers used can be from 01 to 49, the level 01 is the highest level. The data names which are at the lowest level are called elementary data names and those above it at higher levels are called grouped data names.

Under this procedure the record-name [grouped data name] and the field names [elementary data names] will have the following relations:

The total record can be referenced by using the name Student-Record and the individual fields under it can be referenced by using the name of the fields, like, Student- name, Roll-no, etc. which have to be unique.

The PIC, short form of the reserved word PICTURE is used to define the type and size of the field. PIC X(20) means any type of characters of maximum 20 character length. The 999 indicates only numerical of 3 character length can be entered—it could also be written as PIC 9(3), meaning three 9s.

Continuing the Data Division, we have the next section as:

 

 

 

The end-of-file is a reserved word, which is used to indicate when the end has been reached in the file, that is, to indicate that there are no more records. The word VALUE is used to put an appropriate initial value in the respective fields.

The elementary data name in the working-storage section, which does not belong to any data name group is often given the level number of 77, though 01 can also be used. With data division having defined all the file and data with their respective names which will be used in the program, the last division has to be written which contain the statements for manipulation of data.

The Picture Clause:

This clause, PIC in short form, is used to specify the general characteristic of the type of data to be stored in data names, this being used in Data Division.

Some of the codes used to mark different types of position are:

X: A position which can hold any allowable character.

9: A position which will only hold a numeric value.

A: A position which will hold a letter or a space.

V: A position which shows the position of an assumed decimal point.

PIC 9999V99 or PIC 9(4) V99 indicates that there are four integers followed by a decimal point with two decimal places after it. Each of the above codes represent a position, except V, which shows the position of the decimal point.

iv. Procedure Division:

All the three previous divisions do the house-keeping work, which provide the infrastructure for this division, where the actual processing of data takes place to produce the desired information—the instructions for which are written here.

All data-names which are referred to in the Procedure Division have to be defined in the Data Division, which are declarations made to reserve space in memory where the actual values will be stored.

The data-names [fields] which involve input-output operations using records have to be defined in the File Section and those data-names which are used for storing the different values during the intermediate stage of processing have to defined in the Working-Storage Section.

The Procedure Division contains different statements and sentences to manipulate the data. As already stated, each statement starts with a verb which specifies the operation to be done—the verbs are reserved words having predefined syntax.


Essay # 5. Arithmetical, Verbs Used in COBOL:

These are used to perform arithmetical operations on data values, which are specified by the respective data names.

Their simplified syntax are:

Addition:

ADD variable-1 [variable-2]… TO variable-S

which is equivalent to variable-S = variable-S + variable-1 [+ variable-2]…

As you can see from above, the data name shown as variable-S contains the final value after addition, its old value being added to the values of the data names specified on the left hand side of TO. Whenever a square bracket is used in a syntax, it indicates optional items which may or may not be used.

Here it means that you can have more than one variable name in the left hand side of TO. In place of the variables in the left hand side of TO, numeric literals can also be used, but, variable-S must be a variable as otherwise its value cannot change to take up the final value after addition.

Another syntax is:

ADD variable-1 variable-2 [variable-3]… GIVING variable-S

The above is equivalent to: variable-S = variable-1 + variable-2 [+ variable-3]…

Here the value of the variable-S is over written by the result of the addition and its initial value is not added up. As usual, you can use numeric literals in the left hand side of the clause GIVING, where two variable names are required as in this case it is meaningless to add a variable to nothing.

Examples:

 

 

 

 

If the above three statements are executed consecutively one after another, the value of the variables will be different in the last two cases. After the first execution, we have, A = 10, B = 20, and C = 10.

So after second execution, B becomes B + A + C = 20 + 10 + 10 = 40. So, A = 10, B = 40 and C = 10. After the last execution, we have C = A + B = 10 + 40 = 50. Just remember that the values contained in a variable is the last value assigned to it.

All the variable [data names or field names] use in the above computation has to be defined under Data Division. The variables can be numeric fields of same or different files or those defined as a numeric literal in the Working-Storage Section. The variables used are also called Operands, and they must not have any PICTURE clause other than those using 9 and V, while defining them.

Subtraction:

What have been discussed in general for addition also apply to the subtraction verb, whose syntax is:

 

 

 

 

As before, let us have: A = 10, B = 20 and C = 0.

 

 

 

Multiplication:

 

 

 

 

 

 

Division:

Here we have three different syntax.

 

 

 

 

 

 

 

 

You cannot divide by 0 and if you do, it will cause an error.

Moving Values:

The verb MOVE allows a value to be assigned to a variable. Its syntax is: MOVE variable-1 TO variable-2.

The value contained in variable-1 is transferred to variable-2, with the value of variable- 1 remaining unchanged. Variable-1 can be a constant.

ADD X Y GIVING Z. actually represents:

MOVE 0 TO Z.

ADD X TO Z.

ADD Y TO Z.

Computation:

There is a verb called COMPUTE, which can be used carry to out a number of computations in one go.

Its syntax is:

COMPUTE variable-1 = arithmetic expression

The result of the arithmetic expression, which gives a numeric value, is assigned to the variable-1. When using the COMPUTE statement, the following symbols are allowed to build the arithmetic expression.

+ for addition.

– for subtraction.

* for multiplication. / for division.

** for exponentiation, that is, raising to a power.

For example, x = a2 + 4ab + c could be written as:

COMPUTE x = (a ** 2 + 4 * a * b + c)

Just remember that at least one space must be provided between each mathematical operator and the variable names before and after it.

Procedure:

A Procedure is a series of one or more statements to be executed one after another and which is given a unique name to identify it. Normally all instructions, given in statements, are executed in sequence one after another, unless some special commands are given to alter the sequence.

For example, you may want a group of instructions to be executed several times, before processing the instruction after these set of instructions.

The verb used to execute a named procedure is Perform, whose syntax is:

PERFORM procedure-name. — executes all the statements under that procedure, that is, all the statements till a different procedure name is encountered.

PERFORM paragraph-1 To paragraph-2. — executes all the statements contained between paragraph-1 and paragraph-2.

PERFORM procedure-name integer TIMES. — executes the procedure “integer” num­ber of times. The “integer” can be given by a variable name containing numeric value.

PERFORM procedure-name VARYING variable-1 FROM value-1 BY value-2 UNTIL condition.

The procedure is executed as long as the condition specified is true. The condition could be the value of a variable not exceeding an integer, say, 12.

The variable-1 after VARYING is giving an initial value specified by FROM value-1, which is increased in steps after each execution by what is given BY value-2. This value of the variable-1 is tested in the condition clause.

For example, if you write:

PERFORM do-addition VARYING I FROM 1 BY 2 UNTIL 1 < 21.

The procedure do-addition is executed first with value of I as 1 and since this satisfies the condition 1 < 20, it will be executed again with value of I as [1 + 2] or 3. This will continue as long as the value of I remains below 21.


Essay # 6. File Operation Using COBOL:

Before a file can be used, it is to be opened for either Input or Output. In the former case data is taken from the file and the latter case the data is sent to the file.

The syntax is:

OPEN INPUT filename-1 [filename-2]…

OPEN OUTPUT filename-3 [filename-4]…

The file(s) have to be closed after execution, and so:

CLOSE filename-1 [filename-2]…

To write to a file, the syntax is:

WRITE record-name. — the complete record is written at a time.

To get data from a file, the syntax is: READ filename RECORD.

The statement, GO TO paragraph-name, is used for unconditional branching off to another paragraph. The Perform verb is used for conditional branching.

STOP RUN. is used to end the execution of the program.


Essay # 7. Displaying on Monitor Using COBOL:

The instructions to display the values of some variables or literals on the screen the statements is:

DISPLAY (position-specification) variable-1/literal-1. — displays the values at the specified line and column position specified.

DISPLAY (position-specification) ERASE. — clears the screen from the position speci­fied. The position-specification is given by (LIN, COL) or (integer-1, integer-2) where the first parameter specifies the line and the second parameter specifies the column position.


Essay # 8. Accepting from Keyboard Using COBOL:

ACCEPT (position-specification) variable-1 [WITH PROMPT]. — the program waits for user to enter the data value from the keyboard, which is accepted, that is, stored as the value of the variable-1. When the Prompt is used, the place where the input is provided is displayed with a period for alphanumeric value and a space for a numeric value. The position-specification is same as has been explained with Display.

Example of Programs:

Example 1:

To Display a Number of * on Screen in the Form of a Rectangle

Given below is a program, which asks the user to enter the number of lines for displaying a rectangle with a maximum of 20 rows. The rectangle is created by displaying asterisks in a row numbering thrice the number of lines.

The line numbers have been given in the listing of the source-code, just to facilitate understanding what is being done in what line. This has been compiled by using Microsoft COBOL Compiler [1983], copyright of Microsoft.

Line Number Source Line MICROSOFT Microcomputer COBOL Compiler Version 1.07

1. IDENTIFICATION DIVISION.

2. PROGRAM-ID. EXAMPL01.

3. ENVIRONMENT DIVISIONS.

4. DATA DIVISION.

5. WORKING-STORAGE SECTION.

6 . 01 A PIC 9(2).

7. 01 B PIC 9(2).

8. 01 C PIC 9(2).

9. 01 X PIC 9(2) VALUE 3.

10. 01 Y PIC 9(2).

11. 01 TOT PIC 9(4).

12. PROCEDURE DIVISION.

13. TO-BEGIN.

14. DISPLAY(1, 1) ERASE.

15. DISPLAY(2, 1)- “How many rows [Maximum 20] ?”.

16. ACCEPT(2, 31) Y WITH PROMPT.

17. PERFORM COMP-IT VARYING A

18. FROM 1 BY 1 UNTIL A > Y.

19. COMPUTE TOT = ( Y * C )

20 . DISPLAY(24, 53) “Total Number of Stars = “.

21. DISPLAY(24, 77) TOT.

22. STOP RUN.

23. COMP-IT.

24. ADD X A GIVING LIN.

25 .ADD X 18 GIVING COL.

26.MULTIPLY Y BY 3 GIVING C.

27. PERFORM SHOW-IT VARYING B

28. FROM 1 BY 1 UNTIL B > C.

29. SHOW-IT.

30. DISPLAY(LIN, COL) “*”.

31. ADD 1 TO COL.

The variables used in the program have been defined under Working-Storage Section in line numbers 6 to 11; as fields from any record/file is not involved. The variable in line 9 has also been given an initial value of 3 by using the Value clause. Line numbers 13, 23 and 29 contain three procedures named as To-begin, Comp-it and Show-it.

The Show-it procedure forms the lines using the condition B > C and the statement in line 17, control the display of rows. After line number 17 & 18, the execution [control] shifts to line 23 and returns only when all the asterisks are displayed in a particular row, varying the column position.

This continues until all the required rows are displayed. Then, the control goes to line number 19 where the Compute verb has been used to calculate the total number of * displayed. The operation of line number 19 could also be done using Add verb; it has been used as a demonstration.

Thereafter, sequentially lines 20, 21 and 22 are executed, ending the operation. The LIN and COL data names have not been defined in the Working-storage Section because these are special reserved words available with MS COBOL.

In line 27, B is given an initial value of 1 and a step increase of 1. The statement is defined to continue till the value of B so obtained does not exceed the value of C. Similarly in line 17, A starts with an initial value of 1, incremented by 1 after each cycle.

You should execute this program on paper by assigning different values, as per instructions, to different variables and see how the asterisks are displayed, how the lines and columns change.

Example 2:

To Display * in a Triangular Form

The previous program has been modified here to display asterisks in the shape of a triangle.

You should study carefully the difference between this and the earlier program to improve your understanding of program writing and execution.

1. IDENTIFICATION DIVISION.

2. PROGRAM-ID. Examp102.

3. ENVIRONMENT DIVISION.

4. DATA DIVISION.

5. WORKING-STORAGE SECTION.

6. 01 A PIC 9(2).

7. 01 B PIC 9(2).

8. 01 X PIC 9(2).

9. 01 Y PIC 9(2).

10. PROCEDURE DIVISION. ,

11. TO-BEGIN.

12. DISPLAY(1, 1) ERASE.

13. DISPLAY(2, 1) “How many Rows [Maximum 22] ?”.

14. ACCEPT(2, 32) X WITH PROMPT.

15. PERFORM COMP-IT VARYING A

16. FROM 1 BY 1 UNTIL A > X

17. STOP RUN.

18. COMP-IT.

19. SUBTRACT 1 FROM A GIVING B.

20. MULTIPLY B BY 2 GIVING Y.

21. ADD 1 TO Y.

22. SUBTRACT B FROM 50 GIVING COL.

23. ADD 2 A GIVING LIN.

24. PERFORM SHOW-IT VARYING B

25. FROM 1 BY 1 UNTIL B > Y.

26. SHOW-IT.

27. DISPLAY(LIN, COL) “*”.

28. ADD 1 TO COL.

Example 3:

Use of a Sequential File:

Line Number Source Line MICROSOFT Microcomputer COBOL Compiler Version 1.07

1. IDENTIFICATION DIVISION.

2. PROGRAM-ID. EXAMPL03

3. ENVIRONMENT DIVISION.

4. CONFIGURATION SECTION.

5. INPUT-OUTPUT SECTION.

6. FILE-CONTROL.

7. SELECT DATAFILE ASSIGN TO DISK

8. ORGANIZATION IS LINE SEQUENTIAL.

9. DATA DIVISION.

10. FILE SECTION.

11. FD DATAFILE

12. LABEL RECORDS ARE STANDARD

13 .VALUE OF FILE-ID “STUDENT.DAT”.

14. 01 STUDENT.

15. 05 NAME PIC X(31).

16. 05 SUBJCT PIC X(31).

17. 05 ROLLNO PIC 9(2).

18. WORKING-STORAGE SECTION.

19. 01 DRAWLINE PIC X(40) VALUE ALL “#”.

20. 01 EXIT-CODE PIC 99.

21. PROCEDURE DIVISION.

22. DISPLAY-FORM.

23. OPEN OUTPUT DATAFILE.

24. DISPLAY (1, 1) ERASE.

25. DISPLAYS (7, 21) DRAWLINE.

26. DISPLAY(8, 30) “Enter the Prompted Data”

27. DISPLAYS, 21) DRAWLINE.

28. DISPLAY(11, 21) “Name : “.

29. DISPLAY(12, 21) “Subject: “.

30. DISPLAY(13, 21) “Roll No: “.

31. DISPLAY(15, 21) DRAWLINE.

32. DISPLAY(19, 40) “To Exit, Press F3 when at the Name Field.”.

33. ENTER-DATA.

34. ACCEPT(11, 30) NAME WITH PROMPT.

35. ACCEPT EXIT-CODE FROM ESCAPE KEY.

36. IF EXIT-CODE = 4 GO TO EXIT-ENTRY.

37. ACCEPT (12, 30) SUBJCT WITH PROMPT.

38. ACCEPT (13, 59) ROLLNO WITH PROMPT.

39. WRITE STUDENT. GO TO ENTER-DATA.

40. EXIT-ENTRY.

41. CLOSE DATAFILE WITH LOCK.

42. STOP RUN.

In this program, certain data is taken from the user, which is typed on the keyboard and it is stored in a file, named as “student.dat”. The data is stored in a Sequential File, where, all the data are stored in the same sequence as these are received and retrieving is also done in sequence, one after another starting with the first record, as these are stored.

You can see the contents of this file, by using the Type command of MS DOS.

This program allows you to enter as many data as you like. So, the procedure Exit-entry [line number 40 has been provided to end your data entry whenever you like. In line 35, the program analyses the key pressed by you by storing the value returned by the key pressed to the variable Exit-code.

If you press the function key F2, a value of 4 is received by the CPU and stored in the variable Exit-code. In line 36, when compared with 4, naturally, this is found to be true and so the control branches of to the procedure Exit-entry, which closes the data file and stops execution. Otherwise, execution continues with line number 37.

Depending on some of the special keys pressed, the value returned by the function keys F1 to F10 are 02 to 11 respectively and 01 on pressing the Esc key.

In line 34, the Accept verb contains a “with prompt” clause. This causes a number of periods to be displayed, depending on the width of the data field, as the “name” is non-numeric field. You can eliminate the clause to prevent display of the periods.


Essay # 9. Compilation of Programs Using COBOL:

To compile the above programs in a PC with Microsoft COBOL, prepare a text file with COB extension and restrict the filename to 8 characters as prescribed by MS DOS. Then at DOS prompt, enter:

C> COBOL text-filename; <R>

It will start compiling and report if any error found. Make the corrections and recompile, till you get error-free object file, with OB] extension. Next:

C> LINK test-filename; <R>

This will link the file and produce an executable file with EXE extension and same name as the text-filename. To execute the program, just type the name at the DOS prompt ‘and press the Return <R> key.

COBOL naturally has large number of reserved words which can be used in program preparation. Moreover, the syntax of some of the verbs used also contain additional options. However, to restrict ourselves to the elementary level, those have not been provided.