Tutorial for the VS Code extension: Getting a backward data flow slice
Perform the tutorial based on the sample project GenApp to explore how to get a backward data flow slice.
Tutorial scenario
Many a time you need to understand how a variable gets the value that is used to update a database table or the query information from a database table. To meet these needs, you can perform a backward data flow analysis. In this tutorial, you will learn how to get a backward data flow slice for a variable that participates in a database operation. The slice shall consist of all the statements from all the programs in the backward call chain that play a role in determining the value of the variable. The tutorial performs a context sensitive analysis so that infeasible paths can be ruled out.
Assumption
The output of the backward data flow slice is presented in the form of a workbook. You can use the output in determining the code blocks that are needed for creating services by using the forward code slicing as explained in Tutorial for the VS Code extension: Isolating or extracting the Update Motor Policy functionality as a service.
The following tutorial is based on the assumption that you want to analyze the data access of the program LGUPDB01 and then get a backward data flow slice on the Read variables in SQL queries.
Prerequisites
- You have installed and configured Z Refactoring Assistant as instructed in Getting started.
- You have built the GenApp project in the IBM AD Build Client as described in Prerequisite: Building the GenApp project.
- You have installed the IBM watsonx Code Assistant for Z Refactoring Assistant Visual Studio Code extension as described in Installing and setting up.
Procedures
- Launch your Visual Studio Code application.
- Select .
- Select a folder that contains all of your project files from the dialog and click Select Folder to confirm your selection. The workspace folder is opened in your Visual Studio Code window.
- Open the Visual Studio Code Command Palette by selecting from the Visual Studio Code menu.
- Enter Preferences: Open User Settings in the command palette.
- Search for
IBM watsonx Code Assistant for Z Refactoring Assistant
to locate the extension settings. - Enter the URL of the Refactoring Assistant server as the Refactoring Assistant Server: URL property value.
- Select the Accounts icon in the Visual Studio Code Activity Bar and select Sign in with IBM ADDI to use IBM watsonx Code Assistant for Z Refactoring Assistant.
- After you log into ADDI, you will be prompted to select an AD project. From the AD project drop-down list, select the project that you built with IBM AD Build Client.
- The Graph view of the GenApp project is
displayed. Note: The Graph view maintains the connection to the Refactoring Assistant server and should remain open while working with AD projects. If this window is closed, use the Visual Studio Code Accounts icon to log into the server again.
- Choose the program for which you want to analyze the data access. For demonstration purpose, the program LGUPDB01 is used in this tutorial. Type LGUPDB01 in the search box. You will see LGUPDB01 in the results.
- Click the result item LGUPDB01 and then press Enter. A table closure is
computed and displayed as the following example.
- Click the Action Menu (
) icon on the upper right corner of the LGUPDB01 program node and select the Identify table/file access statements option.
- From the Key Conditions view, click the SQL
statement of interest, which scrolls the source code editor to the location of the selected
conditional statement. For example, click EXEC SQL (line 475),
you can see the text that is selected in the editor as shown in the following screenshot.
- In the Key Conditions view, right-click the key condition
EXEC SQL (line 475)
and then select Slice on variable to new service. - Enter Data Analysis when prompted for a name for the new service.
- Select the variable for which you want to get the data flow analysis. For example, select the
DB2-POLICYNUM-INT variable from the list.
- Select Yes for the Perform context sensitive analysis if
possible? question.Note: When you choose to perform context sensitive analysis, the analysis will try to eliminate infeasible paths and make the analysis results more precise. However, the analysis can be more time-consuming in the meantime. Since the analysis relies on static analysis data, some degree of imprecision might still be found in the data flow analysis and the slice might show some infeasible paths.
- The workbook editor opens on the
Data Analysis.cbls
file, which shows the service code blocks. If the workbook editor is opened in a view group next to the read-onlyLGUPDB01.cbl
file, select a code block to scroll the source file to the selected block so that you can view the block in context. Scroll up and down to see all the statements across the program call chain that are involved in the data flow for the chosen variable.The Project Artifacts view is populated with all referenced project files.
Now, you have explored how to get a backward data flow slice to perform a data flow analysis for a variable. You can repeat the procedures to slice on other data access statements of interest for analysis.