Lesson 2 · July 2026 RPG Enhancements
RPG %LOOKUPNE: Find the First Value That Does Not Match
Learn how to use RPG %LOOKUPNE to find the first array element that is not equal to a search value, with short practical examples.
%LOOKUPNE helps RPG developers find the first array element that is not equal to a search value.
Most RPG developers are already familiar with %LOOKUP.
It helps find a matching value in an array.
%LOOKUPNE is different.
It helps find the first value that does not match.
That may sound small, but it is useful when you want to detect where a group of values changes, where default values stop, or where an array contains the first exception.
What changed?
RPG now includes %LOOKUPNE.
Conceptually:
position = %lookupne(search-value : array);
It returns the array index of the first element that is not equal to the search value.
If no different value is found, the result is zero.
Simple way to remember
%LOOKUP finds the first matching value. %LOOKUPNE finds the first value that does not match.
Simple example
Suppose an array contains order status values.
**free
ctl-opt dftactgrp(*no);
dcl-s statuses char(1) dim(5);
dcl-s pos int(10);
statuses(1) = 'P';
statuses(2) = 'P';
statuses(3) = 'P';
statuses(4) = 'E';
statuses(5) = 'P';
pos = %lookupne('P' : statuses);
// pos = 4
This searches the array and returns the first position where the value is not 'P'.
In this case, position 4 contains 'E'.
Why this is useful
Without %LOOKUPNE, you would usually write a loop.
pos = 0;
for i = 1 to %elem(statuses);
if statuses(i) <> 'P';
pos = i;
leave;
endif;
endfor;
That works.
But %LOOKUPNE expresses the intent more clearly:
pos = %lookupne('P' : statuses);
The code says exactly what it is trying to do:
Find the first value that is not equal to this value.
Example: find first non-blank value
A common use case is finding the first meaningful value in an array that may be initialized with blanks.
**free
ctl-opt dftactgrp(*no);
dcl-s notes varchar(50) dim(5);
dcl-s pos int(10);
notes(1) = '';
notes(2) = '';
notes(3) = 'Address changed';
notes(4) = '';
notes(5) = '';
pos = %lookupne('' : notes);
// pos = 3
This returns the first element that is not blank.
That can be useful when processing optional values, validation messages, notes, or staged data.
Example: detect first changed value
Imagine an array where most values should be the same.
**free
ctl-opt dftactgrp(*no);
dcl-s warehouse char(3) dim(6);
dcl-s pos int(10);
warehouse(1) = 'EDM';
warehouse(2) = 'EDM';
warehouse(3) = 'EDM';
warehouse(4) = 'CGY';
warehouse(5) = 'EDM';
warehouse(6) = 'EDM';
pos = %lookupne('EDM' : warehouse);
// pos = 4
This tells you the first position that breaks the expected value.
Using a start index
Like other lookup functions, %LOOKUPNE can use a start position.
pos = %lookupne('P' : statuses : 3);
This starts looking from element 3.
That can be useful when earlier elements have already been processed.
When to use %LOOKUPNE
Use %LOOKUPNE when you need to find the first value that differs from an expected value.
Good use cases include:
- Finding the first non-blank value
- Finding the first status that is not normal
- Finding the first array element that changed
- Finding the first exception in a group of expected values
- Replacing simple loops that search for a non-matching value
When not to use %LOOKUPNE
Do not use %LOOKUPNE when a loop would make the business logic clearer.
For example, if you need multiple checks, extra calculations, logging, or complex conditions, a loop may be easier to read and maintain.
Also remember that %LOOKUPNE finds the first element that is not equal to the search value.
It does not tell you why the value is different.
Performance note
IBM documents that %LOOKUPNE always uses a sequential search starting at the start index.
That is important to know when working with large arrays.
For normal business arrays, that may be perfectly fine.
For very large arrays or performance-sensitive logic, understand the search behavior before replacing existing logic.
PTF / release note
PTF / release note
Before using %LOOKUPNE, verify the required IBM i release level, RPG compiler PTF, SQL RPG compile support, and runtime PTFs on the systems where the program will be compiled and run.
At the time of writing, IBM’s RPG Cafe lists %LOOKUPNE as part of the July 2026 RPG enhancements and should be checked for current PTF information before using it in real development or production environments.
Final takeaway
%LOOKUPNE is a small but useful addition to RPG.
It gives developers a direct way to find the first array element that does not match an expected value.
Use it when the intent is simple:
Find the first value that is different.
That is clearer than writing a loop when all you need is the first non-matching element.
References
Documentation and references used for this lesson.

Comments
Share your thoughts, questions, or real-world IBM i experiences related to this article.