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 Understand 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 Understand 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 Understandto locate the extension settings. - Enter the URL of the Refactoring Assistant services as the Z Code Assistant > Understand: URL property value.
- Select the Accounts icon in the Visual Studio Code Activity Bar and select Sign in with Z Understand to use IBM watsonx Code Assistant for Z Understand.
- After you log into Z Understand, you will be prompted to select an analysis project. From the analysis 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 Z Understand server and should remain open while working with analysis project. 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. In the flow chart, you can see that the LGUPDB01 program node has dotted arrows pointing outwards, which denote the data access on tables and files from the respective node.
- 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 Project Artifacts 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) to see the source code associated with the selected key condition.
- In the Project Artifacts view, right-click the key condition
EXEC SQL (line 475)and then select Slice on variable to new service for data flow analysis. - 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.cblsfile, which shows the service code blocks. If the workbook editor is opened in a view group next to the read-onlyLGUPDB01.cblfile, 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.