In RPGLE (IBM i), the EXCEPT
operation code is used in traditional (fixed-format) RPG to write output to a printer file (PRTF) using an output specification defined in the program or external file.
It is rarely used in modern Free-Form RPG, but still important to understand for maintaining legacy applications.
๐งพ What EXCEPT
Does
-
It writes a record to a printer file based on a named output specification.
-
The format must be defined in O-specs in the source, or externally in the printer file.
๐ Example (Fixed-Format RPG)
Assume a printer file MYREPORT
is defined with a record format named DETAIL
.
FMYREPORT O F 132 PRINTER
DName S 30A
DAge S 3S 0
C EXCEPT DETAIL
ODETAIL E Name Age
-
EXCEPT DETAIL
writes the output line defined in theODETAIL
specification. -
The fields
Name
andAge
are placed at specific positions.
โ๏ธ Key Notes
Feature | Description |
---|---|
Output only | EXCEPT is used only for writing, not reading |
PRINTER files only | Works with files defined with PRINTER device |
O-Spec Required | Needs output specs (O -specs) or externally described formats |
Used in reports | Common in old-style report generation |
๐ซ Not Used in Free-Form RPG
-
In modern free-form RPG,
EXCEPT
is generally not used. -
Instead, output is handled with
WRITE
or SQL/IFS/logs depending on the context.
โ Summary
-
EXCEPT
writes output lines to printer files using a named output spec. -
It's a legacy opcode, used primarily in fixed-format RPG for printed report generation.
-
Modern programs avoid
EXCEPT
in favor ofWRITE
, free-form printing, or SQL-based reporting.
----------------------------------------------------------------------------------------------------------------------------------------------
Great question.
๐ Does EXCEPT
Lock a File in RPGLE?
No, the EXCEPT
operation does not lock a file or record in the traditional sense.
๐ Why?
-
EXCEPT
is used to write output to a printer file (PRTF)—not a database file. -
Printer files do not involve record-level locking like database files do.
-
It simply sends a formatted line to the spool file or printer output.
โ๏ธ Details:
Feature | EXCEPT Behavior |
---|---|
Used for | Report printing (not DB I/O) |
Locks file? | โ No – no record or file locking |
Device Type | PRINTER |
Concurrency | Safe – multiple jobs can write to their own spool files independently |
โ Summary
-
EXCEPT
is strictly for formatted report writing. -
It does not lock any files or records.
-
Locking concerns apply to database files (PF/LF) accessed with
CHAIN
,READ
,UPDATE
, etc.—not to printer files used withEXCEPT
.
If you're seeing unexpected behavior around locking, it may involve other files in your program, not the EXCEPT
itself. I can help you analyze that too.
----------------------------------------------------------------------------------------------------------------------------------
No, you cannot update a database file using the EXCEPT
opcode in RPGLE.
๐ What EXCEPT
Does and Doesn't Do
Feature | EXCEPT Behavior |
---|---|
Used for | Writing output lines to a printer file |
Updates database file? | โ No |
Inserts new DB records? | โ No |
Device type | PRINTER device only |
Associated file type | O-spec output or external printer formats |
โ If You Want to Update a File in RPGLE
Use these opcodes instead (for database files):
Opcode | Purpose |
---|---|
CHAIN |
Retrieve a record by key |
READ |
Read a sequential record |
UPDATE |
Update a locked record |
WRITE |
Add a new record |
DELETE |
Delete an existing record |
๐ง Example (Correct Way to Update a Record):
dcl-f MyFile usage(*update) keyed;
chain keyField MyFile;
if %found(MyFile);
MyField = 'NewValue';
update MyFile;
endif;
โ Summary
-
EXCEPT
is not used for updating or manipulating database files. -
It is used only for writing output lines to a printer file (e.g., report generation).
-
For database updates, use
CHAIN
+UPDATE
, or SQLUPDATE
statements.
---------------------------------------------------------------------------------------------------------------------------
Yes, in AS/400 RPGLE interviews—especially for legacy system roles—you might encounter questions about the EXCEPT
opcode. Here's how such interview questions are typically framed and how you can respond:
๐ฌ Common Interview Questions on EXCEPT
Opcode
โ
1. What is the purpose of the EXCEPT
opcode in RPG?
Answer:
The
EXCEPT
opcode is used in traditional RPG (especially fixed-format) to write output records to a printer file. It references a named output specification (O-spec), which defines how the output line should be formatted. It is typically used for generating reports or printed documents.
โ
2. Can EXCEPT
be used to update or write to database files?
Answer:
No.
EXCEPT
is used only with printer files, not database files. For updating database records, we use opcodes likeUPDATE
,WRITE
,DELETE
, andCHAIN
.
โ
3. What’s the difference between EXCEPT
and WRITE
in RPG?
Answer:
Feature | EXCEPT |
WRITE |
---|---|---|
File type | Printer file | Database or printer file |
Needs record format? | Yes, defined in O-spec or externally | Yes |
Used in | Report generation | Writing records (DB or print) |
Modern use? | Rare / legacy | Common in free-form RPG |
โ
4. Is EXCEPT
still used in modern RPG programming?
Answer:
Rarely. Modern RPG (free-form) and reporting tools typically use
WRITE
, embedded SQL, or external reporting tools (like Query/400, DB2 Web Query, or JasperReports).EXCEPT
is mainly seen in legacy RPG III or RPG IV (fixed-format) programs.
โ
5. What happens if the named EXCEPT
format doesn’t exist?
Answer:
If the format is not defined in the O-specs or in the external printer file, the compiler will throw an error during compilation, as
EXCEPT
needs a valid output format to write to.
โ Pro Tip for Interviews
If you're asked about EXCEPT
, the interviewer is likely checking:
-
Your familiarity with legacy RPG practices
-
Whether you know the difference between printer vs. database file handling
-
Your adaptability to modern techniques