If you want to update just one field in a file using RPGLE without rewriting the entire record. In IBM i (AS/400) RPGLE, you can do a partial update using the %FIELDS built-in function.
Example: Update a Single Field in RPGLE (Free-Format)
dcl-f CUSTFILE usage(*update);
dcl-s custId like(CUSTID);
dcl-s newPhone like(PHONE);
custId = '1001';
newPhone = '7025551234';
// Read the record by key
chain custId CUSTFILE;
if %found(CUSTFILE);
PHONE = newPhone;
update %fields(PHONE) CUSTFILE; // Only updates PHONE field
endif;
dcl-s custId like(CUSTID);
dcl-s newPhone like(PHONE);
custId = '1001';
newPhone = '7025551234';
// Read the record by key
chain custId CUSTFILE;
if %found(CUSTFILE);
PHONE = newPhone;
update %fields(PHONE) CUSTFILE; // Only updates PHONE field
endif;
Key Points
Key Points
