%LOOKUPxx

640 Views


%LOOKUPxx (Look Up an Array Element)

Unlike the LOOKUP operation code, %LOOKUP applies only to arrays. 

%LOOKUP
An exact match.
%LOOKUPLT
The value that is closest to arg but less than arg.
%LOOKUPLE
An exact match, or the value that is closest to arg but less than arg.
%LOOKUPGT
The value that is closest to arg but greater than arg.
%LOOKUPGE
An exact match, or the value that is closest to arg but greater than arg.

If no value matches the specified condition, zero is returned. The value returned is in unsigned integer format (type U).

The search starts at index start_index and continues for number_of_elems elements. By default, the entire array is searched.

The second parameter can be a scalar array in the form ARRAY_NAME. For %LOOKUP, it can also be a keyed array data structure in the form ARRAY_DS_NAME(*).SUBFIELD_NAME.

For %LOOKUPLT, %LOOKUPLE, %LOOKUPGT, and %LOOKUPGE, the array must be defined with keyword ASCEND or DESCEND.

/FREE
   arr(1) = 'Cornwall';
   arr(2) = 'Kingston';
   arr(3) = 'London';
   arr(4) = 'Paris';
   arr(5) = 'Scarborough';
   arr(6) = 'York';

   n = %LOOKUP('Paris':arr);
   // n = 4

   n = %LOOKUP('Thunder Bay':arr);
   // n = 0 (not found)

   n = %LOOKUP('Kingston':arr:3);
   // n = 0 (not found after start index)

   n = %LOOKUPLE('Paris':arr);
   // n = 4

   n = %LOOKUPLE('Milton':arr);
   // n = 3

   n = %LOOKUPGT('Sudbury':arr);
   // n = 6

   n = %LOOKUPGT('Yorks':arr:2:4);
   // n = 0 (not found between elements 2 and 5)
 /END-FREE

%loopkup - ibm.com

When %LOOKUP *NE LOOKUP: rpgpgm.com

Post Comments