length libname name $ 8;

INIT:
   libs=makelist(); 
   liblist=makelist();
   logical=instance(loadclass('sashelp.fsp.logical.class'));
   call send(logical, '_get_members_', liblist,
            "TYPE='LIBRARY'");
   * call putlist(liblist, 'liblist=', 0);
   do i=1 to listlen(liblist);
      rc=insertc(libs, getnitemc(getiteml(liblist, i), 'NAME'), -1);
   end;
   call send(logical, '_TERM_');
   rc=dellist(liblist, 'Y');

   members=instance(loadclass('sashelp.fsp.library.class'));
   memlist=makelist();
   dsets=makelist();

   varclass=instance(loadclass('sashelp.fsp.datafile.class'));
   varlist=makelist();
   vars=makelist();
return;

LIBRARY:
   rc=clearlist(dsets);
   rc=clearlist(vars);
   call notify('library', '_get_last_sel_', row, issel, libname);
   if issel then do;
       call send(members, '_setup_', libname);
       call send(members, '_get_members_', memlist,
              "MEMTYPE='DATA VIEW'");
      do i=1 to listlen(memlist);
         rc=insertc(dsets, getnitemc(getiteml(memlist, i), 'MEMNAME'), 
                    -1);
      end;
      call notify('datasets', '_update_');
      call notify('variable', '_update_');
   end;
return;

DATASETS:
   rc=clearlist(vars);
   call notify('datasets', '_get_last_sel_', row, issel, name);
   if issel then do;
      call send(varclass, '_setup_', libname||"."||name);
      call send(varclass, '_get_members_', varlist);
      do i=1 to listlen(varlist);
         rc=insertc(vars, getnitemc(getiteml(varlist, i), 'NAME'), -1);
      end;
      call notify('variable', '_update_');
   end;
return;

TERM:
   call send(members, '_term_');
   call send(varclass, '_term_');
   rc=dellist(libs,'Y');
   rc=dellist(memlist,'Y');
   rc=dellist(dsets,'Y');
   rc=dellist(varlist,'Y');
   rc=dellist(vars,'Y');
return;