%{ showchildren.i recursive function to display category navigation Invoked as: @show_children (ctable, cgmenbr, parent, mycat, "0", "0") Parameters (global variables) ctable (in) table of category info, provided by fill_ctable() parent (in) display child categories of this parent ref # mycat (in) targeted category -- show with arrow cgmenbr (in) merchant number "0"s provides placeholder for local variables i and x. Purpose: Provide a recursive function to display the exploded left-bar navigation tree of the product categories. How it works: The pseudo-code version (in a language with params and local vars) looks like: function show_children (table, parent, mycat) { for all x, where parent_of(x) == parent { display category x if x is any_parent_of (mycat) show_children (table, x, mycat) } } Notes & Bugs: This code requires Net.Data version 6.1.1.1; earlier versions do not properly support parameters and recursion. Since Net.Data does not support any direct definition of local variables, they must be "faked" by supplying non-functional arguments which can then be used as local variables. Hence the trailing "0"s, which become i and x, respectively. History of revisions: +CR 11/13/00 11:14 New script. +CR 11/26/00 11:14 Updated for Net.Data 6.1.1.1 support. ========================================================================%} %{---any_parent_of() is a recursive service function, used only by show_children(), that determines if x is the same as cat, a parent of cat, a g'parent of cat... etc. %} %macro_function any_parent_of (OUT success, IN ctable, IN x, IN cat) { %if (x == cat) @dtw_assign (success, "1") %else %{---returns index cx of cat in ctable. %} @ctable_index (cx, ctable, cat, "0") %{---if ctable[cx,4] == x return true %} %if (@dtw_tb_rgetv (ctable, cx, "4") == x) @dtw_assign (success, "1") %{---elif ctable[cx,4] == "" return false %} %elif (@dtw_tb_rgetv (ctable, cx, "4") == "") @dtw_assign (success, "0") %{---else cat = ctable[cx, 1]; return any_parent_of() %} %else @any_parent_of (success, ctable, x, @dtw_tb_rgetv (ctable, cx, "4")) %endif %endif %} %macro_function show_children (IN ctable, IN cgmenbr, IN parent, IN mycat, IN i, IN x) { %{---Indentation of "exploded" view is handled by tables within tables... %} %{---For x, in children of parent... %} @dtw_assign (i, "1") %while (i <= @dtw_tb_rrows(ctable)) { %if (@dtw_tb_rgetv (ctable, i, "4") == parent) @dtw_assign (x, @dtw_tb_rgetv (ctable, i, "1")) %{---Display category x. %} %if (x == mycat) %else %endif @dtw_assign (text, @dtw_tb_rgetv(ctable, i, "2")) %endif @dtw_add (i, "1", i) %}
 >  $(text) %{---If x is any parent of mycat, call show_children recursively on x. %} @any_parent_of (success, ctable, x, mycat) %if (success == "1") @show_children (ctable, cgmenbr, x, mycat, "0", "0") %endif
%}