PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Join the forum, it's quick and easy

PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).
PMS Information Systems
Would you like to react to this message? Create an account in a few clicks or log in to continue.

LOKUP opcode Vs %LOOKUP BIF

Go down

LOKUP opcode Vs %LOOKUP BIF Empty LOKUP opcode Vs %LOOKUP BIF

Post  maran Tue Jan 24, 2012 7:53 pm

The %LookUp built-in function is more than just a simple replacement for the LOOKUP operation code to allow use in /Free format logic. It offers the option of supercharging the performance of an array search operation.

Let's cover the basics first.

%LOOKUP( searchfor : array {: startindex {: numelems}})

The first parameter is the argument you're searching for, and the second parameter the name of the array where you're looking; i.e., what would have been specified in Factor 1 and 2 of the LOOKUP op code, respectively. The optional third parameter is the starting index for the search, i.e., what you could have specified as an index on the Factor 2 array.

The fourth parameter is the number of elements to search. This option didn't exist in the LOOKUP op code, so this represents the first enhancement offered by %LookUp.


Perhaps the best feature of %LookUp when compared with the op code is the ability to use a binary search rather than the much slower linear search when the data in the array is in sequence (ascending or descending).

The LookUp operation code always performs a linear search, even if the array is sequenced.


A mistake that is made more commonly than you might think is to specify Ascend or Descend on an array even when the values are not in sequence. This didn't cause a problem for the LookUp operation code when searching for an equal match, but it would cause a problem for %LookUp's binary search.
maran
maran
Admin

Posts : 442
Join date : 2009-07-24

https://pmsinformationsystem.forumotion.net

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum