/**********************************************************************/


rc=fetchobs(dsid,10);                                     
if (rc=%sysrc(_swnoupd)) then do;                         


                                                          
end;                                                      
else do;                                                  


                                                          
end;                                                      


/**********************************************************************/


   /* DSID     - the data set identifier                  */ 
   /* obs      - the number of the observation to fetch   */ 
   /* maxtime  - the number of seconds to continue trying */ 
   /* maxtries - the maximum number of times to try       */ 
   /*            the fetch                                */ 
   /* modvar   - the variable number of the variable      */ 
   /*            to update                                */ 
   /* modamt   - the amount to modify the variable by     */ 
   /* newval   - the value of the variable after the      */ 
   /*            update                                   */ 
entry dsid obs rc maxtime maxtries 8                         
      optional=modvar modamt newval 8;                       
                                                             
INIT:                                                        
   rc=1;                    /* assume no success          */ 
return;                                                      

MAIN:                                                        
   if (dsid) then do;       /* if good DSID, try lock     */ 
      try=0;                /* have not tried             */ 
      elapse=0;             /* no time trying             */ 
      start=time();         /* starting to try            */ 
                                                             
         /* keep trying until: out of time, used all      */ 
         /* tries, or got lock                            */ 
      do while((elapse0) then                                 
            leave;                                           
         else do;               /* if unable to get lock, */ 
            msg=sysmsg();        /* set the message       */ 
            elapse=time()-start; /* calculate the         */ 
                                 /* elapsed time          */ 
            try=try+1;       /* increment number of tries */ 
            rc=system('\ob call the host WAIT routine\obe ');
         end;                                                
      end;                                                   
   end;                                                      
return;                                                      
                                                             
TERM:
return;  


/**********************************************************************/


call display('getlock.scl', dsid, obsnum, rc, 2, 10,
     custvnum, 1, custno);                                       
  if (rc¬=0) then do;                                            
                                                                 
   
                                                              
end;


/**********************************************************************/


GETROW:                                 
   if (fetchobs(dsid, _currow_ )) then  
      call endtable();                  
return;                                 
                                        
PUTROW:                                 
   rc=fetchobs(dsid, _currow_, 'NOSET');
   rc=update(dsid);                     
return; 


/**********************************************************************/


GETROW:                         
   if (noteid¬=.) then          
      rc=dropnote(dsid, noteid);
                                
   rc=fetchobs(dsid, _currow_); 
                                
   if (rc<0 or rc=%sysrc(_sweof)) then   
      call endtable();                   
   else do;                              
      noteid=note(dsid);                 
      rc=unlock(dsid);                   
   end;                                  
return;                                  
                                         
PUTROW:                                  
   rc=point(dsid, noteid);               
   rc=fetch(dsid, 'NOSET');              
                                         
   if (rc<0 or rc=%sysrc(_swnoupd)) then 
      _msg_=sysmsg();                    
   else if (update(dsid )¬=0) then       
      _msg_=sysmsg();                    
return;                                  


/**********************************************************************/


GETROW:                                   
   rc=fetchobs(dsid, _currow_);           
   if (rc<0 or rc=%sysrc(_sweof)) then    
      call endtable();                    
   else if (rc=%sysrc(_swnoupd)) then do; 
      protect _all_;                      
      _msg_=sysmsg();                     
      end;                                
return;                                   

PUTROW:                     
   if (update(dsid)¬=0) then
      _msg_=sysmsg();       
return;                                                               


/**********************************************************************/


GETROW:                                                      
   if (noteid¬=.) then                                       
      rc=dropnote(dsid, noteid);                             
                                                             
   rc=fetchobs(dsid, _currow_);                              
                                                             
   if (rc<0 or rc=%sysrc(_sweof)) then                       
      call endtable();                                       
   else do;                                                  
      noteid=note(dsid);                                     
      rc=unlock(dsid);                                       
      oldx=x;                                                
      oldy=y;                                                
      oldz=z;                                                
      end;                                                   
return;                                                      
                                                             
PUTROW:                                                      
   rc=point(dsid, noteid);                                   
   rc=fetch(dsid, 'NOSET');                                  
   if (rc<0 or rc=%sysrc(_swnoupd)) then                     
      _msg_=sysmsg();                                        
   else if (oldx¬=getvarn(dsid, xvnum) or                    
            oldy¬=getvarn(dsid, yvnum) or                    
            oldz¬=getvarc(dsid, zvnum)) then do;             
                                                             
             
                                                
   end;                                                      
   else if (update(dsid)¬=0) then
      _msg_=sysmsg();            
 return;                         


/**********************************************************************/