Unused local variables should be removed


    This rule states that all local variables that are declared but not used within a PowerBuilder code should be removed. This is to ensure that the code is as clean and efficient as possible, and that unnecessary variables are not taking up memory space. Additionally, this rule helps to identify any potential errors or typos that may have been made when declaring variables. By removing unused local variables, the code is easier to read, understand, and debug.

Key Benefits

  • Reduced memory usage: Removing unused local variables helps reduce memory usage by freeing up resources.
  • Cleaner code: Eliminating unused local variables helps keep your code clean and organized.
  • Fewer bugs: Unused variables can lead to unexpected bugs, so removing them can help reduce the chances of running into them.


Non-compliant Code Example

global function string testQueries (string ls_valor)

string ls_sqlsyntax

string query = "Delete FROM employee WHERE emp_id = '" + ls_valor + "'" //Non compliant code (local variable query never used)

string query1 = "Select * FROM Users WHERE Username = '" + ls_valor + "'" //Non compliant code (local variable query1 never used)

ls_sqlsyntax = "Insert INTO employee (emp_id) Values ('" + ls_valor + "')"

ls_valor = runQuery("Update Users Set city = 'city1' WHERE emp_id = '" + ls_valor + "'")


string ls_where

ls_where = "EMPId  = " + ls_valor 

ls_sqlsyntax = "SELECT emp_id FROM employee WHERE " + ls_where 

PREPARE SQLSA FROM :ls_sqlsyntax;

PREPARE SQLSA FROM "Select * FROM employee WHERE city = 'city1' AND state='state1'";

OPEN DYNAMIC my_cursor ;

Return ls_valor
end function
Visual Expert 2024