Release the NEW Power of CL

Release the NEW Power of CL

Name:

Email:

Profile Manager

Stop spending time and money reinstating user profiles!

Try Profile Manager Today!

30 DAY FREE TRIAL

Learn More

Programming Services

Do you need a program written?

Bruce Vining Services can provide highly experienced IBM i developers to supplement your staff with short term contracts. If you are looking for custom solutions involving system functions such as communications, database, security, encryption, print, and work management you will find your answers at Bruce Vining Services.

PDF Print E-mail

Read Prior Equal (READPE)

Where allowed to run:
  • Batch program (*BPGM)
  • Interactive program (*IPGM)
Threadsafe: Conditional
Parameters
Examples
Error messages

The Read Prior Equal (READPE) command reads the prior record from where a file is currently pointing if the record has the same key value as the current record.

This command never runs in the traditional sense and will return an error if an attempt is made to run the command. The CLF precompilers, when they encounter this command in a CL source program, replace the command and generate CL instructions directly into the compiled CL program.

Restrictions:

  • This command can only be used in a CL program that is created using a CLF precompiler command. The CLF precompiler commands are CRTBNDCLF, CRTCLFMOD, and CRTCLFPGM.
Top

Parameters

KeywordDescriptionChoicesNotes
KEYLIST Key field list Values (up to 10 repetitions): Not restricted Optional, Positional 1
FILEID File identifier Simple name Optional
RCDFMT Record format Character value, *ONLY Optional
EOF End of file Logical value Optional
ERR Error found Logical value Optional
RCDLCK Record lock *OPNF, *NO Optional
KEYSTRUCT Key field structure Element list Optional
Element 1: Number of key fields Unsigned integer
Element 2: Structure Character value
OPNPGM Program opening file Single values: *CURPGM
Other values: Qualified object name
Optional
Qualifier 1: Program opening file Name
Qualifier 2: Library Name, *CURLIB
Top

Key field list (KEYLIST)

Specifies the key values to be used when reading a record by key.

You can specify up to 10 values for this parameter. Each value specified corresponds to one key field in the file's key definition. The definition of the CL variable used does not have to match the definition of the key field within the file. The two definitions can be of different TYPE and LEN. In addition, character expressions can be used.

If the file has a composite key it is not necessary to provide all key values. Read by partial key is supported. If a file has three key fields, you can specify one, two, or all three key field values with this parameter.

When specifying numeric variables or numeric literals, any valid numeric datatype can be used. For instance the CL variable may be declared as TYPE(*DEC) while the file key field is defined as TYPE(*INT). When using numeric variables or literals the maximum number of digits at runtime that can be represented to the left of the decimal point is nine. At runtime the maximum number of digits to the right of the decimal point is five. When using a CL variable the variable can be declared with a larger size, for instance TYPE(*DEC) LEN(15 0), but at run time the actual value must be within the range of .00001 to 9999999999.99999.

If the numeric value is outside of this range the system will send message CPF0001 (Error found on READRCDCLF command) prior to running the command. For numeric keys that exceed this range you can pass the numeric value as a character value or use the KEYSTRUCT parameter. The following examples demonstrate how to use a character value for numeric keys with a value greater than 9999999999.99999.

The first example uses a character variable with a length of 30 to represent the numeric value. The second example uses a character literal to represent a numeric value of 15 digits.

 

    /* Using a large character variable             */
    Dcl        Var(&Char) Type(*Char) Len(30)
    Dcl        Var(&Dec)  Type(*Dec)  Len(15 0) +
                            Value(123456789012345)
    ChgVar     Var(&Char) Value(&Dec)
    Chain      &Char BIGKEY
    /* or using a character literal value           */
    Chain      '123456789012345' BIGKEY

 

You cannot specify both KEYLIST and KEYSTRUCT with the same command.

unrestricted-value
Specify the CL variables, or literal values, that contain the key values to be used. There must be one CL variable or literal value specified for each key field to be used.

When working with files with multiple keys you do not have to specify all key fields. Only specify those key values that you want used when reading a record. You cannot however omit key values. For example, if the file has five key fields defined and you want to specify key field 3 then you must also specify key fields 1 and 2. You do not however need to specify values for keys 4 and 5.

Top

File identifier (FILEID)

Specifies the file identifier that was used on a previous Open File for Processing (OPEN) or Open File using CLF (OPNFCLF) command in the application.

This parameter is used by CLF commands to identify the file to be processed by the command.

If the file is declared using the DCLFCLF command this parameter is optional if the RCDFMT parameter specifies a record format name that is associated with one and only one file ID.

simple-name
Specify a name that matches the FILEID parameter value of a previous OPEN or OPNFCLF command.
Top

Record format (RCDFMT)

Specifies the name of the record format to be used.

*ONLY
There is only one record format defined for the file. This record format will be used by the command.
character-value
Specify the name of the record format to be used.
Top

End of file (EOF)

Specifies a logical CL variable to receive the end-of-file status. If the variable value is equal to '1' (true) then end-of-file was reached when performing the read command. If the variable value is equal to '0' (false) then end-of-file was not reached.

This CL variable is typically declared by either the Declare Indicators using CLF (DCLINDCLF) command or the Generate Indicators using CLF (GENINDCLF) command. These commands would have specified CLFIND(*YES). When using these commands the name of the declared CL variable is &EOF.

If no CL variable is specified and an end of file condition is encountered the application program will be sent escape message VC2501C.

logical-value
Specify the name of a CL variable declared as TYPE(*LGL).
Top

Error found (ERR)

Specifies a CL logical variable to receive general error status. If the variable value is equal to '1' (true) then an error was found when performing the command. If the variable value is equal to '0' (false) then no error was found when performing the command.

This CL variable can be declared by the Declare Indicators using CLF (DCLINDCLF) command, the Generate Indicators using CLF (GENINDCLF) command, or by you using the Declare CL Variable (DCL) command. The two CLF commands would have specified CLFIND(*YES). When using the CLF commands the name of the CL variable is &ERR.

If no CL variable is specified and an error condition is encountered the application program will be sent an escape message.

logical-value
Specify the name of a CL variable declared as TYPE(*LGL).
Top

Record lock (RCDLCK)

Specifies if the record being read should be locked.

*OPNF
The record being read will be locked based on the value specifed for the USAGE parameter when the file was opened. If the file is open with USAGE(*BOTH) then the record will be locked. Otherwise the record will not be locked.
*NO
The record will not be locked. If the job currently holds a lock on a record within the file the pre-existing lock will continue to be held. To release a pre-existing lock you can use either the Release a Record (UNLOCK) command or the Release Record using CLF (RLSRCDCLF) command.
Top

Key field structure (KEYSTRUCT)

Specifies the key values to be used when reading a record by key.

You cannot specify KEYLIST and KEYSTRUCT with the same command.

Element 1: Number of key fields

unsigned-integer
Specify the number of key fields within the structure element that are to be used. If the file has a composite key it is not necessary to provide all key values. Read by partial key is supported.

Element 2: Structure

character-value
Specify the CL variable that contains the key values. The key fields provided in the CL variable must be declared the same as the key fields defined within the keyed access path being used.

A key field structure can be defined using either the Declare File Key Structure (DCLFKSCLF) or the Generate File Key Structure (GENFKSCLF) command.

Top

Program opening file (OPNPGM)

The same FILEID value can be in use across multiple programs within a job. Each instance of a file open is uniquely identifed by the OPNPGM parameter. This parameter specifes the application program that initially opened the file using the Declare File using CLF (OPEN) or the Open File using CLF (OPNFCLF) command.

All CLF commands that reference the same FILEID and OPNPGM combination share the same view of the file. If one program causes the position within the file to change all programs see that change. If one program closes the file then the file is closed to all programs.

The combination of FILEID and OPNPGM must be unique within the activation group the application program is running in.

If the program name is *CURPGM then the library qualifier for this parameter is ignored. The library of the current program will be used.

Single values: Program opening file

*CURPGM
The current program opened the file associated with FILEID. It is this file open instance that is to be used.

Qualifier 1: Program opening file

name
Specify the name of the program that initially opened the file identified by FILEID. It is this file open instance that is to be used.

Qualifier 2: Library

*CURLIB
The current library for the thread is used. If there is no current library for the thread then library QGPL is used.
name
Specify the name of the library where the program that initially opened the file is located.
Top

Examples for READPE

Example 1: Reading a Previous Record with a Key Equal to a Value

 

    ReadPE     (&EMPDPT) VC2EMP EOF(&EOF)

 

The READPE command will read the previous record from file VC2EMP if the first key field of the record has a value equal to the value of CL variable &EMPDPT. If the previous record does not have a key value equal to the value of CL variable &EMPDPT then CL logical variable &EOF will be set to true. The CL logical variable &EOF will also be set to true when attempting to read a record prior to the first record in the file.

Top

Error messages for READPE

*ESCAPE Messages

CPF0001
Error found on &1 command.
VC2501A
File &1 is not open for access by relative record number.
VC2501B
Record not found in file &1.
VC2501C
End of file for file &1.
VC25021
The &4 command was not successful when accessing File ID &2.
VC25025
Target datatype of &1 not recognized.
VC2502E
File ID &1 is not open.
VC25065
RCDBUF parameter is missing on &2 command.
VC25076
Record in file &1 is locked by another job.
VC29002
Function did not complete. See previously listed messages related to possible user errors.
VC29003
Function did not complete. See previously listed messages for possible cause.
VC29004
Function did not complete. See previously listed messages for possible cause.
VC29005
Function did not complete. Contact your service provider.
VC29013
Function did not complete. See previously listed messages for possible cause.
Top
 
Joomla 1.5 Templates by Joomlashack