Using Code Extract view


Often COBOL programs contain the logic for multiple functions. If a developer wants to work on the logic in one part, they need to check out, edit, compile, test, and then deploy the entire program. With the help of Code Extract View, you can break apart the program to make concurrent work more effortless. In the Code Extract View in BMC AMI DevX Code Insights, you can create a separate callable subprogram based on a selected procedure. When the new subprogram is ready to compile, it receives the inputs from the call and returns what is needed. The original main program will now contain a call to the new subprogram, sending and receiving the data, in place of the previous code. This feature is only available for COBOL programs.

When you have your program in Code Insights, select the Code Extract tab. You can see the following procedures in your program and they will be ranked as candidates for extract. You can adjust the score used for ranking.

Column

Description

Procedure Name

Name of the procedure

Score

The score used for ranking

Bus Logic Stmts

Business logic statement

Complexity

Complexity based on McCabe metric

Extract: Code %

Percentage of program

Extract: Dup Code %

Percentage of programs that would be duplicated

Extract: Procedures

Procedure in extract

Extract: Dup Procedures

Procedure in the extract that would be duplicated

Extract: Stmts

Statements in extract

Extract: Dup Stmts

Statements in the extract that would be duplicated


Right-click on the procedure and select the following required option:

  • Extract Preview 
  • Extract Code
  • Select Business Logic Data Items
  • Configure Procedure Extract Scoring

Extract Preview

Select the Preview Extract option. The Extract Preview report is displayed within the editor. The Extract Preview report displays what other procedures might come with the selected procedure and if there is a possibility for duplicate code. 

image-2023-11-22_17-32-28.png

Extract Code

When you select the Extract Code option. The Extract Code dialog box is displayed.

image-2023-11-22_16-50-19.png

In the Extract Code dialog box, you can perform the following actions:

  • In the New program name for extracted code field, enter the name for the new extracted program.
  • Select the required option in the Duplicate Procedure Handling field.
  • Select the Comment out dead code check box to comment out any dead code that is in the programs. It isn't unusual for programs to have code that cannot be reached. This can cause confusion for developers because it might not be obvious. When you select this option the code will have an asterisk in column 7 and a banner indicating it is code that was determined to not be executable.
  • Select the Comment out unused Db2 and file declarations check box to comment out any unused file and Db2 declarations in the program.
  • Click OK.

This creates a folder in the project. The folder name is the program name you have entered for your extract and the date and time are also included. This enables you to distinguish between extracts if you are trying out various extract strategies. The folder contains the following.

  • The new main program that now has a call to the newly created subprogram
  • The new extract program
  • Any copybooks created to eliminate duplicate code
  • A Report that provides you with details of what was selected for this extract
  • A log containing diagnostics in case there was an issue with the extract. This can be sent to support to help in problem resolution

Select Business Logic Data Items

Select the Select Business Logic Data Items option. The Select Business Logic Data Items dialog box is displayed.

image-2023-9-1_15-40-36.png

  • From the Select data item dropdown, select the data item or enter the text that is related to the desired business logic. When you return to the Extra view, there will be a count of the data items found in each of the procedures. The ranking score will be affected by the amount of weight you have given to Business Logic Statements.
  • Select the Include impacted data items (Find indirect) check box.
  • Select the Include aliases check box.
  • Click OK.

Configure Procedure Extract Scoring

The Code Extract view contains a Score column that ranks the procedures by desirability for extract. You can configure the scoring to give a higher weight as per your requirement. 

Select the Configure Procedure Extract Scoring option. The Configure Procedure Extract Scoring dialog box is displayed.

image-2023-9-1_15-42-16.png

Configure the procedure extract scoring and click OK to save your changes. You can configure the procedure extract scoring based on the following use cases.

  • Business Logic Extraction - You want to find where certain business logic resides, then extract that into a new subprogram. The way to do this is to locate statements using the key fields you enter. Giving this a higher ranking will make it easier for you to identify this logic.
  • Removing Complexity - You may feel that the current program is just too complex to understand. By breaking it into smaller, easier-to-understand programs it will be easier to work with and test. Complexity is based on the McCabe Complexity Score and is here given Low, Medium, or High. Ranking Complexity higher will move Procedures with higher complexity up in the sort order.
  • Removing Statements - You may want to remove as many statements as possible. If you have a standard that programs cannot exceed a line count you can give priority to statement count to identify extracts that will remove the most lines possible.
  • Duplicate Code - As discussed in a different section, splits can sometimes result in duplicate code, putting this higher in the ranking will help you to identify Procedures that have the characteristics you desire, but would not result in duplicate code.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*