Flux RSS des billets

DotMG's joblog

Work hard at whatever you do! (Ecc. 9. 10a)
FEOD, what does it mean?
Publié le 18 Oct 2013, 3:52 pm dans iseries

I have been coding with RPG/400 for more thant 12 years. These are a number of opcode I've never used, and I even didn't knew exactly what do they mean, and for which purpose may I need to use them.

One of these is FEOD : Force End Of Data.

The FEOD operation signals the logical end of data for a primary, secondary, or full procedural file. The FEOD function differs, depending on the file type and device. (For an explanation of how FEOD differs per file type and device, see the Database Guide, SC41-9659.)

FEOD differs from the CLOSE operation: the program is not disconnected from the device or file; the file can be used again for subsequent file operations without an explicit OPEN operation being specified to the file.

You can specify conditioning indicators. Factor 2 names the file to which FEOD is specified. You can specify a resulting indicator in positions 56 and 57 to be set on if the operation is not completed successfully.

To process any further sequential operations to the file after the FEOD operation (for example, READ or READP), you must reposition the file.

According to its definition, it's like a CLOSE but does not disconnect the program? In fact, this explanation does not say why it may be needed. To understand its use, we must know the mechanism that takes place when you write or read a record in an RPG program.

Physically, the program has 3 resources for storing data : the hard disk : the non-volatile storage device, the RAM buffer, and a DB layer. When you issue the WRITE operation, the record is not necessarily written to disk, it is written to the RAM buffer. Writing to hard disk happens only when the program ends, or when the RAM buffer is full, or when you ask it to be written, by using the FEOD opcode. When you try to access the record with embedded SQL, the program only look at the DB layer, which may be linked to the hard disk, not the RAM buffer. What this means is that, if you write 5 records to your file, then use embedded SQL to access the newly written records, you may not see them.

So, if you mix a SQL opcode WRITE and embedded SQL SELECT in your program, to ensure a correct synchronisation, you must issue an FEOD opcode after each WRITE. This asks the program to write data to disk without waiting for the buffer to be full. It alters performance but this can help you avoid strange results with your application.

Les commentaires sont fermés pour ce billet.