home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / busi / smii026.zip / SMII026.TXT
Text File  |  1990-03-17  |  8KB  |  159 lines

  1.                              INFORMIX SOFTWARE, INC.
  2.                                    SmartWareII
  3.                          Technical Support Bulletin 026
  4.           
  5.           
  6.           Subject:  Predicting  Breakpoints in Database Reports  using
  7.                     User-defined Functions in SmartWareII
  8.           
  9.           Date:     February 22, 1990
  10.           
  11.           
  12.           With  SmartWareII's  ability  to place calculations  in  the
  13.           Database Report Generator TABLE TITLES and BREAKPOINT result
  14.           line  label,  there  is  a need to  determine  table  report
  15.           breakpoints through the use of user-defined functions.  This
  16.           is accomplished using this Technical Support Bulletin.  This
  17.           document  can be used along with Technical Support  Bulletin
  18.           18   for  generating  Database  Reports  using  user-defined
  19.           functions.
  20.           
  21.           User-defined  functions  are  developed  with  SmartWareII's
  22.           Project  Development Language.   The user-defined  functions
  23.           are made available using the REMEMBER LOAD command.
  24.           
  25.           public clear_grand(), fetch(1), new_break(1)
  26.           public $break_field, $break_point, counter, page_number
  27.           
  28.           function clear_grand()
  29.                counter = 0
  30.                return blank
  31.           end function
  32.           
  33.           function fetch($sent_field)
  34.           
  35.                $break_field = indirect($sent_field)
  36.                return blank
  37.           
  38.           end function
  39.           
  40.           function new_break($send_break)
  41.           
  42.                $break_point = indirect($send_break)
  43.                if $break_field <> $break_point
  44.                     counter = counter + 1
  45.                     page_number = str(counter)
  46.                     counter = 0
  47.                     return "Page"&page_number
  48.                else
  49.                     counter = counter + 1
  50.                     page_number = str(counter)
  51.                     return "Page"&page_number
  52.                end if
  53.           
  54.           end function
  55.  
  56.           The  function clear_totals() serves as a way of clearing the
  57.           variables  back  to a zero value.   This function should  be
  58.           placed  in a defined GRAND-TOTAL in the Table.   By  placing
  59.           the function in the GRAND-TOTAL section,  the Report routine
  60.           evaluates  the  function at the beginning of the report  and
  61.           clears counter.
  62.           
  63.           This  is accomplished by placing the function in the  Result
  64.           Line  Label,  where  the word GRAND TOTAL normally  appears.
  65.           After clearing the variables,  the functions can be used for
  66.           another  Report  routine.  Any  SmartWare  or  user  defined
  67.           function  can  be  placed  in the result  line  label  of  a
  68.           BREAKPOINT or GRAND-TOTAL.  
  69.           
  70.           This  brings up an interesting point.   The Report Generator
  71.           allows  for  calculations to be placed in a  Grand-Total  or
  72.           Breakpoint  result  line  label.    These  calculations  are
  73.           evaluated  at  the  beginning of the  current  action.   The
  74.           results  are then printed at the end of the current  action. 
  75.           The  results are based on the first record of the action and
  76.           not all records in the break.
  77.           
  78.           Fortunately,  Table  Titles  allows for calculations  to  be
  79.           placed   on  both  the  Headings  and  Footings.    If   the
  80.           calculation  is placed in the Footing lines by using an  "="
  81.           sign as the first character, it will be evaluated at the end
  82.           of  each  page  of  the report.   This is  the  theory  that
  83.           operates  Technical Support Bulletin 18.   Technical Support
  84.           Bulletin  18 develops user-defined functions to provide  for
  85.           running and cumulative totals.
  86.           
  87.           This  Technical  Support  Bulletin develops  functions  that
  88.           allow  for  determining a new breakpoint value.   This  then
  89.           allows  the user to develop function libraries that  provide
  90.           results based on the breakpoint.  These calculations use the
  91.           ability that Table Titles allow for calculations.
  92.           
  93.           The  function  fetch(1)  should be defined as  a  calculated
  94.           column and should pass to the function another field that is
  95.           present in the report.   The function has been prototyped to
  96.           receive  one  field,  or  value by declaring in  the  PUBLIC
  97.           statement one argument.  The field passed to fetch(1) should
  98.           be the breakpoint field.
  99.           
  100.           The  calculation  should  be developed using  the  following
  101.           syntax
  102.           
  103.                fetch("[breakpoint_field]")
  104.           
  105.  
  106.           Notice that the calculation sends the field title as text to
  107.           the  function.   This  allows the function to determine  the
  108.           current value of the field.   The indirect() function in the
  109.           fetch(1)  function  will calculate the current  break  field
  110.           value.
  111.           
  112.           The  function  new_break(1)  should be placed in  the  TABLE
  113.           TITLES  section  of the Report.   While the desirable  place
  114.           would  be  in  a FORM CALCULATION field or the  result  line
  115.           label of the breakpoint,  it is not evaluated in the desired
  116.           order.    The   FORM   portion   of  a   FORM-TABLE   or   a
  117.           FORM-TABLE-FORM  is  evaluated on the first record and  then
  118.           the  table records are evaluated and processed.   The  final
  119.           page consisting of the FORM and TABLE is  then printed.
  120.           
  121.           The  calculation  should  be developed using  the  following
  122.           syntax
  123.           
  124.           Footings:
  125.           Line 1:   =new_break("[breakpoint_field]")
  126.           
  127.           In the user-defined example above, page numbers are returned
  128.           based on the breakpoint value.   Each breakpoint has its own
  129.           page numbering scheme.  New_break(1) returns an alphanumeric
  130.           result  that  includes the static text Page and  a  variable
  131.           page number from the variables counter and page_number.
  132.           
  133.           The  function  new_break(1) is evaluated at the end of  each
  134.           physical  page  that  the table produces.   If a  new  break
  135.           record  is  accessed  when  this  function  is  called,  the
  136.           variable break_point will reflect the new break value.
  137.           
  138.           The   function  new_break(1)  can  be  combined  with  other
  139.           user-defined functions to calculate information based on the
  140.           break  information.   The IF statement determines when a new
  141.           break  is taking effect.   The THEN condition,  or when  the
  142.           condition  is  TRUE,  indicates  a new break  condition  has
  143.           occurred.   Any  function library can be called or  combined
  144.           with  the  RETURN  command within the THEN part  of  the  IF
  145.           statement.
  146.           
  147.           The  ELSE  part of the IF statement contains  the  condition
  148.           when  the breakpoint has not changed.   At this  point,  the
  149.           report is still under the current break value.  Any function
  150.           library  can  be called or combined with the RETURN  command
  151.           within the ELSE part of the IF statement.
  152.           
  153.           Informix  SmartWareII  Technical  Support  hopes  that  this
  154.           Technical   Support   Bulletin  is  useful  to   SmartWareII
  155.           end-users.   While these supplied functions are simple, they
  156.           represent   a  starting  place  for  developing  programming
  157.           structures   and  techniques  for  applying  user  developed
  158.           applications in SmartWare II commands.
  159.