public Var findVariable(String name) {
    Var var;
    String name1 = name.toUpperCase();
    String name1a = null;
    String name2 = null;
    Scope cur = exec.currentScope;
    Package pack;
    Package packCallContext = exec.getPackageCallContext();
    ArrayList<String> qualified = exec.meta.splitIdentifier(name);
    if (qualified != null) {
      name1 = qualified.get(0).toUpperCase();
      name2 = qualified.get(1).toUpperCase();
      pack = findPackage(name1);
      if (pack != null) {        
        var = pack.findVariable(name2);
        if (var != null) {
          return var;
        }
      }
    }    
    if (name1.startsWith(":")) {
      name1a = name1.substring(1);
    }    
    while (cur != null) {
      var = findVariable(cur.vars, name1);
      if (var == null && name1a != null) {
        var = findVariable(cur.vars, name1a);
      }
      if (var == null && packCallContext != null) {
        var = packCallContext.findVariable(name1);
      }
      if (var != null) {
        return var;
      }
      if (cur.type == Scope.Type.ROUTINE) {
        cur = exec.globalScope;
      }
      else {
        cur = cur.parent;
      }
    }    
    return null;
  }
Find an existing variable by name
hplsql/src/main/java/org/apache/hive/hplsql/Exec.java