Home | Mainframe Wiki | Free Downloads | Sample Programs | More References | Mainframe Forum

IBMMainframes.com

Quick References for IBM Mainframe Programming

COBOL CODING GUIDELINES

 

PROGRAMMING GUIDELINES FOR MAINFRAME COBOL

  * VS COBOL II GUIDELINES

NEVER USE THE FOLLOWING STATEMENTS:

1. ALTER
2. LABEL RECORDS
3. VALUE OF
4. COMP-1 & COMP-2
5. RD, CD & LD entries
6. MOVE HIGH-VALUE/LOW-VALUE/QUOTES TO <numeric item>
7. ACCEPT <comp/comp-3 data item>
8. JUST/BLANK/SYNC/OCCURS WITH GROUP ITEM
9. USE PROCEDURE FOR A SORT/MERGE REFERENCED FILE
10. ALL CONSTANT WITH NUMERIC ITEMS
11. MEMORY SIZE
12. DATA RECORDS
13. ENTER, ENTRY, STOP

PREVENT THE FOLLOWING STATEMENTS:

1. GO TO - --DEPENDING
2. RERUN & MULTIPLE FILE
3. PADDING CHARACTER
4. REDEFINED DATA CONVERSION (instead use MOVE)

AVOID USING THE FOLLOWING IN NEW PROGRAMS (to compatible with COBOL 2002):

1. GO TO
2. COBOL DEBUGGING MODULES
3. AUTHOR, DATE-WRITTEN etc
4. BLANK WHEN ZERO HAVING A ‘S’ DESCRIPTOR
5. NEXT SENTENCE (instead use CONTINUE)
6. ON OVERFLOW in call (instead use on EXCEPTION)
7. AVOID NOT BEFORE ‘LESS THAN OR EQUAL TO/…’ (Instead, use GREATER THAN)
8. AVOID USING ‘N’ & ‘E’ AS SPECIAL-NAMES. CURRENCY SIGN.


EVERY COBOL PROGRAM MUST FOLLOW INDENTATION SPECIFIED BY ANSI.

IDENTIFICATION DIVISION AND PROGRAM-ID ARE NOT OPTIONAL FIELDS.

FOLLOW ONE ENTRY ONE EXIT CONSTRAIN THROUGHOUT THE PROGRAM.

NEVER USE GO TO, GO TO DEPENDING & ALTER STATEMENTS.

USE EVALUATE STATEMENT INSTEAD OF NESTED IF.

USE * INSTEAD OF / TO MENTION A COMMENT LINE.

PROGRAM-ID & SUB PROGRAM NAME (PDS MEMBER) MUST BE SAME.

ALWAYS USE A SIX CHARACTER VARIABLE AS A PROGRAM -ID AND SAME AS THE MEMBER NAME (PROGRAM NAME).

NEVER USE A NON-ALPHABETICAL VARIABLE AS A PROCEDURE NAME. (ex: 0001)

USE FIRST FOUR CHARACTERS AS A NUMERIC DIGIT IN A PARA NAME. (ex: 0001-READPARA)

PROCEDURE DIVISION MUST HAVE AT LEAST ONE PARAGRAPH IF IT HAS ANY STATEMENT WITH IN IT.

USE STOP RUN INSTEAD OF END PROGRAM IF YOU HAVE ONLY ONE PROGRAM.

A CONTINUATION CHARACTER ( - ) CAN ONLY BE USED WHEN YOU SPLIT A COBOL VERB. (Not a sentence/statement).

THE PROGRAM-ID, PROCEDURE NAME & IDENTIFIERS MUST NOT BE A COBOL RESERVED WORD.

ALPHANUMERIC FIELDS CANNOT BE USED WITH ARITHMETIC VERBS.

YOU CANNOT INITIALIZE ALPHANUMERIC ITEMS WITH NUMERIC DATA.

VALUE CLAUSE CANNOT BE USE IN LINKAGE SECTION AND FILE SECTION EXCEPT CONDITION NAME CONDITION.

YOU CANNOT USE VALUE CLASS IN THE ELEMENTARY ITEM OF A GROUP IF THE GROUP IS ALREADY INITIALIZED.

USE FILLER CLAUSE ONLY WITH GROUP ITEMS.

NUMERIC EDITED DESCRIPTORS CAN’T BE INITIALIZED.

YOU CANNOT USE EDITED NUMERIC FIELDS IN ARITHMETIC.

YOU CAN’T INITIALIZE A NUMERIC DATA WITH AN ALPHANUMERIC FIGURATIVE CONSTANT.

ALL COBOL DELIMITERS MUST FOLLOWED BY A SPACE (Except space).

MULTIPLE DESTINATIONS ARE NOT ALLOWED IN VS COBOL II.

YOU CAN ACCEPT ONLY ONE DATA AT A TIME.

THERE MUST BE ONLY ONE LVALUE FOR COBOL MOVE, MULTIPLY & DIVIDE STATEMENTS.

THERE MUST BE ONLY ONE RVALUE FOR ALL COBOL ARITHMETIC VERBS IF YOU ARE USING THE COBOL ‘GIVING’ VERB.

GIVING IS NOT OPTIONAL WITH DIVIDE---BY VERB.

USE ‘05’ INSTEAD OF ‘02’ FOR SPECIFYING NEXT LEVEL WITHIN A GROUP.

USE X FILED FOR FILE\SORT STATUS AND FILLER CLAUSES.

ALL DELIMITERS MUST BE FOLLOWED BY A SPACE IN COBOL.

ARITHMETIC OPERATORS MUST BE FOLLOWED BY A SPACE IN COBOL.

AVOID USING GO TOs AND ALTER STATEMENTS.

SUGGEST COMP-3 WHEN THERE IS A NEED OF A DECIMAL POINT.

NEVER USE COMP FOR A NON-INTEGER NUMERIC (REAL NO).

YOU MUST USE SYNC FOR COMP-2 DATA ITEM.

SUGGEST COMP-3 FOR S9(1) AND S9(5) DATA ITEMS THAN COMP.

USE SIGN SEPARATE CLAUSE THAN EDITING CHARACTERS.

USAGE MUST BE NUMERIC DISPLAY WHILE USING SIGN CLAUSE.

AVOID USING DATA CONVERSIONS IF POSSIBLE.

NEVER TRY TO MOVE A COMP/COMP-3(BINARY/DECIMAL) FIELD TO DISPLAY(EBCDIC).

0-9 (NUMERIC) IS > A-Z (ALPHABET) IN EBCDIC COLLATING (MAINFRAMES). A-Z IS > 0-9 IN
PC (ASCII).

IF THERE IS NO END-IF, THEN THE CURRENT ELSE STATEMENT IS MATCHED TO THE LAST
IF STATEMENT THAT DOESN’T HAS AN ELSE PAIR.

ROUNDED & ON SIZE ERROR CANNOT BE USED WITH MOVE STATEMENT. USE ONLY WITH
ARITHMETIC VERBS.

USE INDEXES INSTEAD OF SUBSCRIPTS.

INDEXED BY IS A SUB PART OF OCCURS CLAUSE AND MUST BE SPECIFIED WITH OCCURS
CLAUSE WITH OUT ANY DECLARATION.

ASCENDING/DESCENDING IS A SUB PART OF OCCURS + INDEXED CLAUSE AND MUST BE
SPECIFIED AFTER OCCURS BUT BEFORE INDEXED BY.

STRING VERBS CAN ONLY BE USED WITH DISPLAY USAGE.

'FOR' PHRASE IS NOT OPTIONAL IN INSPECT – TALLYING VERB.

DELIMITED PHRASE IS NOT OPTIONAL IN STRING VERB.

USE 01 LEVEL ITEM FOR DECLARING LINKAGE SECTION ENTRIES.

USE INDEXES INSTEAD OF SUBSCRIPTS IF POSSIBLE.

NEVER REDEFINE A COMP/COMP-3 ITEM OVER A DISPLAY USAGE.

NEVER TRY TO ACCEPT A COMP/COMP-3 ITEM DIRECTLY FROM CONSOLE.

USE SYNC CLAUSE FOR COMP, COMP-1 & COMP-2 DATA ITEMS.

USE EVALUATE STATEMENT INSTEAD OF NESTED IF STATEMENT.

USE CONTINUE INSTEAD OF NEXT SENTENCE.

PERFORM BINARY SEARCH IF THE NO OF ELEMENTS OF THE TABLE IS GREATER THAN 70.

ALWAYS SPECIFY BINARY USAGE FOR SUBSCRIPTS & COUNTERS.

YOU CANNOT USE EXTERNAL & GLOBAL VARIABLES IN LINKAGE SECTION.

YOU CAN SET PASSWORD FROM COBOL ONLY TO VSAM FILES.

PADDING CHARACTERS & RECORD DELIMITERS ARE VALID ONLY FOR SEQUENTIAL FILES.

THE USAGE OF THE FILE STATUS MUST BE DISPLAY.

THE VSAM STATUS CODE MUST BE A GROUP ITEM OF LENGTH 6.

YOU CANNOT RERUN OR OVERRIDE (SAME AREA) EXTERNAL FILES.

EXTERNAL FILES MUST BE REUSED ONLY UNDER SAME ACCESS MODE.

RECORD KEY/RELATIVE KEY OF EXTERNAL FILES MUST BE EXTERNAL WITH SAME SIZE.

RECORD KEY MUST NOT BE A VARIABLE LENGTH GROUP ITEM.

YOU MUST SPECIFY AS- ASSIGN ORGANIZATION IN SELECT CLAUSE FOR VSAM/ESDS FILE.
ex: SELECT seqfile ASSIGN TO AS-jclddname.
FILE STATUS FS, VSC.

AVOID USING NONSTANDARD LEVEL NUMBERS. (Such as 02,03,04,06 etc---). INSTEAD USE 05 TO DECLARE ELEMENTARY ITEMS OF A GROUP.

DECLARE ALL ITEMS IN LINKAGE SECTION WITH 01 LEVEL NUMBER (instead of 77).

DECLARE DECIMAL & BINARY DATA WITH 01 LEVEL NO. (Instead of 77)

DECLARE FILE STATUS & RECORD KEY AS ALPHANUMERIC ALWAYS.

DON’T SPECIFY RECORDING MODE CLAUSE FOR VSAM FILES.

SPECIFY BLOCK CONTAINS 0 RECORDS ONLY FOR FB, VB & Spanned QSAM/SAM FILES.

DON’T SPECIFY ANY FILE DESCRIPTION ENTRY FOR VSAM FILES (ESDS/RRDS/KSDS).

ALWAYS USE PROGRAM-ID AS 8 CHAR ALPHABET NAME WITHOUT ANY HYPHEN. FIRST CHAR MUST BE AN ALPHABET. (Otherwise, system will replace it)

USE SYNC CLAUSE ONLY FOR BINARY DATA ITEMS.

AVOID DATA CONVERSIONS BY REDEFINING.

YOU CAN’T ACCEPT A NEGATIVE VALUE WITHOUT ‘S’ SIGN FOR ANY USAGE.

YOU CANNOT INITIALIZE A GROUP AS ALPHANUMERIC IF THE GROUP CONTAINS USAGE/SYNC/JUST CLAUSE.

ALL ARITHMETIC & RELATIONAL OPERATORS MUST PROCEED & FOLLOW BY A SPACE.

DON’T PROVIDE ANY SPACE B/W RELATIONAL OPERATORS. ( Ex: <= , >= )

Copyright 2003-2016 © IBMMAINFRAMES.com All rights Reserved.

Home | Mainframe Wiki | Free Downloads | Sample Programs | More References | Mainframe Forum