The wonderful IBM RPGLE programming language:
For file I/O requests in RPG (ie: Chain, Read, Reade, Setll, etc) we can add some options using
(N) – No Lock
(E) – Error Logging
(NE) – No Lock and Error Logging
Writing code in RPG the CHAIN operation code is used to go and get a specific ROW (or record) of data from a file. It returns the first entry that matches the KEY that is being used. In this blog let’s look at what happens when the file(CustomerMasterFile) is defined in our program as an UPDATE file. So, if we wanted to retrieve the Customer information from a Customer Master file (assuming it is keyed by the company name and the customer id number) we might code it simply like this:
CHAIN (Company : CustomerNumber) CustomerMasterFile;
which is basically the same as:
SETLL (Company : CustomerNumber) CustomerMasterFile; READE (Company : CustomerNumber) CustomerMasterFile;
This will get the data that matches the key criteria (Company and Customer) and it will place a record lock to prevent any other programs reading that record while we are exclusively using it. Now, we can add these extender things to add extra functions. So, you might also see this code like this
CHAIN(N) (Company : CustomerNumber) CustomerMasterFile;
And this means – read the data but do not lock the record (obviously this only applies to files defined as update capable). For files defined as UPDATE then records are *locked ready to be updated. Using the (N) extender says – read this update file, treat it like an INPUT file and do not lock the record you are reading.
The trouble is that reading a record with (N) *NOLOCK might still fail if somebody else has already grabbed that record and is exclusively locking it.
So what if we see this:
CHAIN(NE) (Company : CustomerNumber) CustomerMasterFile;
This extends the function to say N=NOLOCK and E=ERRORLOGGING so we are given more information about the CHAIN attempt. Code to use the NE example might look something like this:
IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.
Chain(NE) hang low….
‘device file does not contain an entry for screen size’ after upgrade to IBM i 7.3
Funky IBM i Email Validation Program using SQL Regex
Simple email validation SQL RPG ILE program
Turnover Tip – Checkout to new library retaining source line changes dates
IBM i ACS 5250 EMULATOR FONT – and other ridiculous mumbo jumbo