How Used Report

This report shows a snippet from each line of code where a database field is used. For example, a how-used report for sports2000.customer.custnum might show:

s2k\gui\bcust.w
define temp-table ...  like Customer.CustNum validate

s2k\gui\dcust.w
define temp-table ...  like Customer.CustNum validate

s2k\gui\dcust_cl.w
define temp-table ...  like Customer.CustNum validate

s2k\gui\orderreport.p
format ...  Customer.CustNum column-label "Cust-Num" format ">>>>9"
display ...  Customer.CustNum

s2k\gui\vcust.w
define temp-table ...  like Customer.CustNum validate

s2k\gui\vcust2.w
define temp-table ...  like Customer.CustNum validate

s2k\gui\vordlne2.w
find ...  customer.custnum eq order.custnum
find ...  customer.custnum eq order.custnum

s2k\gui\worder.w
define variable ...  like customer.custnum

See this WebSVN link for the full source.

This report takes a ProRefactor Field object (reportField) as a parameter, and then walks the syntax tree for each parse unit passed to it, starting at the topmost JPNode node in the tree. It checks to see if each node is a FieldRefNode referencing the reportField we are interested in:

private void walkTree(JPNode node) throws Exception {
      if (node==null) return;
      boolean match = false;
      if (node instanceof FieldRefNode) {
           Symbol symbol = node.getSymbol();
           if (        symbol!=null
               && symbol instanceof FieldBuffer
               && ((FieldBuffer)symbol).getField() == reportField
               )
               match = true;
      }
      if (match) {
           printReference(node);
      } else {
           walkTree(node.firstChild());
      }
      walkTree(node.nextSibling());
}

In printReference(), the beginning of the statement is found, and the first one node or two (DISPLAY, ASSIGN, etc.) is displayed, followed by the ellipses "...". The parent of the FieldRefNode is then found, and everything below it is then printed (including, of course, the FieldRefNode itself).

If you are new to syntax trees, then you might want to have a look at joanju.com/dist/docs/parse_trees to get an idea why print2() has to take an extra step to make sure that binary operators are printed in line.