Chapter Contents

Previous

Next
SAS/MDDB Server Administrator's Guide

Using an MDDB with SAS/AF Software

You can access MDDBs from applications that you create with SAS/AF software by using the MDDB_M class. The following example shows how to use the MDDB_M class to provide data to the SAS/AF Table Editor viewer. For more information on the MDDB_M class, refer to the SAS/MDDB Server online Help.

This SCL code attaches the table editor to an instance of the MDDB_M class and reads in the MDDB that was created in Example 1: Building an MDDB Using the MDDB Procedure.

/*-- load the MDDB_M class to read the mddb data --*/
dcl object tabid;
dcl object mddbid=_new_ sashelp.mddb.mddb_m();

init:
   /*-- get the table editor id --*/
   _frame_._getWidget('obj1', tabid);

   /*-- attach the table editor to this instance of mddb_m --*/
   tabid._attach(mddbid);

   /*-- read in the MDDB you created --*/
   mddbid._setMddbTable('SASUSER.MDDB');


   classlist=makelist();
   /*-- create the class list for your table --*/
   rc = insertc(classlist, 'COUNTRY', -1);
   rc = insertc(classlist, 'PRODUCT', -1);

   /*-- make your table --*/
   mddbid._makeTable(classlist);
   mddbid._addComputedValue('_STATS_', 'Difference');

   /*-- set the SCL that will be run to calculate Difference --*/
   mddbid._setSource('SAMPCOMP.SCL', 'Y');
   rc=rc;
return;

The following SCL code is the SAMPCOMP.SCL program called from the previous code. It calculates the computed values for this example:

_stats_=";;
_anlsys_=";;

init:
   cellist=makelist();
   rc=rc;
   /*-- find out the address of the cell we are computing --*/
   _self_._getCompCellAddress(cellist);

   /*-- if we are computing the difference of ACTUAL/PREDICT sales --*/
   if ( _stats_="Difference" ) then
   do;
      getlist=makelist();
      rc=copylist(cellist, 'y', getlist);

      /*-- setup the address to request SUM values --*/
      rc = setnitemc(getlist, 'SUM', '_STATS_');

      if (_anlsys_='ACTUAL') then
      do;
         _self_._getValues(getlist, aval);
         rc=setnitemc(getlist, 'PREDICT', '_ANLSYS_');
         _self_._getValues(getlist, pval);
      end;
      else
      do;
         _self_._getValues(getlist, pval);
         rc=setnitemc(getlist, 'ACTUAL', '_ANLSYS_');
         _self_._getValues(getlist, aval);
      end;

      /*-- set up the value of the computed cell to contain --*/
      /*-- the difference of predicted sales from actual sales --*/
      value=aval - pval;

      /*-- if we predicted more than we actually sold,   --*/
      /*-- turn that cell to RED so the value stands out --*/
      if (value < 0) then
      /*-- if the difference is negative it will be RED --*/
      _self_._setCellColor(cellist, 'red');
      else
      /*-- if the difference is positive it will be GREEN --*/
      _self_._setCellColor(cellist, 'green');
      rc=dellist(getlist,'Y');
   end;
   rc=dellist(cellist,'Y');
return;

The following display shows the results of running a FRAME entry with the SAS/AF Table Editor Viewer object and gives the results of the above programs:

Table Editor Viewer Frame

[IMAGE]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.