Professional Documents
Culture Documents
Page 1 of 18
Date :
STANDARDS
FOR
COBOL
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 2 of 18
Date :
Contents
1.
DOCUMENT CONTROL......................................................................................................................................
2 PURPOSE.....................................................................................................................................................................
3 SCOPE..........................................................................................................................................................................
4 RESPONSIBILITY.....................................................................................................................................................
5 INTRODUCTION........................................................................................................................................................
6 INITIAL SETUP :........................................................................................................................................................
6.1 LIBRARY MANAGEMENT :........................................................................................................................................
6.1.1 Source Library :...............................................................................................................................................
6.1.2 Object and Load Library :..............................................................................................................................
6.1.3 Copy book libraries :.......................................................................................................................................
6.1.4 Subroutines :....................................................................................................................................................
6.1.5 JCL Library:....................................................................................................................................................
7 NAMING CONVENTION..........................................................................................................................................
7.1 PROGRAM NAMES :..................................................................................................................................................
7.2 SUBROUTINE NAMES :..............................................................................................................................................
7.3 COPYBOOK NAMES :...............................................................................................................................................
7.4 LOGICAL FILE NAME :.............................................................................................................................................
7.5 DATASET LABEL :..................................................................................................................................................
7.6 FILE DESCRIPTOR :.................................................................................................................................................
8 PROGRAM STRUCTURE.......................................................................................................................................
8.1 IDENTIFICATION DIVISION :.....................................................................................................................................
8.2 ENVIRONMENT DIVISION.........................................................................................................................................
8.3 DATA DIVISION.......................................................................................................................................................
8.4 PROCEDURE DIVISION..............................................................................................................................................
9 INDENTATION............................................................................................................................................................
9.1 GENERAL GUIDELINES.............................................................................................................................................
9.2 SPACING CONSIDERATIONS:....................................................................................................................................
10 DOCUMENTATION................................................................................................................................................
10.1
10.2
10.3
10.4
IDENTIFICATION DIVISION....................................................................................................................................
ENVIRONMENT DIVISION......................................................................................................................................
DATA DIVISION.....................................................................................................................................................
PROCEDURE DIVISION...........................................................................................................................................
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 3 of 18
Date :
PM845A
BY : SD
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
1.
Page 4 of 18
Date :
DOCUMENT CONTROL
DOCUMENT NAME : COBOL CODING STANDARDS
ABSTRACT This document contains the programming standards and guidelines for VS
COBOL II.
DOCUMENT REFERENCE : COBOLSTD
AUTHORISATION
Process Owner
Name : Sunil Joshi
Signature:
Name : Suchet Dabadge
Signature:
Name : Gauri Gokhale
Signature:
Reviewed By
Name : N.S.Muralidhara
Signature :
Name : Uday Vartak
Signature :
Name : Prakash Devan
Signature :
Name: Anil Paranjpe
Signature:
Name: Raj Chittar
Signature:
SECURITY CLASSIFICATION
Authorised By
Name : Andy Ranaweera
Signature :
Company Confidential
DISTRIBUTION LIST
COPY NO.
ISSUED TO
MASTER
01
VERSION HISTORY
VERSION
DATE
PREPARED BY
ISSUE 1.0
03/11/93 1
Vivek K.
Ghodekar
ISSUE 2.0
ISSUE 2.1
ISSUE 2.2
27/10/95
10/11/97
18/06/98
Hari Iyer
Anil Apte
Suchet Dabadge
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 5 of 18
Date :
2 Purpose
To provide guidelines to programmers for coding COBOL programs.
3 Scope
This document covers all the possible aspects that are required to write a structured
COBOL program. The standards are specific to IBM Mainframe. VSAM
considerations typical to COBOL have been included.
4 Responsibility
The responsibility lies on a programmer who writes a fresh program or modifies an
existing program.
5 Introduction
This document contains the programming standards and guidelines for VS COBOL II.
Standards define practices which are mandatory and enhance consistency and
readability. Guidelines relate to suggested practices which will enhance performance
and maintainability of the code.
6 Initial Setup :
This section covers the standards for various activities to be performed when the
project starts.
6.1
Library Management :
The various libraries have to be named as follows :
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 6 of 18
Date :
6.1.4 Subroutines :
Following convention is to be used to name Subroutine Source libraries :
Env.Projid. SUBSRC
Load module if created separately will reside in LOADLIB.
7 NAMING CONVENTION.
7.1
Program names :
Should be of the type - XXMT999V
XX - represents the Application code which is unique for a project
M - represents the module code which is unique within a application
T - represents the type :
O for On-line inquiry
U for On-line Update programs
B for Batch inquiry
C for Batch Modify programs
X for menu program
999 - represents the serial number of the program.
V - represents the version of the program
eg. LIDO001A for LI System daily attendance register(D) module program no 001 version A.
All On-line initiated batch programs will be treated as batch programs
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
7.2
Page 7 of 18
Date :
Subroutine names :
Should be of the type - XXMSYZ99
XX - represents the Application code which is unique for a project
M - Module name
S - identifies a subroutine
Y - is the data communication component (DC) . These are:
C - CICS
I - IDMS
B - Batch
O - Others
Z - is the database component (DB). These are:
D - DB2
V - VSAM
O - Others
99 - represents the serial number of the subroutine
eg. LIDSBV01 for LI system daily attendance register(D) subroutine using COBOL and
VSAM.
7.3
Copybook names :
Should be of the type - XXM999T
XX - represents the Application code which is unique for a project
M - Module name
999 - represents the serial number of the copybook
T - identifies the type of the copybook. These are:
P - Procedure Division
D - Data Division
eg LID001P LI System Procedure division copybook no 001.
7.4
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
7.5
Page 8 of 18
Date :
Dataset Label :
Should be of the type - MYT999NN
M - Module name
Y - Type of file access. This could be:
I - Input
O - Output
U - Update
R - Report
T999 - type and serial number of program
NN - Serial number of file within the program
eg DIO00101 for daily attendance register(D) input file no 01 in program no 001
7.6
File Descriptor :
FD record name should be <meaningful name>-rec. Subsequent levels should be
have meaningful names.
eg
01 EMPMAST-REC.
03 EMPNAME PIC X(8).
03 EMPADDR PIC X(20).
PROGRAM STRUCTURE.
This section covers the coding conventions to be followed in each COBOL division.
8.1
Identification Division :
The following entries are mandatory in the identification division PROGRAM-ID. program-id.
program-id should be the same as the member-name which contains the program.
AUTHOR. Author-name, MBT
DATE-WRITTEN, DATE-COMPILED entries should be specified in DD-MM-YYYY format.
INSTALLATION : should specify the location eg., M B T - SEEPZ, BOMBAY - 96.
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
8.2
Page 9 of 18
Date :
Environment Division.
SOURCE COMPUTER and OBJECT COMPUTER entries are mandatory.
The following standards are specified for SELECT Statements
SELECT logical-filename ASSIGN to dataset-label
ORGANIZATION IS ...
ACCESS MODE IS ...
FILE STATUS is file-status-var.
All the entries specified above are mandatory.
File-status-var should be named according to working-storage variable naming conventions and
should be same for all files.
8.3
Data Division.
FILE SECTION : Use Copybooks as far as possible, except in cases like output report files. Avoid
creating more than one copybook for a single file.
WORKING-STORAGE :
1. Increment level numbers in increments of 2 i.e. 01 , 03 , 05 ,07, 09 etc.,
2. All variables of given type eg. flags, strings ,etc., may be grouped together under a 01 level.
3. General structure of 01 level WORKING-STORAGE variable should be WX99-type
where X has values:
P - for variables used as part of print record layout
S - for other variables
99 specifies the serial no of the 01 level.
type could be flags , counters, headers, strings, constants, date and time variables , etc.,
eg.
01 WS01-FLAG.
01 WP01-HEADER.
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 10 of 18
Date :
e.g. 01 W06-COUNTER.
03 W06-line-counter
03 W06-page-counter
pic X.
value 'Y'.
While naming EOF or end of cursor conditions, use distinct names for each file/cursor. This
prevents
errors and confusion.
6. Use as few 01 levels as possible. This can be achieved by grouping variables according to the
specific
type to which they belong and by placing the type at 01 level and the variables at subordinate
levels.
eg.
01 W06-CNTR.
03 W06-LNE-CNTR
03 W06-PGE-CNTR
03 W06-LOOP-CNTR
7. Avoid the use of RENAMES.
8. Constants should be initialized in the Working storage using the VALUE clause.
9. 77 and 49 levels should not be used.
LINKAGE SECTION : Prefix user-defined LINKAGE SECTION variables with 'LS99-'
e.g. LS01-DATE-PARM .
8.4
Procedure Division.
1. SECTIONs are preferred over paragraphs.
2. Section/Para names must begin with nnnn-, where nnnn- is a mnemonic code starting from
1000
(except 0000 for the first section/para in the program), the mnemonic code is
incremented by 1000 for main sections/paras i.e. 2000-,3000- etc.For sub paras the name
should start with the mnemonic code increased by 100 i.e. 1100-, 2100- etc. The convention is
to be maintained for subsequent levels.
The exit section/para is to be coded after every section/para. nnnn-paraname-exit is the name of
the exit para of the para nnnnn-paraname. eg.
0000-MAIN SECTION.
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 11 of 18
Date :
PERFORM 1000-INITIALIZE
PERFORM 2000-PROCESS
PERFORM 3000-CLOSE
PERFORM 4000-END.
0000-MAIN-EXIT.
EXIT.
1000-INITIALIZE SECTION.
PERFORM 1100-INIT-VARS
PERFORM 1200-INIT-TABLES
PERFORM 1300-OPEN-FILES.
1000-INITIALIZE-EXIT.
EXIT.
Common routines are to be named as 9nnn-para-name.
3. Common routines should be grouped together and placed at the end of the program.
4. The range of a PERFORM statement should not exceed one para. That is avoid PERFORM THRU
except THRU EXIT-para.
5. Avoid the ALTER statement.
6. Programs and subroutines should have a single entry and single exit point.
7. The IF - ELSE statement should not be nested beyond 3 levels. Use PERFORM for complex nesting.
8. Use explicit scope terminators like END-EVALUATE, END-IF, END-PERFORM etc. Use periods
only to indicate end of para.
9.Use in-line PERFORM if the logical function is not complex and not likely to be used by other paras.
10. Avoid literals in the program. Define them in the Working-Storage section.
11. Avoid using MOVE CORRESPONDING.
12. Code only one statement per line.
13. One para should implement only one logical function and should be about a page(55 lines) in
length.
14. Use COMPUTE verb in preference to other arithmetic verbs for complex arithmetic operations. Use
brackets in COMPUTE statements to make the operation clear.
15. Use EVALUATE statement when you need to test several conditions and specify different actions
for each. Avoid nesting EVALUATEs.
eg..
EVALUATE TRUE
WHEN (A = B)
PM845A
PERFORM .....
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
PERFORM .....
WHEN OTHER
PERFORM .....
Page 12 of 18
Date :
END-EVALUATE.
16. Use COMP-3 usage for variables involved in arithmetic operations and counters. For counters
with small range less than 9(4) , use COMP usage.
17. Called and calling paras should be coded close to each other.
18. In tables use subscript rather than index for access where possible. Index may be used only for Table
searches.
19. Avoid use of NOT condition.
20. Relative indexing is more efficient than defining an alternative index with the offset factored in and
using that index. e.g.
TBL-ELEMENT (INDX1 + 2, INDX2 - 5)
is better than
SET INDX3 TO INDX1
SET INDX3 UP BY 2
SET INDX4 TO INDX2
SET INDX4 DOWN BY 5
TBL-ELEMENT (INDX3, INDX4)
21. OCCURS DEPENDING ON considerations :
Computation on variable-length data items is significantly slower than that on fixed-length data
items.
Copy variable-length data items into fixed-length
frequency access.
Page 13 of 18
Date :
Parameters should be passed through the LINKAGE SECTION except in stand-alone batch
jobs where they may be passed through the JCL.
27. SORTand MERGE:
Use VS COBOL II SORT and MERGE facilities with discretion. It is generally preferable to do
sorting and merging outside the program and then use the sorted data in the program rather
than doing SORT/MERGE within the program.
9 INDENTATION.
The following standards enhance readability of code and also promote coding consistency.
9.1
General Guidelines.
1. All A-AREA statements should start in the 8th column.
2. All B-AREA statements should start in the 12th column.
3. 01 entries should start in the 8th column.
4. Subsequent level entries should start in the 12th, 16th, 20th columns.
5. Leave a gap of 2 spaces between level No. and variable name.
6. Start PICTURE clauses in 45th column.
7. Any continuation should begin in 16th column.
8. Section/Para name should start in 8th column.
9. Subsequent entries in 12th column.
10. Align the 'TOs' and 'THRUs' to a particular column in a para.
11. Align IF, ELSE and END-IF in one column to make the structure clear.
eg.
IF COND-1
STMT1........
IF COND-2
STMT2.....
ELSE
STMT3.....
END-IF
END-IF
12. The statement should start in the same column as the condition.
13. Any nested IF statement should be aligned with the previous statement.
eg. In the example above the IF COND-2 statement is aligned with STMT1.
14. In case of compound conditions start each condition on a new line in the same column.
IF (COND-1
COND-2
COND-3)
COND-4
STMT1
END-IF
OR
OR
AND
9.2
Spacing Considerations:
BY : SD
Page 14 of 18
Date :
10 DOCUMENTATION.
This section gives standards for documenting the code so as to enhance maintainability.
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 15 of 18
Date :
03 FILLER
PIC X(10)
VALUE ALL '*'.
03 FILLER
PIC x(40)
VALUE 'This is the start of working storage'.
03 FILLER
PIC X(10)
VALUE ALL '*'.
03 FILLER
PIC X(10)
VALUE ALL '*'.
03 FILLER
PIC x(40)
VALUE 'This is the end of working storage'.
03 FILLER
PIC X(10)
VALUE ALL '*'.
2. Document any variable whose function is not clear from the name.
3. For each copybook the function should be documented in the program itself
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 16 of 18
Date :
1100-OPENFILES-PARA.
******************************************************
Performed By - 1000-INIT-PARA
Functions - Opens all files
Para Performed - none
******************************************************
The calling para need not be specified for common routines called from many other paras.
2. Redundant lines of code should be deleted rather than commented.
3. Any changed line should be documented to explain the change and the reason for the
change.
Insert 2 comment lines each before and after the altered line. The first comment line should
start
with CR no-begin and the last one should start with CR no-end (CR no. stands for the change
request
number). The first line should specify the reason for change. eg.
** CR01-begin. This line added to accept the new parm
**
Move parm to w05-link-parm.
**
** CR01-end
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 17 of 18
Date :
3. Any tool used for testing and debugging should be documented in the ENVIRONMENT
DIVISION.
4. Document any special JCL used to perform unit testing of the module in the ENVIRONMENT
DIVISION.
5. The COBTEST facility of VS COBOL II provides a complete interactive or batch debugging tool.
This tool if available is recommended.
6. Use of JCLs for unit testing is recommended, especially for subroutines.
7. The debug option is recommended for debugging. code statements meant for debugging with a 'd'
in column 7 and compile the program with DEBUG option. A NODEBUG option at runtime can
be used to suppress the debug statements.
12 VSAM CONSIDERATIONS.
12.1 Introduction :
The following topics cover the standards and guidelines to be followed in use of VSAM.
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD
Page 18 of 18
Date :
13 BIBLIOGRAPHY
1. STRUCTURED COBOL PROGRAMMING ( FIFTH EDITION )
By : NANCY STERN and ROBERT A. STERN Publisher : JOHN WILEY & SONS, INC.
2. IBM VS COBOL II
GENERAL INFORMATION - RELEASE 3.1
3. COBOL PROGRAMMING INCLUDING MS-COBOL AND COBOL 85
( SECOND EDITION )
By : M K. ROY and D GHOSH DASTIDAR
Publisher : TATA McGRAW-HILL
4. COMPREHENSIVE COBOL ( VOLUMES I AND II )
By : ANDREW S. PHILIPPAKIS and LEONARD J. KAZMIER Publisher : McGRAW-HILL
5. MVS/VSAM FOR THE APPLICATION PROGRAMMER
By : GARY D. BROWN and S.A.M.SMITH
Publisher : SHROFF PUBLISHERS AND
DISTRIBUTORS PVT LTD.,
14 GLOSSARY
Alternate Index : Allows a dataset to be ordered and accessed on key other than the primary key.
Case structure : A logical control structure used when there are numerous paths to be followed
depending on the contents of a given field. The EVALUATE verb in COBOL is used to implement
the CASE structure.
Cluster : VSAM terminology for the logical dataset for storing records. A cluster consists of Data and
Index components.
Condition Name : A name assigned to a specific value or a range of values that an identifier can
assume.
EVALUATE : A statement used to implement the case structure.
FD : File descriptor.
File Descriptor (FD) : The entries used to describe an input or output file.
FILE STATUS : Used with the SELECT statement for determining the result of an I/O operation.
INDEX (File) : Reference table that stores Key Field and the corresponding disk address for each
record in a file.
In-line PERFORM : PERFORM statement without a header delimited with END-PERFORM.
LINKAGE SECTION : Section used to receive parameters from calling programs.
Logical control structures : Ways in which instructions in program may be executed.
QSAM : Physical Sequential File Structure.
PM845A
Issue 2.2
Company Confidential
Mahindra-British Telecom Limited
BY : SD