Refactoring source code
The z Systems® LPEX Editor and the COBOL Editor automatically provides various refactoring for you to work with source codes in COBOL program files.
Extracting code into a new copybook
You can extract contiguous COBOL statements into a new COBOL copybook.
Before you begin
- COBOL Editor
- z Systems LPEX Editor
About this task
- Validity
- The action is enabled only when text is selected in the Procedure Division of the COBOL source. Furthermore, if you select a COBOL word or variable name, the action is disabled.
- Completeness
- The selected text contains one or more valid COBOL statements. It also means that if you select a partial statement such as an IF statement or a partial PERFORM statement, the action is disabled until you extend the selection to select the complete IF or PERFORM statement.
Procedure
To extract code to a new copybook, complete the following steps:
Extracting code into a new program file
You can extract contiguous COBOL statements into a new program file.
Before you begin
- COBOL Editor
- z Systems LPEX Editor
- Extracting code into a new program file is unsupported in files that contain preprocessor directives.
- Extracting code into a new program file is unsupported for program logic involving an
SQL DECLARE
statement. - Selected
REPLACE
statements can only be manually transferred. - Avoid using Refactor > Create Program under the COBOL 6.2 conditional directives.
- You need to specify a procedure copybook file if there are referenced paragraphs or procedures to be made "common." If there aren't any commonly referenced paragraphs or procedures from the selection, the option is not available.
- In the z Systems LPEX editor, this operation cannot be undone.
- Create Program is disabled in the following conditions:
- Selection contains
OPEN
,READ
,WRITE
, andCLOSE
clauses. - Selection contains references to file descriptors.
- Selection contains the COBOL words, such as
EXIT PROGRAM
,STOP RUN
,GOBACK
,CANCEL
. - Selection contains the CICS® words, such as
EXEC CICS RETURN
.
- Selection contains
About this task
- Validity
- The action is enabled only when text is selected in the Procedure Division of the COBOL source. Furthermore, if you select a COBOL word or variable name, the action is disabled.
- Completeness
- The selected text contains one or more valid COBOL statements. It also means that if you select a partial statement such as an IF statement or a partial PERFORM statement, the action is disabled until you extend the selection to select the complete IF or PERFORM statement.
- Logic
- The selected texts must have a logic with procedure calls. If the extracted code is not
consecutive in the current program, an error displays to explain the problem. You can continue and
accept the updates. If the extracted code is valid, the
COPY
insertion is made in the same location in the source code.
Procedure
To extract code into a new program file, do these steps:
Renaming a data item or paragraph in a COBOL program
You can rename a data item or paragraph and references to that data item or paragraph in a COBOL program.
About this task
- COBOL Editor
- z Systems LPEX Editor
The Rename operation shows an information screen with the projected warnings and how many data items are going to be changed if the refactor operation is committed. Optionally, another page is shown with a preview of what the source will look like compared to the original source after the refactor operation is accepted.
The preview page shows the Rename function.
- The Rename action does not recognize Pseudo SO/SI bytes included in DBCS strings.
- The Remove noise words and Extract paragraph actions do not work when sequence numbers are present.
- The Rename action does not work on DBCS variable names.
- When errors are detected by real-time syntax checking, the Rename action is not available.
Procedure
To rename a data item or paragraph in your COBOL file, complete the following steps:
Extracting a paragraph or section in a COBOL program
You can extract contiguous COBOL statements into a new paragraph or section.
Before you begin
- COBOL Editor
- z Systems LPEX Editor
About this task
- Validity
- The action is enabled only when text is selected in the Procedure Division of the COBOL source. Furthermore, if you select a COBOL word or variable name, the action is disabled.
- Completeness
- The selected text contains one or more valid COBOL statements. It also means that if you select a partial statement such as an IF statement or a partial PERFORM statement, the action is disabled until you extend the selection to select the complete IF or PERFORM statement.
- Logic
- The selected texts must have a logic with procedure calls. If the extracted code is not
consecutive in the current program, an error displays to explain the problem. You can continue and
accept the updates. If the extracted code is valid, the
COPY
insertion is made in the same location in the source code.
Procedure
To extract a paragraph or section, complete the following steps:
Removing specified unnecessary words from a COBOL program
You can remove specified unnecessary words from a COBOL program. The words, IS, THEN, and
PROCEED TO are not necessary in the COBOL source. They are considered noise
words. Removing
these words from the source has no effect on compiling the program.
About this task
- COBOL Editor
- z Systems LPEX Editor
Procedure
Identifying unused variables and copybooks
An unused variable is one whose data element structure, including parent and subordinate items, is not referred to in the main program. An unused copybook is one that contains unused variables. You can view the unused variables and copybooks and remove them from the program to clean it of superfluous information.
Before you begin
- COBOL Editor
- z Systems LPEX Editor
- To set the appearance and placement of annotations:
- Select .
- On the Annotations page, select Highlight Unused Variables and change the settings as needed.
- Click OK to save the changes.
- To identify unused variables or copybooks when you save a program in the editor:
- Select .
- On the Save Actions page, select Identify unused variables and then click OK to save the setting.
- This function is not supported in files that contain preprocessor directives.
- This function identifies unused variables with complete data structures only. Unused subordinates of a variable are not shown individually.
- In the z Systems LPEX editor, this operation cannot be undone.