Efficient Editing Techniques for COBOL, JCL, and PL/I Source Code
Editing mainframe source code efficiently requires understanding the unique requirements and conventions of each language. COBOL, JCL, and PL/I each have specific column positioning rules, formatting requirements, and best practices that, when mastered, dramatically improve your editing speed and accuracy. This tutorial covers language-specific techniques, ISPF editor features that support each language, and productivity tips that help you work more efficiently.
Whether you're maintaining legacy code or writing new programs, efficient editing techniques reduce errors, save time, and make code easier to read and maintain. The ISPF editor provides powerful features specifically designed to support fixed-format languages, and learning to leverage these features effectively is essential for mainframe development productivity.
Mainframe source languages like COBOL, JCL, and PL/I use fixed-format coding, meaning specific columns have specific meanings. Unlike free-format languages where you can place code anywhere, fixed-format languages require code to be in particular column ranges. Understanding these requirements is the foundation of efficient editing.
Why Fixed-Format Matters
Fixed-format coding exists because these languages were designed when programs were stored on punched cards, where each column position had physical meaning. While modern development doesn't use punched cards, the column requirements remain because:
Compiler Requirements: Compilers expect code in specific columns and may reject or misinterpret code in wrong positions.
Legacy Compatibility: Existing codebases follow these conventions, and maintaining consistency is important.
Standards Compliance: Many organizations have coding standards that enforce column positioning.
Tool Compatibility: Various mainframe tools (formatters, analyzers, documentation generators) expect code in standard positions.
The ISPF editor helps you maintain proper column positioning through visual markers, margins, and column display features. Learning to use these features effectively is crucial for efficient editing.
COBOL Editing Techniques
COBOL has the most strict column requirements of the three languages. Understanding COBOL's column structure and using ISPF features to maintain it is essential for efficient COBOL editing.
COBOL Column Structure
COBOL source code is organized into specific column areas, each with distinct purposes:
Columns 1-6 (Sequence Number Area): Optional area for line sequence numbers. Often left blank in modern development but may be used for version control or line identification. Some organizations use this area for sequence numbers that help with change tracking.
Column 7 (Indicator Area): Single character that indicates line type:
Blank: Regular source code line
* (asterisk): Comment line - entire line is treated as a comment
/ (slash): Comment line that causes page eject when printing
- (hyphen): Continuation line - indicates this line continues the previous line
D: Debug line - included only when compiler debug option is enabled
Columns 8-11 (Area A): Reserved for division headers, section names, paragraph names, FD (File Description), SD (Sort Description), 01 level numbers, and 77 level numbers. Code in Area A must start at column 8, 9, 10, or 11, but typically starts at column 8 for alignment.
Columns 12-72 (Area B): Where most COBOL code goes. Statements, data definitions (02-49, 66, 88 levels), procedure code, and most other COBOL syntax must be in Area B. Code can start anywhere from column 12 to column 72, but typically starts at column 12 for readability.
Columns 73-80 (Identification Area): Optional area often used for sequence numbers, program identification, or left blank. Some organizations use this for change tracking or version control information.
ISPF Editor Features for COBOL
ISPF provides several features specifically helpful for COBOL editing:
Column Markers
Enable column markers in ISPF Settings (Option 0) to display vertical lines at key column positions. For COBOL, markers at columns 1, 7, 8, 12, and 72 are particularly useful. These visual guides help you position code correctly without constantly counting columns.
Column markers appear as vertical lines on the screen, making it easy to see where Area A ends and Area B begins, where the indicator area is, and where lines should end. This visual feedback is invaluable for maintaining proper formatting, especially when editing existing code or when you're learning COBOL column requirements.
Margins for COBOL
Set your left margin to column 8 (for Area A entries) or column 12 (for Area B entries) depending on what you're editing. The right margin should typically be set to column 72 to prevent accidentally typing beyond the valid code area. ISPF will automatically wrap or warn you if you try to type beyond the right margin.
You can change margins dynamically using the MARGINS command or by setting them in your editor profile. For mixed editing (both Area A and Area B code), you might set the left margin to 12 (Area B) and manually position Area A entries, or use the TAB key if configured to jump to column 8.
COBOL-Specific Editing Tips
Use FIND for Navigation: Use FIND to locate specific divisions (IDENTIFICATION DIVISION, DATA DIVISION, PROCEDURE DIVISION), sections, or paragraph names. For example, FIND PROCEDURE DIVISION quickly jumps to the procedure section.
Block Commands for Formatting: Use block commands to align multiple data definitions or statements. For example, select a block of 05-level data items and use SHIFT to align them consistently.
Line Commands for Structure: Use line commands like CC (copy) and MM (move) to duplicate similar data structures or procedure sections, then modify as needed.
Continuation Lines: When a line exceeds column 72, place a hyphen (-) in column 7 of the next line and continue the statement starting in column 12. ISPF can help align continuation lines using SHIFT commands.
Comment Management: Use * in column 7 for full-line comments. For inline comments in Area B, use the comment delimiter (*> in modern COBOL or * in column 7 of a separate line).
COBOL Editing Example
Here's an example showing proper COBOL formatting with column positions indicated:
text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE01.
AUTHOR. YOUR-NAME.
*
* This is a comment line
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-COUNTER PIC 9(05) VALUE ZERO.
01 WS-RESULT PIC 9(10) VALUE ZERO.
PROCEDURE DIVISION.
MAIN-PARAGRAPH.
DISPLAY 'Hello, World!'
ADD 1 TO WS-COUNTER
IF WS-COUNTER > 100
DISPLAY 'Counter exceeded 100'
END-IF
STOP RUN.
Notice how:
Division and section names start in Area A (column 8)
Comment lines have * in column 7
Data items (01 level) start in Area A (column 8)
Procedure code starts in Area B (column 12)
All code stays within columns 12-72 (Area B)
JCL Editing Techniques
JCL (Job Control Language) has different formatting requirements than COBOL. JCL statements are simpler in structure but have their own conventions that, when followed, make JCL easier to read and maintain.
JCL Column Structure
JCL statements follow these column conventions:
Columns 1-2: JCL statement identifier. Must be // for JOB, EXEC, DD, and most JCL statements. /* indicates end of input data. //* indicates a comment line.
Column 3 and beyond: JCL statement content. The statement name (JOB, EXEC, DD) typically starts immediately after //, followed by parameters.
Continuation: When a JCL statement is too long, continue it on the next line by placing // in columns 1-2, then continue the statement starting at an appropriate column (often column 3 or aligned with previous content).
Comments: Lines starting with //* are treated as comments and ignored by the system.
ISPF Editor Features for JCL
JCL editing benefits from several ISPF features:
Alignment and Formatting
JCL statements are easier to read when parameters are aligned. Use ISPF block commands and SHIFT to align similar parameters across multiple statements. For example, if you have multiple DD statements, aligning the DD names and dataset names makes the JCL much more readable.
Use column markers at column 1 and column 3 to help maintain proper JCL formatting. The visual guide helps ensure // is always in the correct position and that statement content starts in the right place.
JCL-Specific Editing Tips
Copy Similar Statements: JCL often has repetitive DD statements. Use line command CC to copy a DD statement, then modify the dataset name and other parameters. This is faster and less error-prone than typing each statement.
FIND for Dataset Names: Use FIND to locate all references to a specific dataset name when you need to update it across multiple statements.
Block Operations: Use block commands to modify multiple similar statements at once. For example, you might need to add the same parameter to multiple DD statements.
Comment Management: Use //* for comments. You can use block commands to comment or uncomment multiple lines if needed.
Parameter Alignment: Align parameters vertically for readability. For example, align all DSN= parameters or all DISP= parameters to make JCL easier to scan and understand.
Statement names (JOB, EXEC, DD) start immediately after //
PL/I Editing Techniques
PL/I is more flexible than COBOL but still has conventions that, when followed, improve code readability and maintainability. PL/I allows free-format coding within certain boundaries.
PL/I Column Structure
PL/I source code follows these conventions:
Column 1: Often reserved for continuation indicators. A + or - in column 1 indicates the line continues the previous statement. Some organizations use column 1 for other special purposes.
Column 2 and beyond: PL/I source code. Code can start at column 2 or later, with typical indentation for nested structures. Most organizations use column 2 or a consistent indentation (like column 5 or 8) for the start of code.
Line Length: While PL/I doesn't have the strict 72-column limit of COBOL, many organizations enforce a maximum line length (often 72 or 80 columns) for compatibility and readability.
Continuation: Use + or - in column 1 to indicate continuation lines. The continuation character helps compilers and formatters understand line relationships.
Comments: PL/I uses /* */ for block comments and // for line comments (in some dialects). Comments can appear anywhere in the code.
ISPF Editor Features for PL/I
PL/I editing benefits from flexible ISPF features:
Flexible Formatting
PL/I's flexibility means you can use ISPF's formatting features more freely. Use SHIFT commands to adjust indentation for nested structures, use block commands to format similar code blocks consistently, and use alignment features to improve readability.
Set margins appropriate for your organization's PL/I coding standards. Many organizations use column 2 as the left margin and column 72 or 80 as the right margin, but this can vary.
PL/I-Specific Editing Tips
Indentation for Structure: Use consistent indentation to show program structure. ISPF block commands help maintain consistent indentation across similar code blocks.
Block Comments: PL/I block comments (/* */) can span multiple lines. ISPF can help format and manage these effectively.
Continuation Management: When lines are too long, use + or - in column 1 for continuation. ISPF can help align continuation lines.
Case Sensitivity: PL/I is case-insensitive, but consistent casing improves readability. Use ISPF text transform commands (UPPER, LOWER, CAPS) to maintain consistent casing.
Structure Navigation: Use FIND to locate procedure definitions, BEGIN blocks, and other structural elements. PL/I's block structure benefits from good navigation techniques.
PL/I Editing Example
Here's an example showing PL/I formatting conventions:
text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* PL/I Program Example */
EXAMPLE: PROCEDURE OPTIONS(MAIN);
DECLARE (COUNTER, RESULT) FIXED BINARY(31) INITIAL(0);
DECLARE MESSAGE CHARACTER(50) VARYING;
/* Main processing logic */
DO COUNTER = 1 TO 100;
RESULT = RESULT + COUNTER;
END;
MESSAGE = 'Processing complete. Result = ' ||
+ PUT(RESULT);
PUT SKIP LIST(MESSAGE);
END EXAMPLE;
Notice how:
Code starts at column 5 (typical indentation)
Continuation line uses + in column 1
Block comments use /* */
Indentation shows program structure
Code stays within reasonable column limits
Common Editing Techniques Across Languages
While each language has specific requirements, many efficient editing techniques apply to all three languages. Mastering these general techniques improves your productivity regardless of which language you're editing.
Navigation Techniques
Efficient navigation is crucial when working with large source files:
FIND Command: Use FIND to locate specific text, procedure names, data names, or structural elements. FIND is case-insensitive by default but can be made case-sensitive. Use FIND NEXT to locate subsequent occurrences.
Line Number Navigation: Use line numbers to jump to specific lines. Type a line number and press Enter to jump directly to that line. This is useful when you know the approximate location or when working with compiler error messages that reference line numbers.
Top and Bottom: Use T (top) line command or TOP primary command to jump to the beginning of the file. Use B (bottom) line command or BOTTOM primary command to jump to the end.
Split Screen: Use split-screen mode to view different parts of the same file simultaneously. This is invaluable when you need to reference one part of the code while editing another.
Text Manipulation Techniques
ISPF provides powerful text manipulation features:
FIND and CHANGE: Use FIND to locate text and CHANGE to replace it. CHANGE can replace a single occurrence or all occurrences (CHANGE ... ALL). This is essential for renaming variables, updating dataset names, or making consistent changes across code.
Block Commands: Use block commands to operate on multiple lines simultaneously. Select a block of lines and apply commands like SHIFT (to indent), DELETE, COPY, or text transformations.
Line Commands: Use line commands (CC for copy, MM for move, DD for delete, etc.) for efficient line-level operations. These are faster than using primary commands for single-line operations.
Text Transform: Use text transform commands (UPPER, LOWER, CAPS) to change case. This is useful for maintaining consistent casing, especially in languages where case doesn't matter but readability does.
Formatting and Alignment
Consistent formatting improves code readability:
SHIFT Commands: Use SHIFT LEFT and SHIFT RIGHT to adjust indentation. This is crucial for maintaining proper column positioning in fixed-format languages and for maintaining consistent indentation in all languages.
Alignment: Use block operations to align similar elements. For example, align all assignment statements, align all parameter lists, or align similar data definitions.
Column Positioning: Use column markers and margins to maintain proper positioning. The visual feedback helps you stay within language-specific column requirements.
Consistent Spacing: Maintain consistent spacing around operators, keywords, and parameters. ISPF can help with this through careful use of editing commands.
Error Prevention Techniques
Preventing errors is more efficient than fixing them:
Verify Column Positions: Always verify that code is in the correct columns, especially when copying or moving code. Column markers help with this.
Test Incrementally: Make small changes and test frequently rather than making many changes at once. This makes it easier to identify problems.
Use FIND Before CHANGE: Use FIND to locate all occurrences before using CHANGE, especially when changing variable names or dataset names. This helps ensure you change all necessary occurrences and don't change things you shouldn't.
Save Frequently: Save your work frequently to avoid losing changes. ISPF automatically saves to temporary storage, but explicit saves ensure your changes are preserved.
Review Before Saving: Review your changes before final save, especially when using block operations or global changes. Use BROWSE mode or split-screen to review without making changes.
Language-Specific Best Practices
Each language has best practices that, when followed, improve code quality and editing efficiency:
COBOL Best Practices
Always Verify Column Positions: COBOL's strict column requirements mean incorrect positioning causes compiler errors. Always verify Area A and Area B positioning.
Use Meaningful Paragraph Names: Well-named paragraphs make navigation easier. Use FIND to jump to specific paragraphs by name.
Maintain Consistent Indentation: Even within Area B, consistent indentation improves readability. Use SHIFT commands to maintain alignment.
Comment Complex Logic: Use comment lines (* in column 7) to explain complex logic. Well-placed comments make maintenance easier.
Group Related Data: Keep related data definitions together. Use block commands to move or copy related groups.
JCL Best Practices
Align Parameters: Align similar parameters across statements for readability. Use block commands to maintain alignment.
Use Consistent Naming: Use consistent naming conventions for step names, DD names, and dataset names. FIND helps locate all references when names need updating.
Comment Complex JCL: Use //* comments to explain complex JCL logic or parameter choices.
Group Related Statements: Keep related DD statements together. Use line commands to organize statements logically.
Verify Dataset Names: Always verify dataset names are correct. Use FIND to locate all references before making changes.
PL/I Best Practices
Maintain Consistent Indentation: PL/I's block structure benefits from consistent indentation. Use SHIFT commands to maintain alignment.
Use Meaningful Names: Well-named variables and procedures make code self-documenting and easier to navigate.
Comment Complex Logic: Use comments to explain complex algorithms or business logic.
Group Related Declarations: Keep related variable declarations together. Use block commands to organize code.
Maintain Consistent Formatting: Consistent formatting improves readability. Use ISPF formatting features to maintain consistency.
Explain Like I'm 5: Editing Source Code
Think of editing source code like writing on special paper with boxes:
COBOL is like writing on paper with very strict boxes. Some things (like titles) must go in the left box (Area A), and most writing must go in the right box (Area B). If you write in the wrong box, the teacher (compiler) won't understand your work. The ISPF editor is like having a helper who draws lines on the paper so you always know which box to write in!
JCL is like writing instructions that always start with // at the beginning of each line. It's like writing a recipe where every step starts the same way. The ISPF editor helps you copy similar instructions quickly, so you don't have to write the same thing over and over!
PL/I is like writing on paper where you have more freedom, but you still want to write neatly in lines. You can start writing almost anywhere, but it's better to keep things organized. The ISPF editor is like having a ruler that helps you keep your writing straight and organized!
Editing Tools are like having special helpers: FIND is like a magic pointer that shows you where specific words are, CHANGE is like an eraser and pen that fixes words automatically, and block commands are like having scissors and glue that let you move whole paragraphs at once!
So editing source code is like writing on special paper with helpful tools that make sure everything goes in the right place and looks neat!
Practice Exercises
Complete these exercises to master efficient editing techniques:
Exercise 1: COBOL Column Positioning
Objective: Practice proper COBOL column positioning.
Steps:
Open a COBOL source file in ISPF editor.
Enable column markers (Settings, Editor options).
Locate the PROCEDURE DIVISION using FIND.
Verify that division/section names are in Area A (columns 8-11).
Verify that procedure code is in Area B (columns 12-72).
Add a new paragraph name in Area A and a simple DISPLAY statement in Area B.
Add a comment line using * in column 7.
Exercise 2: JCL Statement Management
Objective: Practice efficient JCL editing techniques.
Steps:
Open a JCL file in ISPF editor.
Use FIND to locate all DD statements.
Use line command CC to copy a DD statement.
Modify the copied statement to reference a different dataset.
Use block commands to align DSN= parameters across multiple DD statements.
Add a comment line using //*.
Exercise 3: Navigation and Search
Objective: Master navigation and search techniques.
Steps:
Open a large source file (COBOL, JCL, or PL/I).
Use FIND to locate a specific procedure name or data name.
Use FIND NEXT to locate subsequent occurrences.
Use line numbers to jump to a specific line.
Use TOP command to jump to the beginning.
Use BOTTOM command to jump to the end.
Use split-screen to view the beginning and end simultaneously.
Exercise 4: Text Manipulation
Objective: Practice text manipulation techniques.
Steps:
Open a source file and use FIND to locate a variable name or dataset name.
Use CHANGE to replace a single occurrence.
Use FIND to verify all occurrences before using CHANGE ... ALL.
Use CHANGE ... ALL to replace all occurrences of a name.
Use block commands to select multiple lines and apply SHIFT to adjust indentation.
Use text transform (UPPER) to change case of selected text.
Exercise 5: Complete Workflow
Objective: Combine all techniques in a realistic editing scenario.
Steps:
Open a source file that needs modification.
Use FIND to locate the section that needs changes.
Use split-screen to view related code sections.
Make the necessary edits using appropriate column positioning.
Use block commands to format the changes consistently.
Use FIND to verify all related references are updated.
Review changes before saving.
Test Your Knowledge
1. In COBOL, where does Area A start?
Column 1
Column 8
Column 12
Column 72
2. What character is used in column 7 of COBOL for comments?
C
*
#
!
3. In JCL, where should JOB statements start?
Column 8
Column 1 or after //
Column 12
Anywhere
4. What ISPF command helps you locate specific text in source code?
LOCATE
FIND
SEARCH
GOTO
5. In COBOL, where does Area B (where most code goes) start?
Column 1
Column 8
Column 12
Column 72
6. What is the maximum recommended column for COBOL source code?