4D Blog

Home Product Logical operations on entity selections

Logical operations on entity selections

May 7, 2018

Product

The ORDA series continues! In this blog post we’ll see how to use logical operators on entity selections!

These operations allow you to get intersections, unions, or differences between two entity selections like you can with classic 4D sets.

Logical operators on entity selections example

In classic 4D, you use sets to perform logical operations on several query results. You must create a set after each query, perform the logical operation on the sets, and finally update the current selection of the concerned table with the result set. It’s a bit heavy! Thankfully, with ORDA things are becoming much lighter! Each query gives you an entity selection to which logical operators can be directly applied!

 

ORDA provides the following methods to perform logical operations on two entity selections:

– and(): get the intersection between two entity selections (entities belonging to both)

– or(): get the union between two entity selections (entities belonging to one or to the other)

– minus(): get the difference between two entity selections (entities belonging to one and not to the other)

These methods can also be applied to an entity selection and an individual entity.

Example

An example is worth a thousand words! Let’s take a look at employees and their food preferences.

CLASSIC 4D:

//A named selection "meat" is created before
// ...
QUERY BY ATTRIBUTE([Employee];[Employee]food;"fish";=;True)
CREATE SET([Employee];"fish")
USE NAMED SELECTION("meat")
CREATE SET([Employee];"meat")
UNION("fish";"meat";"result")
USE SET("result")
CLEAR SET("meat")
CLEAR SET("fish")
CLEAR SET("result")

ORDA:

Here, we have a method which receives an entity selection as parameter. We return the union of the $eatingMeat entity selection and the $eatingFish entity selection.

C_OBJECT($eatingFish;$1;$eatingMeat;$result)
 
$eatingMeat:=$1
//Get employees eating fish
$eatingFish:=ds.Employee.query("food.fish=:1";True)
//Get the union of the 2 entity selections $eatingMeat and $eatingFish
$result:=$eatingMeat.or($eatingFish)
$0:=$result

 

Discuss

Tags Database, Objects, ORDA, v17

Latest related posts

  • June 16, 2025

    Generate, share and use web sessions One-Time Passcodes (OTP)

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

Avatar
Marie-Sophie Landrieu-Yvert
• Product Owner • Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy