Ü  UNLOCK (Unlock Data Area/Unlock Record Lock in a file)

  I.            Unlock Data Area

·         This opcode is used to unlock the dataarea.

Factor 1

Op-code

Factor 2

Result Field

Resulting Indicators

       HI                            LO                      EQ

UNLOCK(E)

Data area name

 

 

Error

 

 

Example


Columns . . . :    6  76            Edit                           AMINEM/PRJ1
 SEU==>                                                                  GENACC
 FMT C  CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
        *************** Beginning of data *************************************
0004.00 C     *DTAARA       DEFINE                  DA               12        
0005.00 C     *ENTRY        PLIST                                               
0006.00 C                   PARM                    A1               12        
0007.00 C     *LOCK         IN        DA                                       
0008.00 C                   MOVEL     DA            C                12        
0009.00 C                   MOVEL     *ZEROS        I                12 0      
0010.00 C                   EVAL      I=%INT(C)                                
0011.00 C                   ADD       1             I                          
0012.00 C                   EVAL      C=%CHAR(I)                               
0013.00 C                   MOVEL     C             DA                         
0015.00 C                   MOVEL     C             A1                         
0016.00 C                   OUT       DA                                       
0017.00 C                   UNLOCK    DA                                       
0019.00 C                   SETON                                        LR    
0020.00 C                   return                                             
        ****************** End of data ****************************************

 

Below is the dataarea used in the program “DA”:

                               Display Data Area                               
                                                             System:   SYSTEM09
 Data area . . . . . . . :   DA                                              
   Library . . . . . . . :     QGPL                                            
 Type  . . . . . . . . . :   *CHAR                                             
 Length  . . . . . . . . :   30                                                
 Text  . . . . . . . . . :                                                     
                                                                               
            Value                                                              
 Offset      *...+....1....+....2....+....3....+....4....+....5                
     0      '100000000001'                                   
 
 
                                                                               
                                                                               
 F3=Exit   F12=Cancel  

                         

 

OUTPUT

On each call of this program, auto-generation of number will happen.

The generated number will be updated to the dataarea.

 

 

 

 

II.            Unlock Record Lock in a file

§   The UNLOCK operation makes the current locked record to be unlocked for an update operation on a file.  

§   The current locked is unlocked on subsequent read operation i.e. when we read another record the previous read operation record lock will be unlocked.

§  The current locked record is automatically unlocked when the UPDATE operation performed on the record is over.

 

Example

 

§  There is one physical file MASTER with the record as below:

 

 
 ORG CODE  ACC NUMBER    CURRENCY  OPEN DATE  PARTY NUM
    191    A00000000002    USD      20120605  P00000000002
    191    A00000000004    EUR       1072012  P00000000004
    191    A00000000005    USD       6072011  P00000000005
    192    A00000000006    USD       9082012  P00000000006
    191    A00000000007    EUR       9082000  P00000000007
    191    A00000000008    USD       9082007  P00000000008
    192    A00000000009    TRY       6092000  P00000000009

 

 

 

§  We have created 2 programs OP_UPDATE1 & OP_UPDATE2.

 


Columns . . . :    6  80               Edit                                  AMINEM/QRPGLESRC
SEU==>                                                                             OP_UPDATE1
FMT H  HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 HOPTION(*NODEBUGIO)                                                             130131
0002.00 FMASTER    UF A E           K DISK    USROPN                                    130130
0009.00  *                                                                              130124
0010.00 C                   OPEN      MASTER                                            130130
0011.00 C     *LOVAL        SETLL     REC1                                              130131
0012.00 C                   READ      MASTER                                            130131
0013.00 C                   DOW       NOT %EOF(MASTER)                                  130131
0014.00 C                   IF        ACC='A00000000002'                                130131
0015.00 C                   EVAL      CCY='USD'                                         130131
0016.00 C                   UPDATE    REC1                                              130130
0017.00 C                   ELSE                                                        130131
0018.00 C                   UNLOCK    MASTER                                            130131
0019.00 C                   ENDIF                                                       130131
0020.00 C                   READ      MASTER                                            130131
0021.00 C                   ENDDO                                                       130131
0023.00  *                                                                              130123
0024.00 C                   SETON                                        LR             130123
****************** End of data *******************************************************


 

 

 


Columns . . . :    6  80               Edit                                 AMINEM/QRPGLESRC
SEU==>                                                                            OP_UPDATE2
FMT H  HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 HOPTION(*NODEBUGIO)                                                             130131
0002.00 FMASTER    UF A E           K DISK    USROPN                                    130130
0003.00                                                                                 130121
0004.00 C                   OPEN      MASTER                                            130130
0005.00 C     *LOVAL        SETLL     REC1                                              130131
0006.00 C                   READ      MASTER                                            130131
0007.00 C                   DOW       NOT %EOF(MASTER)                                  130131
0008.00 C                   IF        CCY='EUR'                                         130131
0009.00 C                   EVAL      ACCSTS=4                                          130131
0010.00 C                   UPDATE    REC1                                              130130
0013.00 C                   ENDIF                                                       130131
0014.00 C                   READ      MASTER                                            130131
0015.00 C                   ENDDO                                                       130131
0016.00                                                                                 130131
0017.00 C                   SETON                                        LR             130123
****************** End of data *******************************************************


                  

§  Here both the programs are trying to update the same file. Suppose the first program has read one record from the physical file ‘MASTER’.

§  There will be lock on the file once is READ operation is performed on the file and the lock won’t be released until any other READ or UPDATE or UNLOCK is performed.

§  Now 2nd program tries to access the same record to update it. But it gets an error message “Unable to allocate a record in file MASTER” since that record is allocated to the first program.

§  Here 2nd program has to wait for the 1st program to release the lock on that record.

§  To release the lock 1st program uses UNLOCK if the record it has read is of no relevance.











User Comments:



Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy