After READC returns a changed subfile record, the program can modify field values and issue UPDATE on the subfile format to write those changes back to the in-memory subfile buffer. The updated values are visible when the subfile is next displayed via EXFMT SFLCTL.
DOW NOT Done;
READC SFLREC;
IF %EOF();
Done = *ON;
ELSE;
// Process the changed record, then clear the option field
OPT = *Blank;
UPDATE SFLREC;
ENDIF;
ENDDO;
// Next EXFMT shows the cleared OPT field
EXFMT SFLCTL;
UPDATE targets the subfile record at the RRN of the most recent READC or CHAIN. No other subfile I/O operations should be performed between the READC/CHAIN and the UPDATE.
Issuing UPDATE on a subfile format without a prior successful READC (or CHAIN) raises a runtime error with file status 1221 ("Update or delete without a prior input operation"). Programs can trap this with a MONITOR/ON-ERROR block or the (E) extender.
For a WORKSTN file, the format named on UPDATE must be a subfile record format that the DCL-F exposes via the SFILE keyword. The compiler rejects the following at compile time (reported as "Factor 2 is not a WORKSTN subfile-format name"):
- UPDATE on a subfile format without SFILE - like READC, the owning DCL-F must declare
SFILE(format:<rrn-variable>):[ERROR] MYPGM.rpgle:10:2 - UPDATE 'SFLREC' requires the SFILE keyword on DCL-F 'CUSTLIST' - use SFILE(SFLREC:<rrn-variable>) - UPDATE on a non-subfile screen format - UPDATE is not valid on a regular (non-SFL) display format:
[ERROR] MYPGM.rpgle:10:2 - UPDATE 'PROMPT01' references a non-subfile format - UPDATE on a WORKSTN file requires a subfile (SFL) record format - UPDATE on an unknown format - the format does not match any disk record format or declared display file format:
[ERROR] MYPGM.rpgle:10:2 - UPDATE references unknown format 'NOSUCH' - not a disk record format or a declared display file format
(UPDATE on a disk record format remains valid and is unaffected by these checks.)