If your application uses a file name instead of a record format name for records to be added to the database, and if the file used is a logical file with more than one record format, you need to write a format selector program to determine where a record should be placed in the database.
When an application program wants to add a record to the database file, the system calls the format selector program. The format selector program examines the record and specifies the record format to be used. The system then adds the record to the database file using the specified record format name.
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++... +++* C *ENTRY PLIST C PARM RECORD 80 C* The length of field RECORD must equal the length of C* the longest record expected. C PARM FORMAT 10 C MOVELRECORD BYTE 1 C BYTE IFEQ 'A' C MOVEL'HDR' FORMAT C ELSE C MOVEL'DTL' FORMAT C END
The format selector receives the record in the first parameter; therefore, this field must be declared to be the length of the longest record expected by the format selector. The format selector can access any portion of the record to determine the record format name. In this example, the format selector checks the first character in the record for the character A. If the first character is A, the format selector moves the record format name HDR into the second parameter (FORMAT). If the character is not A, the format selector moves the record format name DTL into the second parameter.
The format selector uses the second parameter, which is a 10-character field, to pass the record format name to the system. When the system knows the name of the record format, it adds the record to the database.
To create the format selector, you use the create program command for the language in which you wrote the program. You cannot specify USRPRF(*OWNER) on the create command. The format selector must run under the user's user profile not the owner's user profile.
In addition, for security and integrity and because performance would be severely affected, you must not have any calls or input/output operations within the format selector.
The name of the format selector is specified on the FMTSLR parameter of the Create Logical File (CRTLF), Change Logical File (CHGLF), or Override with Database File (OVRDBF) command. The format selector program does not have to exist when the file is created, but it must exist when the application program is run.