Posts

Showing posts from June, 2025

Simplifying RPG Assignments with EVAL-CORR: A Real-World Example

Image
As RPG developers, we often find ourselves writing repetitive and verbose code to move data between data structures — especially when we fetch records from a database and need to populate another structure with the same fields. Fortunately, the EVAL-CORR operation (available in RPG Free Format as a simple EVAL assignment when structures share field names) allows us to replace multiple lines of manual assignments with one clean and elegant statement. In this post, I’ll show you how EVAL-CORR works using a practical example that fetches customer data from a physical file (CLANA00F) and copies selected fields into another data structure. The Problem: Manual Field Mapping Suppose you have a data structure UserData filled via an SQL FETCH, and you want to copy its values into another structure CLANArec with a matching layout. You might be tempted to do something like this: CLANAREC.CLANN0 = WWANN0;  CLANAREC.CLCCL0 = WWCCL0;  CLANAREC.CLCIB0 = WWCIB0;  CLANAREC.CLNOM0 = WWNO...