Update opcode questions

14 Views


Here’s a focused set of interview questions and model answers related to the UPDATE opcode in RPGLE—particularly useful for assessing or demonstrating your understanding of record-level updates in IBM i environments:


🎤 Interview Questions: UPDATE Opcode in RPGLE


💬 Q1: What is the purpose of the UPDATE opcode in RPGLE?

Sample Answer:

The UPDATE opcode is used to write modified data back to a database record that has been previously read and locked using an operation like CHAIN, READ, or READ(E). It writes the updated values of the record buffer to the database.


💬 Q2: Can you update a record without reading it first in RPGLE?

Sample Answer:

No. You must first read and lock the record using CHAIN, READ, or similar. Only then can you use UPDATE to modify it. Otherwise, the program won't know which record to update, and it will result in an error.


💬 Q3: What happens if you try to UPDATE a record that is not locked?

Sample Answer:

The UPDATE operation will fail and raise a record lock error. To handle this safely, we can use UPDATE(E) and check %ERROR or %STATUS to manage the error condition without crashing the program.


💬 Q4: What is the difference between UPDATE and UPDATE(E) in RPGLE?

Sample Answer:

Feature UPDATE UPDATE(E)
Error handling ❌ No ✅ Yes — allows trap with %ERROR
Crash on failure ✅ Yes ❌ No — you can handle it gracefully

💬 Q5: How do you handle errors from the UPDATE opcode?

Sample Answer:

Use UPDATE(E) and check %ERROR or %STATUS. For example:

update(E) MyFile;
if %error;
   if %status = 1218;
      dsply 'Record is locked by another job';
   endif;
endif;

💬 Q6: What are common %STATUS codes for UPDATE errors?

Sample Answer:

Status Code Meaning
1211 Record not found
1216 File not open for update
1218 Record lock conflict

💬 Q7: Can UPDATE be used on all files?

Sample Answer:

Only on files that are opened with update capability, either by using USAGE(*UPDATE) in free-form or F-spec with U in fixed-form. Attempting to update a file opened in input-only mode will result in a runtime error.


💬 Q8: Can you update a specific field using UPDATE?

Sample Answer:

No. UPDATE writes the entire record buffer back to the database. To update only specific fields, you must ensure other fields remain unchanged in the buffer. For field-level updates, embedded SQL is a better option.


💬 Q9: What alternatives exist to UPDATE for modern RPGLE programs?

Sample Answer:

In modern RPGLE, many developers use embedded SQL for updates, which offers more control, conditional logic, and field-level updating. Example:

exec sql
   update MyTable set Status = 'A' where ID = :MyID;

 

Post Comments