The write operation allows you to add a new record to a physical database file member.
The WRITE statement in the RPG/400® language and the WRITE statement in the COBOL/400® language are examples of this operation. New records can be added to a physical file member or to a logical file member that is based on the physical file member. When using a multiple format logical file, a record format name must be supplied to tell the system which physical file member to add the record to.
The new record is normally added at the end of the physical file member. The next available relative record number (including deleted records) is assigned to the new record. Some high-level languages allow you to write a new record over a deleted record position (for example, the WRITE statement in COBOL/400 when the file organization is defined as RELATIVE). For more information about writing records over deleted record positions, see your high-level language topic collection.
If the physical file to which records are added reuses deleted records, the system tries to insert the records into slots that held deleted records. Before you create or change a file to reuse deleted records, you should review the restrictions and tips for use to determine whether the file is a candidate for reuse of deleted record space.
If you are adding new records to a file member that has a keyed access path, the new record appears in the keyed sequence access path immediately at the location defined by the record key. If you are adding records to a logical member that contains select/omit values, the omit values can prevent the new record from appearing in the member's access path.
If the file to which you are adding a record has an insert trigger associated with it, the trigger program is called before or after inserting the record.
If the files you are adding to are associated with referential constraints, record insertion can be affected.
The SIZE parameter on the Create Physical File (CRTPF) and Create Source Physical File (CRTSRCPF) commands determines how many records can be added to a physical file member.