As an RPG III and RPG/400 user, I have always wondered why IBM cannot give us an operation that would search an array starting from any array index and backwards to element 1. This would reduce processing time drastically when there is an application that requires storing unique data values in an array.
Sometimes, I have a maximum array size of 999 (or even 9999) and need to scan through the entire array using LOKUP, in order to find out if the new element to be added already exists in the array, even though I know that most of the array is empty.
One technique I always use in such cases is to fill the array backwards. With maximum array size of 9999, the first element is stored at index 9999, the second at 9998, the third at 9997, and so on.
This way, the LOKUP operation can start from the index which is filled and go to the maximum. It certainly makes a lot of difference in the response time when you do this in an interactive program, such as to stop the user from entering a duplicate item number in order entry.
Of course (tongue in cheek) IBM could make our lives much easier by providing a new opcode (LOKDN maybe?) and do this elegantly.
LATEST COMMENTS
MC Press Online