Setll

797 Views


SETLL (Set Lower Limit)

The SETLL operation positions a file at the next record that has a key or relative record number that is greater than or equal to the search argument.  The SETLL operation does not apply the lock. 

If we just want to check for the existence of the record, then SETLL is better option as CHAIN will put an extra overhead in copying the data to input buffer

Search-arg, must be the key or relative record number used to retrieve the record. It can be a KLIST name, a list of values, or %KDS.

%KDS(data-structure-name{:num-keys})

Setll %Kds( Key_DataStructure : Number_of_keys ) FileName;  
 If %Equal(FileName);                                    
    success = '1' ;                               
 Else;                                                   
    success = '0' ;                              
 Endif;  

-----------------------

SetLL %kds(Key_DS) FileName;                                                 
 If %Equal(FileName);                                    
    success = '1' ;                               
 Else;                                                   
    success = '0' ;                              
 Endif;
-----------------------

Setll %Kds( Key_DS : 1 ) FileName; 
If %Equal(FileName);                    
   success = '1';                
EndIf;

-----------------------     

Setll (Field1 : Field 2) FileName;
Read FileName;                              
Dow Not %EOF(FileName);  
     
     //Some Logic
                  
     Read FileName;   
 
Enddo;          
                                                      

 

               Setll (Profile:Type:Num) FileName;
               If %equal(FileName);
                Reade (Profile:Type:Num) FileName;
                DOW not %EOF(FileName);
                   If (status= 'A');
                      Eval  Field1 = Num;
                      Eval  Field2 = UserName ;
                      Eval  Field3 = SYSDAT7;
                      Eval  Field4 = SysTime  ;
                      Eval  Field5 = PgmName  ;
                      update FileName;
                   ENDIF;
                   reade (Profile:Type:Num) FileName;
                Enddo 
               EndIf

The Key data structure, %KDS, has to be defined below. The critical part is the LIKEREC keyword, it contains the name of the file's record format followed by *KEY. This means that the data structure only contains the key fields of the file.

01  dcl-f TESTFILE keyed ;

02  dcl-ds KeyTestfile likerec(TESTFILER:*key) ;

03  KeyTestfile.FLD001 = '1' ;
04  KeyTestfile.FLD002 = '2' ;
05  KeyTestfile.FLD003 = '3' ;

06  setll%kds(KeyTestfile) TESTFILER ;

Using SetLL and %Equal, we can check for existence of a record in a file without using Chain and Read. 

RPGPGM: Setll %kds

Post Comments