Professional Documents
Culture Documents
Labguide Cobol La01 LC
Labguide Cobol La01 LC
COMPANY CONFIDENTIAL
COPYRIGHT NOTICE
All ideas and information contained in this document are the intellectual property of
Education and Research Department, Infosys Technologies Limited. This document is
not for general distribution and is meant for use only for the person they are
specifically issued to. This document shall not be loaned to anyone, within or outside
Infosys, including its customers. Copying or unauthorized distribution of this
document, in any form or means including electronic, mechanical, photocopying or
otherwise is illegal.
Contents
COPYRIGHT NOTICE .......................................................................................................I
COPYRIGHT NOTICE ...................................................................................................... II
CONTENTS.................................................................................................................. II
CONTEXT ...................................................................................................................1
ASSIGNMENT 1: WRITING A COBOL CODE IN THE CODING SHEET, EXECUTING AND VIEWING THE OUTPUT IN SPOOL ....... 1
ASSIGNMENT 2: DEBUGGING A COBOL PROGRAM .......................................................................... 2
ASSIGNMENT 3: UNDERSTANDING COBOL CODING STANDARDS............................................................. 2
ASSIGNMENT 4: UNDERSTANDING ARITHMETIC STATEMENTS IN COBOL .................................................... 3
ASSIGNMENT 5: UNDERSTANDING EDITED PICTURE CLAUSES AND MOVE VERB ............................................. 4
ASSIGNMENT 6: UNDERSTANDING THE LEGAL MOVES IN COBOL ......................................................... 5
ASSIGNMENT 7: EXERCISES FOR SELF REVIEW ............................................................................... 6
DAY 2 ASSIGNMENTS .....................................................................................................6
ASSIGNMENT 1: CREATION OF PS FILE AND UNDERSTANDING THE READ OPERATION OF A PS FILE ......................... 16
ASSIGNMENT 2: UNDERSTANDING WRITE OPERATION OF A PS FILE ........................................................ 17
ASSIGNMENT 3: APPENDING RECORDS TO A PS FILE ....................................................................... 18
ASSIGNMENT 4: UPDATING RECORDS IN A PS FILE......................................................................... 18
ASSIGNMENT 5: UNDERSTANDING SEQUENTIAL FILE MANIPULATIONS ...................................................... 19
ASSIGNMENT 6: EXERCISES FOR SELF REVIEW ............................................................................. 20
ASSIGNMENT 1: UNDERSTANDING READ AND WRITE OPERATIONS IN A VSAM KSDS FILE ................................ 21
ASSIGNMENT 2: UNDERSTANDING THE VSAM KSDS FILE MANIPULATIONS ................................................ 26
ASSIGNMENT 3: UNDERSTANDING COPY VERB ........................................................................... 27
ASSIGNMENT 4 : UNDERSTANDING CALL VERB ........................................................................... 31
ASSIGNMENT 5: CREATION OF MODULAR COBOL PROGRAMS ............................................................. 34
ASSIGNMENT 6: UNDERSTANDING VSAM KSDS FILE AND PS FILE MANIPULATIONS ........................................ 35
ASSIGNMENT 7: CREATION OF ALTERNATE INDEX FOR A VSAM KSDS FILE ................................................ 35
ASSIGNMENT 8: EXERCISES FOR SELF REVIEW ............................................................................. 36
Context
This document contains assignments to be completed as part of the hands on for the subject
COBOL Programming (Course code: LA01).
Note: In order to complete the course, assignments in this document must be completed in
the sequence mentioned.
Day 1 Assignments
Objective: To learn how to write a COBOL program in the coding sheet, execute it
using a JCL and viewing the output in spool
Problem Description: Write a COBOL program to display the message ‘HELLO WORLD’
onto the spool. Execute the program through JCL.
PDS : TXXXXX.COBOL.DAY1.ASSIGN.PDS
Member for COBOL program : TXXXCB01, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC01
Objective: To learn how to debug a COBOL program and interpret the JES messages in
the spool
Problem Description: Few errors have been introduced in the program of Assignment
1. We will execute this program through JCL and interpret the error messages in the
spool
PDS : TXXXXX.COBOL.DAY1.ASSIGN.PDS
Member for COBOL program : TXXXCB02, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC02
Problem Description:
Refer the reference document provided for coding standards and
implement the HELLOW WORLD program with coding standards.
Note: From here on wards, for all the programs, follow the coding
standards.
PDS : TXXXXX.COBOL.DAY1.ASSIGN.PDS
Member for COBOL program : TXXXCB03, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC03
Problem Description:
Write a COBOL program to evaluate the following expressions using arithmetic
verbs – ADD, SUBTRACT, MULTIPLY and DIVIDE
V = (4/3 ) ∏ r3
P = 2 * (l + b)
R = (a + b) 2 * (a – b)2
Write a JCL to execute the program and display the result in the spool
PDS : TXXXXX.COBOL.DAY1.ASSIGN.PDS
Member for COBOL program : TXXXCB04, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC04
Problem Description:
PICTURE clause of the Sending fields and Receiving fields are given in the below table
along with the contents being moved to them.
Initialize the sending fields using move statements
Use Move statements from sending field to receiving field.
PDS : TXXXXX.COBOL.DAY1.ASSIGN.PDS
Member for COBOL program : TXXXCB05, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC05
Objective: To understand the Legal MOVE Matrix for various data types
Problem Description:
Declare WORKING-STORAGE Variables of the following data types :
Numeric
Alphabetic
Alphanumeric
Numeric Non-integer (decimal with PIC symbol ‘V’)
Edited Numeric
Edited Alphanumeric
Using MOVE statements validate the Matrix given below for the compatibility of data
types.
Numeric
Edited Edited
Data Types Alphabetic Alphanumeric Numeric non
Alphanumeric numeric
integer
Alphabetic Y Y Y N N N
Alphanumeric Y Y Y Y* N N
Edited
Y Y Y N N N
Alphanumeric
Numeric N Y Y Y Y Y
Numeric non
N N N Y Y Y
integer
Edited
N Y Y Y Y Y
numeric
PDS : TXXXXX.COBOL.DAY1.ASSIGN.PDS
Member for COBOL program : TXXXCB06, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC06
Day 2 Assignments
Objective: To learn how to use the ON SIZE ERROR Clause with arithmetic verbs for
accurate results
PDS : TXXXXX.COBOL.DAY2.ASSIGN.PDS
Member for COBOL program : TXXXCB01, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC01
• How to use ON SIZE ERROR clause to handle precision errors in arithmetic verbs
WITH TEST BEFORE : the condition is tested before the body of the loop is
executed even once
WITH TEST AFTER : the condition is tested after the body of the loop is
executed once
PDS : TXXXXX.COBOL.DAY2.ASSIGN.PDS
Member for COBOL program : TXXXCB02, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC02
Objective: To learn how to use arithmetic verbs, ROUNDED and ON SIZE ERROR clauses
to provide results with accurate precision
Problem Description:
Emp. No : 8900
Emp. Name : Shastry
Basic : Rs.xxxx.xx
DA : Rs.xxx.xx
HRA : Rs.xxx.xx
Gross : Rs.xxxxx.xx
• How to use arithmetic verbs, ROUNDED and ON SIZE ERROR clauses in COBOL program
PDS : TXXXXX.COBOL.DAY2.ASSIGN.PDS
Member for COBOL program : TXXXCB03, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC03
Objective: To learn how to use various forms of PERFORM Verbs and IF statements
Problem Description:
Write a COBOL program to create Grade sheets for 2 students in a college.
Accept the name of the student and marks in 3 subjects for every student from the
user.
Calculate the Total, Percentage and Grade for 2 students.
Code every functionality (ACCEPT, calculating Total, percentage & grade and display)
in separate paragraphs.
Use PERFORM …. THRU to execute the paragraphs in sequence for each student
Use PERFORM…..TIMES to repeat the loop for 2 students
Use the following criterion to assign grades based on their Percentage marks
Percentage Grade
>=80 A
70 to 79 B
60 to 69 C
50 to 59 D
< 50 E
Use IF….THEN…ELSE to check for grades
Display the Grade Sheet in the following format :
------------------------------------------------------------------------------------------------------
* Mysore University *
* Student Name : XXXXXXXXXXXX *
------------------------------------------------------------------------------------------------------
Subject Marks
-----------------------------------------------------------
CHSSC 90
PF 90
RDBMS 90
-----------------------------------------------------------
TOTAL 270
-----------------------------------------------------------
Percentage 90%
------------------------------------------------------------------------------------------------------
GRADE OBTAINED A
------------------------------------------------------------------------------------------------------
PDS : TXXXXX.COBOL.DAY2.ASSIGN.PDS
Member for COBOL program : TXXXCB04, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC04
Objective: To learn how to accept the input from the user and perform the display
according to the input
Problem Description:
Accept CHOICE from the user (y/n)
Accept the NAME, IBU from the user
Use PERFORM ……… UNTIL to repeat the loop where the loop has to terminate
whenever the user enters ‘N’ for CHOICE
Display the data in spool
• How to use accept the inputs from the user and display it on the spool using
PERFORM….UNTIL verb
PDS : TXXXXX.COBOL.DAY2.ASSIGN.PDS
Member for COBOL program : TXXXCB05, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC05
Problem Description:
Accept No. of elements ‘N’ to be generated in a WORKING-STORAGE VARIABLE
Use PERFORM………..VARYING to generate the series
PDS : TXXXXX.COBOL.DAY2.ASSIGN.PDS
Member for COBOL program : TXXXCB06, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC06
1. What is the difference between PERFORM…WITH TEST BEFORE and WITH TEST AFTER?
2. When coded in a COBOL program what does STOP RUN do?
3. What are condition names and condition variables?
4. List down the level numbers used for condition variables and condition names
5. Give the syntax of PERFORM……VARYING statement
Day 3 Assignments
Objective: To learn how to create a PS data file for read, write and update operations
Step 1:
Create a sequential file to store the Employee Records in an organization. The record
layout is as follows :
EMPNUM PIC 9(5).
EMPNAME PIC X(25)
DESGINATION PIC A(10)
IBU PIC A(10)
TELEPHONE PIC 9(7)
PS : TXXXXX.COBOL.DAY3.ASSIGN.PS
Populate the PS file with 5 sample records according to the above layout
Problem Description:
Develop a COBOL program to read the records from the PS file created in step1
(TXXXXX.COBOL.DAY3.ASSIGN.PS) [ Refer to demo T115COB1,T115JCL1]
Display the records onto the spool
Handle appropriate error conditions
• How to read the records from a PS file and display them on the spool
PDS : TXXXXX.COBOL.DAY3.ASSIGN.PDS
Member for COBOL program : TXXXCB01, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC01
Problem Description:
Accept the records to be inserted through the JCL [ Refer to demo
T115COB1,T115JCL1]
Develop a COBOL program to read the records from the JCL and write it into the PS
file
Display “successfully written” in the spool, if the write is successful
Handle appropriate error conditions
Problem Description:
Accept 2 records to be appended to the file through the JCL
Develop a COBOL program to read the records from the JCL and append it to the PS
file
Display “successfully appended” in the spool, if the write is successful
Handle appropriate error conditions
Problem Description:
Accept a Telephone Number of an employee from JCL
Develop a COBOL program to update the IBU of the employee who is having that
telephone number, as ‘IHLD’
Display “successfully updated” in the spool, if the update is successful
Problem Description: Master PS file contains the data records. Transaction PS file
contains the transaction records to be inserted/updated/deleted, to/from a master
file. A batch program SEQPROC reads the transaction PS file and according to the flag
I (Insert), U (Update) and D (delete) performs the necessary operations in the master
PS file.
01 MASTER-REC.
05 MASTER-EMP-NO PIC 9(5).
05 FILLER PIC X.
05 MASTER-EMP-NAME PIC X(25).
05 FILLER PIC X.
05 MASTER-EMP-STATUS PIC X(1).
05 FILLER PIC X(47).
Day 4 Assignments
Objective: To learn how to perform READ and WRITE operation in a VSAM KSDS file
Problem Description:
Create a VSAM KSDS file TXXXXX.COBOL.DAY4.ASSIGN1.VSAM with the following
record layout :
REGNO PIC X(05) (KEY FIELD)
NAME PIC A(15)
AGE PIC 9(02)
Step 5: Observe the output in the spool. Open the VSAM file and view the inserted
records
VSAM : TXXXXX.COBOL.DAY4.ASSIGN1.VSAM
PDS : TXXXXX.COBOL.DAY4.ASSIGN.PDS
Member for COBOL program : TXXXCB01, where XXX is last 3 digits of your
employee id
Member for JCL : TXXXJC01
Objective: To learn how to perform updation and deletion in a VSAM KSDS file
Problem Description:
Create a VSAM KSDS file TXXXXX.COBOL.DAY4.ASSIGN2.VSAM through File-Aid with the
following record layout :
DEPT NUM PIC X(5) [KEY FIELD]
DEPTNAME PIC A(15)
DEPTLOC PIC A(10)
(i) Insertion
Write a COBOL program in a member TXXXCB02 to read the records from
the JCL and insert it into the VSAM (XXX is last 3 digits of your employee id)
Execute the program using JCL – TXXXJC02
(ii) Read
Write a COBOL program in a member TXXXCB03 to read the records from
the VSAM and display it onto the spool
Execute the program using JCL- TXXXJC03
(iii) Update
Write a COBOL program in a member TXXXCB04 to
o Accept the Department Number from JCL
o Update the Location of that record to ‘MYSORE’
Execute the program using JCL – TXXXJC04
(iv) Delete
Write a COBOL program in a member TXXXCB05 to
o Accept the Department Number from JCL
o Delete the record from the VSAM
Execute the program using JCL – TXXXJC05
• How to read the records from a PS file and display them on the spool
Objective: To learn how to create Copybooks and use them in the program through
COPY Verb
Problem Description: Copybooks created should have a unique name. The copybooks
are stored in the copy library OPERN.CICS1.COPYLIB
Step 2 : Type CC-CC-CREATE for the FD entry and press ENTER. The following screen
will appear
Step 3 : Type the path of the copybook to be stored with the copybook name. Here
the path is ‘OPERN.CICS3.COPYLIB(TXXXCPY1)’, where XXX is last 3 digits of your
mainframe id. Press ENTER.
Step 4 : The message ‘Member TXXCPY1 created’ will appear in the right top corner
of the screen.
Step 5 : In the member TXXXCB03 , delete the FD entry and replace it with the
copybook.
PDS : TXXXXX.COBOL.DAY4.ASSIGN.PDS
Member for COBOL main program : TXXXCB06
Member for COBOL sub-program : TXXXCB07, where XXX is last 3 digits of
your employee id
Member for JCL : TXXXJC06
Objective: To learn how to create modular programs using CALL verb and how to
include copybooks
Problem Description:
PDS : TXXXXX.COBOL.DAY4.ASSIGN.PDS
VSAM : TXXXXX.COBOL.DAY4.ASSIGN2.VSAM (same file created in Assignment 2)
Member for COBOL program : TXXXCB08, where XXX is last 3 digits of
employee id
Member for JCL : TXXXJC08
Members to be used : TXXXCB03, TXXXCB04, TXXXCB05 (in Assignment 2)
Objective: To learn how to manipulate the transaction records in a PS file and update
the master VSAM KSDS file
Problem Description : Master PS file contains the transaction records that are to be
updated in the VSAM KSDS master file. Transaction PS file contains the transaction
records to be inserted/updated/deleted in a master file. A batch program VSAMPROC
reads the transaction PS file and according to the flag I (Insert), U (Update) and D
(delete) performs the necessary operations in the master VSAM KSDS file.
Step 3 : Write the given COBOL program in the member TXXXCB09 and JCL to
execute program in member TXXXJC09 in PDS TXXXXX.COBOL.DAY4.ASSIGN.PDS
• How to read the records from a transaction PS file and update the same in the VSAM
KSDS master file
Objective: To learn how to create an alternate index for a VSAM KSDS file
Background : Alternate Indexes are used in VSAM files for searching operations.
Besides primary key field, any other field can be an alternate key (preferably numeric
field). Unlike primary key field, alternate key can have duplicate values.
• How to create an alternate index for a VSAM file and use it in a COBOL program
1. Give the syntax of SELECT statement for a VSAM with ALTERNATE INDEX
2. What is the use of FD entries in ENVIRONMENT division?
3. In the below given SELECT statement identify the physical and logical filenames ;
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPFILE ASSIGN TO QSFILE
ORGANIZATION IS INDEXED
ACCESS IS RANDOM.
4. Which PDS is used to store the copybooks created by TSO users?
5. What is the use of LINKAGE SECTION while using CALL statement?
Day 5 Assignments
Objective: To learn how to create an one dimensional array and populate it with data
• How to create one dimensional array and populate them with data
PDS : TXXXXX.COBOL.DAY5.ASSIGN.PDS
Member for COBOL program : TXXXCB01, where XXX is last 3 digits of
employee id
Member for JCL : TXXXJC01
Objective: To learn how to perform string manipulations using STRING and UNSTRING
Verbs
Background: STRING Verb is used in COBOL to concatenate separate strings into one
string. UNSTRING verb is used to split a string into various elementary strings
• How to concatenate strings using STRING Verb and split the strings using UNSTRING
Verb
PDS : TXXXXX.COBOL.DAY5.ASSIGN.PDS
Member for COBOL program : TXXXCB02, where XXX is last 3 digits of
employee id
Member for JCL : TXXXJC02
• How to use INSPECT Verb for counting the number of characters in a string and
replacing the characters
PDS : TXXXXX.COBOL.DAY5.ASSIGN.PDS
Member for COBOL program : TXXXCB03, where XXX is last 3 digits of
employee id
Member for JCL : TXXXJC03
PDS : TXXXXX.COBOL.DAY5.ASSIGN.PDS
Member for COBOL program : TXXXCB04, where XXX is last 3 digits of
employee id
Member for JCL : TXXXJC04
PDS : TXXXXX.COBOL.DAY5.ASSIGN.PDS
Member for COBOL program : TXXXCB05, where XXX is last 3 digits of employee
id
Member for JCL : TXXXJC05
Problem Description:
Develop a modular COBOL program to perform the following string
handling functions using INSPECT, STRING and UNSTRING
Every functionality has to be defined in separate paragraphs
Each paragraph has to be called through PERFORM statement from the
main paragraph
Declare a string with value ‘EDUCATION AND RESEARCH’
Use INSPECT Verb to :
o Count the number of occurrences of A and E in the string
o Replace the character 'A' by 'Z' before the first occurrence of O.
o Replace all the characters 'E' by 'M' occurring before 'D'.
• How to use STRING and UNSTRING Verbs to concatenate and split the strings
• How to use INSPECT verb to count the number of occurrence of the character and to
replace characters in a given string
PDS : TXXXXX.COBOL.DAY5.ASSIGN.PDS
Member for COBOL program : TXXXCB06, where XXX is last 3 digits of employee
id
Member for JCL : TXXXJC06
1. What is the difference between the LEADING and FIRST phrase used with the INSPECT
statement?
2. Predict the output of the following code snippet
IDENTIFICATION DIVISION.
PROGRAM-ID. NEWSTR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-FSTR PIC X(20).
01 WS-SSTR PIC X(35).
01 WS-TSTR PIC X(15).
PROCEDURE DIVISION.
A000-MAIN-PARA.
MOVE ‘INFOSYS LIMITED’ TO WS-FSTR
MOVE ‘MYSORE’ TO WS-SSTR
STRING WS-FSTR, WS-SSTR INTO WS-TSTR
DISPLAY WS-TSTR
STOP RUN.
3. What is the value of WS-COUNT in the following INSPECT statement
IDENTIFICATION DIVISION.
PROGRAM-ID. NEWSTR1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-FSTR PIC X(20).
01 WS-COUNT PIC 9(03).
PROCEDURE DIVISION.
A000-MAIN-PARA.
MOVE ‘GEC INFOSYS MYSORE’ TO WS-FSTR
INSPECT WS-FSTR TALLYING WS-COUNT FOR ALL ‘E’
DISPLAY WS-COUNT
STOP RUN.
4. What is the use of OVERFLOW and POINTER clause in STRING and UNSTRING statements?