?
Solved

CL - CHKRCDLCK command on as/400 i series

Posted on 2005-03-23
13
Medium Priority
?
2,146 Views
Last Modified: 2008-01-09
Hello experts -

Could someone please provide me with some background information (or a place where I can find it) on the CHKRCDLCK (check for record lock) command (CL language) on an as/400 i series platform?  I am relatively new to the CL language and have not been able to find much about this.  

Particularly, I am looking for the syntax of this command and how it handles/throws any errors.

Thanks!
0
Comment
Question by:mossman242
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +1
13 Comments
 
LVL 14

Expert Comment

by:daveslater
ID: 13612846
Hi
the command does not have any parms.
it is simply there to see if a job routing step holds a lock on any file.

escape message CPF321F is issued if the job has a record lock.

dave
0
 
LVL 14

Expert Comment

by:daveslater
ID: 13612873
Ps
a lot of people thought great I can find out if a record is locked before i try to get it for update - but no it does not do that.

Dave

0
 
LVL 14

Expert Comment

by:daveslater
ID: 13612921
pps
to check a command sign on to the 400
enter then command
CHKRCDLCK
press F4 to prompt
Press F1 for help then on most occasions press F2 for extended help - the messages are usually at the bottom of the help

Dave
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:mossman242
ID: 13613309
So are you saying that if I wanted to check to see if a record was available for an update before I actually tried to perform the update, that this wouldn't be possible?

Basically, what is happening is that a dts package runs (usually takes about 15 minutes), then once the DTS package is done writing to the file, the CL code will compare that file to a file on another i series server and update it with any changes.  Now, ideally the DTS package could be tweaked to perform this automatically without ever having to go to the CL code, but however upper management does not want to do this at the moment.  Our CL code is timed to run approx 1500s (25 minutes) after the DTS package begins.  Now for whatever reason, sometimes the DTS package does not finish within the 25 minutes and so therefore we lose records.  I want to loop through a check record or object lock command every two minutes or so to see if the file is still being written to, and if it is not (aka the DTS is done) then begin the process of comparing the two files and updating as needed.

Is the CHKRCDLCK command the best to use for this or is the CHKOBJ command better (and if so how would you recommend going about using it).  Thanks!
0
 
LVL 14

Assisted Solution

by:daveslater
daveslater earned 1000 total points
ID: 13615281
Hi
have you thought of the ALCOBJ command.
you can then see if the file is in use.
If that is not sufficient then there will be an API to to the trick.


Dave
0
 
LVL 14

Expert Comment

by:daveslater
ID: 13616848
Hi
Surly the easiest way to do this is submit both jobs into a single stream jobq, that way when the “DTS package” job finishes your job will kick-in.

Dave
0
 
LVL 27

Expert Comment

by:tliotta
ID: 13618265
mossman242:

Dave's given the two elements that seem best suited. Use a single-threaded job queue for the two jobs so that the first job _must_ complete before the second job starts. And in your CL, use ALCOBJ to test whether other jobs have locks as well as to establish your own lock to prevent a third job from grabbing the file.

I generally try a *EXCL lock to verify that the object (your file) is completely available right at the start. Once that lock's established, I set a second less restrictive lock, and then release the *EXCL lock. The second lock stays until the job finishes and is what prevents activity from other jobs. The second lock often doesn't need to be *EXCL; it could be less restrictive if other jobs are allowed to read the file but not update it. In your case, you can probably use just a single *EXCL lock.

The combination of job queue _plus_ lock protect somewhat from unintentionally running the second job in the wrong job queue.

Tom
0
 
LVL 9

Accepted Solution

by:
ShadowProgrammer earned 1000 total points
ID: 13619762
my six pence worth...

I would go with the exclusive ALCOBJ,

in your CL you would code something like...
................
ALCOBJ OBJ((&LIB/&OBJ &TYPE *EXCL &MEMBER))  
/* Monitor for any error - unable to allocate object - still being written to */
MONMSG CPF0000 EXEC(DO)
    DLYJOB  (120)     /* delay job for 120 seconds (=2 mins) */
   GOTO LOOP
ENDDO
.................

The MONMSG CPF0000 traps any error message, if you wish you could add speciifc messages.
Look at the extended help for any command and you should find a list of errors you can monitor for....  in ALCOBJ these are...
CPF1002     Cannot allocate object &1.                    
CPF1040     Maximum number of objects allocated on system.
CPF1085     Objects not allocated.                        

So you could if you wanted...

........................
ALCOBJ OBJ((&LIB/&OBJ &TYPE *EXCL &MEMBER))
/* monitor for certain messages to do one thing */
MONMSG (CPF1002 CPF1085) EXEC(DO)
    DLYJOB  (120)     /* delay job for 120 seconds */
   GOTO LOOP
ENDDO
/* monitor for certain messages to do another thing */
MONMSG CPF1040 EXEC(DO)
    SNDUSRMSG MSG('Message Text') TOMSGQ(*SYSOPR)
   GOTO SOMEWHERE
ENDDO
/* monitor for ALL other error messages to do another thing */
MONMSG CPF0000 EXEC(DO)
    SNDUSRMSG MSG('Some General Error has happended') TOMSGQ(*SYSOPR)
   GOTO SOMEWHEREELSE
ENDDO
.........................

You can also program a MONMSG CPF0000 without an EXEC parameter, this ignores any specified errors and continues processing with the next statement.


Tony.
0
 
LVL 14

Expert Comment

by:daveslater
ID: 13621953
Hi
here is a command that will do what you wanted the system to do.

==================
Name: RTVLCKCNT
Type : CMD
Source File: QCMDSRC
==================

/******************************************************************/                
/* COMPILE OPTIONS                                                */                
/*   ALLOW(*BPGM                                                  */                
/*         *IPGM                                                  */                
/*         *BREXX                                                 */                
/*         *IREXX                                                 */                
/*         *BMOD                                                  */                
/*         *IMOD)                                                 */                
/******************************************************************/                
             CMD        PROMPT('Retrieve Lock Count')                              
                                                                                   
/* Nbr records */                                                                  
             PARM       KWD(NBRLCKS) TYPE(*DEC) RTNVAL(*YES) MIN(1) +              
                          PROMPT('Number of Records locked')                        
                                                                                   
/* File Name Prompt */                                                              
             PARM       KWD(FILE) TYPE(FILEPMT) MIN(1) PROMPT('File +              
                          Name')                                                    
/* Member Name */                                                          
             PARM       KWD(MBR) TYPE(*NAME) LEN(10) DFT(*FIRST) +        
                          SPCVAL((*FIRST)) PROMPT('Member')                
                                                                           
 FILEPMT:    QUAL       TYPE(*NAME) LEN(10)                                
             QUAL       TYPE(*NAME) LEN(10) DFT(*LIBL) +                  
                          SPCVAL((*LIBL) (*CURLIB)) PROMPT('Library')      

==================
Name: RTVLCKCNT
Type : CLLE
Source File: QCLSRC
==================
/* check for a record lock in a file */                                
             PGM        PARM(&RECORDS &FILLIB &MBR)                    
                                                                       
             DCL        VAR(&RTN) TYPE(*CHAR) LEN(16)                  
             DCL        VAR(&RTNLEN) TYPE(*CHAR) LEN(4)                
             DCL        VAR(&FORMAT) TYPE(*CHAR) LEN(8) +              
                        VALUE('RRCD0100')                              
             DCL        VAR(&FILLIB) TYPE(*CHAR) LEN(20)              
             DCL        VAR(&MBR) TYPE(*CHAR) LEN(10)                  
             DCL        VAR(&RRN) TYPE(*CHAR) LEN(4)                  
             DCL        VAR(&ERROR) TYPE(*CHAR) LEN(15)                
/* Work fields */                                                      
             DCL        VAR(&Records) TYPE(*DEC) LEN(15 5)            
             DCL        VAR(&BYTE4) TYPE(*CHAR) LEN(4)                
             DCL        VAR(&Msgid) TYPE(*CHAR) LEN(7)                
                                                                       
/* set input parms for API call */                                    
             CHGVAR     %BIN(&RTNLEN) VALUE(16)                        
             CHGVAR     %BIN(&RRN) VALUE(0)                            
                                                                               
/* CALL API */                                                                  
             CALL       PGM(QDBRRCDL) PARM(&RTN &RTNLEN &FORMAT +              
                          &FILLIB &MBR &RRN &ERROR)                            
/* Check for error */                                                          
             CHGVAR     VAR(&MSGID) VALUE(%SST(&ERROR 9 7))                    
             IF         COND(&MSGID *NE ' ') THEN(SNDPGMMSG +                  
                          MSGID(CPF9898) MSGF(QCPFMSG) +                        
                          MSGDTA('Message ' || &MSGID || ' issued +            
                          by API') MSGTYPE(*ESCAPE))                            
                                                                               
/* Set return value */                                                          
             CHGVAR     VAR(&BYTE4) VALUE(&RTN)                                
             CHGVAR     VAR(&Records) VALUE(%BIN(&byte4))                      
                                                                               
endpgm                                                                          





================================================

to use simply

PGM                                                              
                                                                 
             DCL        VAR(&NBR) TYPE(*DEC) LEN(15 5)          
                                                                 
             RTVLCKCNT  NBRLCKS(&NBR) FILE(Lib/File)        
             MONMSG     MSGID(CPF9898)                          
   
                                                               
ENDPGM                                                          


I have included this cause I got a bit board and it may be useful for some one else and I like programming API's

I would use the jobq or alcobj as a model 800 is fast and it could have released a record but not got the next one when you run this command so the nbr of locks would be 0.

have fun

Dave
0
 
LVL 9

Expert Comment

by:ShadowProgrammer
ID: 13651612
The reason I went for the object lock is I have assumed that when mossman242 says "then once the DTS package is done writing to the file" he means that it is writing out records (as opposed to updating records) and there is no lock on written records.

If the DTS was updating records, you also run the risk of catching the program between updating a record and reading the next record and finding no locked records even though the program hasn't finished (small risk - but possible!!).

I think it would be much safer to check the object lock.

Tony.
0
 
LVL 14

Expert Comment

by:daveslater
ID: 13651950
Hi  ShadowProgrammer
that is basically what I have said at then end on the code example. The command and program was just a bit of fun to write and may be useful to someone else.

I WOULD GO FOR THE ALCOBJ OPTION


Dave
0
 
LVL 27

Expert Comment

by:tliotta
ID: 13656858
Object locks provide a program a way to make decisions, but what decision needs to be made? Should it be program termination if the lock fails? Should it be a loop for some indeterminate time? Other?

And once the lock is established, will there ever be any other processes that might need similar logic? Who knows what will be developed next month?

Combining the lock _plus_ a single-threaded jobq gives the operations people the best of both worlds. Under normal circumstances, there won't be a conflict -- Job1 will be finished before Job2 starts. Only under unforeseen circumstances will establishing the lock fail -- the programmed response can be unambiguous; the operations staff action can therefore be unambiguous.

Tom
0
 

Author Comment

by:mossman242
ID: 13661956
Ok, sorry for the delay in getting back to everyone.  I was temporarily moved to another emergency project that came up.  I ended up using the alcobj command, in conjunction with a dlyjob.  That seemed to work for me.

Thanks everyone for all of your help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Summer 2017 Scholarship Winners have been announced!
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question