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.

Note: The current version of IBM® watsonx Code Assistant™ for Z Refactoring Assistant supports backward data flow slicing only on Read variables present in SQL queries.

Prerequisites

Procedures

Complete the following steps to perform the tutorial:
  1. Launch your Visual Studio Code application.
  2. Select File > Open Folder.
  3. 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.
  4. Open the Visual Studio Code Command Palette by selecting View > Command Palette from the Visual Studio Code menu.
  5. Enter Preferences: Open User Settings in the command palette.
  6. Search for IBM watsonx Code Assistant for Z Refactoring Assistant to locate the extension settings.
  7. Enter the URL of the Refactoring Assistant server as the Refactoring Assistant Server: URL property value.
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. Click the result item LGUPDB01 and then press Enter. A table closure is computed and displayed as the following example.
    The image shows a table closure as an 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.
  13. Click the Action Menu (The image shows the Action Menu icon.) icon on the upper right corner of the LGUPDB01 program node and select the Identify table/file access statements option.
  14. 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.
    The image shows the source code editor when a conditional statament is selected.
  15. In the Key Conditions view, right-click the key condition EXEC SQL (line 475) and then select Slice on variable to new service.
    The image shows the Slice on condition to new service option.
  16. Enter Data Analysis when prompted for a name for the new service.
    The image shows the screenshot when you enter Data Analysis.
  17. Select the variable for which you want to get the data flow analysis. For example, select the DB2-POLICYNUM-INT variable from the list.
    The image shows the search box where you can choose the variable.
  18. 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 image shows the YES or No question for perfoming context sensitive analysis.
  19. 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-only LGUPDB01.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.
    The image shows the The Project Artifacts view.

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.