In Sage X3 development, there are times when you need to filter records based on a selective list of values—similar to using the IN operator in SQL. However, Sage X3 does not provide a direct equivalent of SQL’s IN operator within its standard 4GL syntax.
Fortunately, there is an effective alternative: the FIND() function.
Using the FIND() Function as an Alternative to SQL IN
The FIND() function allows you to search for one or multiple values in a given character string or list. When used in a table query, it helps you filter records matching the values you specify.
Syntax
FIND(column, list_of_elements)
If the function returns a value other than 0, it means the item was found.
In Sage X3, there are two ways to apply this approach:
1. Using FIND() Directly in a WHERE Condition
You can directly include the FIND() function in your tab
le loop’s WHERE clause along with the list of values you want to search for.
Example: Searching Sales Invoice Records
## Open table
If !clalev([ZSIH]) : Local File SINVOICE[ZSIH] Endif
## Add WHERE to use FIND function to find list of invoices.
FOR [F:ZSIH] WHERE FIND([F:ZSIH]NUM, “2012403SINV0001”, “2012403SINV0002”, “2012403SINV0003”, “2012403SINV0004”) <> 0
INFBOX “Sales Invoice Found : ” + NUM$([F:ZSIH]NUM) ## This will return found invoices.
NEXT
This approach is straightforward and works well when you have a small number of values to check.
New Stuff:- How Sage X3 ERP for Distribution Transforms Inventory Control for Modern Wholesale Businesses
2. Using an Array for Better Flexibility
If you want a cleaner, more dynamic solution—especially with a large or variable list of values—you can store the search values in an array and then call FIND() using that array.
Example: Searching Purchase Invoice Records Using an Array
## Open Table
If !clalev([ZPIH]) : Local File PINVOICE[ZPIH] Endif
## Create Array that holds the list of finding items (invoice numbers)
LOCAL CHAR ZNUMBOM(50)(5)
## Assign Values to Array
ZNUMBOM(1) = “IEINV-BOM-0925-00004”
ZNUMBOM(2) = “IEINV-BOM-0925-00005”
ZNUMBOM(3) = “IEINV-BOM-0925-00006”
ZNUMBOM(4) = “IEINV-BOM-0925-01346”
## Loop through the table to find matching records
FOR [F:ZPIH] WHERE FIND([F:ZPIH]NUM, ZNUMBOM) <> 0
INFBOX “PINV : ” + NUM$([F:ZPIH]NUM) ## Found matching record
NEXT
Using an array makes your code easier to maintain, extend, and reuse.
Conclusion
While Sage X3 does not support the SQL IN operator directly, the FIND() function provides an excellent alternative for filtering records based on a list of values.
Whether you pass values directly in the WHERE clause or use an array for better organization, FIND() is a powerful tool to achieve similar functionality efficiently.
If you frequently work with dynamic lists, the array method is highly recommended for cleaner and more maintainable code.
About Us
Greytrix – a globally recognized and one of the oldest Sage Development Partners is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience and expertise, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development, and implementation competence.
Greytrix has some unique integration solutions developed for Sage CRM with Sage ERPs namely Sage X3, Sage Intacct, Sage 100, Sage 500, and Sage 300. We also offer best-in-class Sage ERP and Sage CRM customization and development services to Business Partners, End Users, and Sage PSG worldwide. Greytrix helps in the migration of Sage CRM from Salesforce | ACT! | SalesLogix | Goldmine | Sugar CRM | Maximizer. Our Sage CRM Product Suite includes addons like Greytrix Business Manager, Sage CRM Project Manager, Sage CRM Resource Planner, Sage CRM Contract Manager, Sage CRM Event Manager, Sage CRM Budget Planner, Gmail Integration, Sage CRM Mobile Service Signature, Sage CRM CTI Framework.
Greytrix is a recognized Sage Champion Partner for GUMU™ Sage X3 – Sage CRM integration listed on Sage Marketplace and Sage CRM – Sage Intacct integration listed on Sage Intacct Marketplace. The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for the processing and execution of application programs at the click of a button.
For more information on our integration solutions, please contact us at sage@greytrix.com. We will be glad to assist you.