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

Position DB File using CLF (POSDBFCLF)

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

The Position DB File using CLF (POSDBFCLF) command positions to a record in the file identified by the FILEID keyword. The position can be specified by key, relative record number (RRN), or one of several special values (*FIRST, *LAST, etc).

If no record is found in the file that meets the positioning criteria the file is positioned to end of file.

Example number 3 of this command documentation provides a sample program that can be used to interactively view the results of various TYPE and KEYREL value combinations. This program can be beneficial when first using the POSDBFCLF command with keyed access paths. The example will assist you in understanding how diffferent TYPE and KEYREL values can be used to position into a file.

Chapter 8 of the CLF Programmer's Guide and Install Reference also discusses in detail the results to expect from various TYPE and KEYREL combinations when working with keyed access paths.

Restrictions:

  • This command is valid only within a CL program.
  • This command is only valid for database and DDM files.
  • The file identified by the FILEID parameter must have been previously opened using the Open File using CLF (OPNFCLF) command.
  • Input/Output operations to a CLF shared file open should not be run concurrently among threads in a job. A shared file open is one where the OPNPGM parameter has been specifed with a value other than *CURPGM. If application thread serialization is used CLF shared files will utilize a common I/O feedback information area.
Top

Parameters

KeywordDescriptionChoicesNotes
FILEID File identifier Simple name Optional, Positional 1
TYPE Type of positioning *START, *KEY, *RRN, *NXT, *PRV, *FIRST, *LAST, *END Optional, Positional 2
RCDFMT Record format Character value, *ONLY Optional
EOF End of file Logical value Optional
RCDNOTFND Record not found Logical value Optional
ERR Error found Logical value Optional
RCDLCK Record lock *OPNF, *NO Optional
RRN Relative record number Integer Optional
KEYREL Key relation *EQ, *LE, *GE, *GT, *LT, *NXTEQ, *PRVEQ, *NXTUNQ, *PRVUNQ Optional
KEYLIST Key field list Values (up to 10 repetitions): Not restricted Optional
KEYSTRUCT Key field structure Element list Optional
Element 1: Number of key fields Unsigned integer
Element 2: Structure Character value
KEYCOUNT Key field count Integer Optional
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

File identifier (FILEID)

Specifies the file identifier that was used on a previous 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.

When using the precompiler, and 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.

This is a required parameter when not using the CLF precompiler.

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

Type of positioning (TYPE)

Specifies the type of positioning to be performed with the file identified by FILEID.

This is a required parameter.

*START
Positions to just before the first record in the file. If the file was opened with ACCMTH(*RRN) specified the position will be based on arrival sequence. If the file was opened with ACCMTH(*KEY) specified the position will be based on key sequence. There is no record associated with this position.

When specified the RRN, KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.

*KEY
The record to be positioned to is identified by key value. When specified the KEYREL and one of the keywords KEYLIST, KEYSTRUCT, or KEYCOUNT are required.

The key value used is specified by either the KEYLIST or the KEYSTRUCT parameter. The key value associated with the record the file is currently position at is used when the KEYCOUNT paraemter is specified. The use of the key (*EQ, *NXTEQ, *LE, etc) is specified by the KEYREL parameter.

*RRN
The record to be positioned to is identified by the RRN parameter. When specified the RRN parameter is required and the KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.
*NXT
The record to be positioned to is the next record in the access path being used.

When specified the RRN, KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.

*PRV
The record to be positioned to is the previous record in the access path being used.

When specified the RRN, KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.

*FIRST
The first record in the file is positioned to. If the file was opened with ACCMTH(*RRN) specified the position will be based on arrival sequence. If the file was opened with ACCMTH(*KEY) specified the position will be based on key sequence.

When specified the RRN, KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.

*LAST
The last record in the file is positioned to. If the file was opened with ACCMTH(*RRN) specified the position will be based on arrival sequence. If the file was opened with ACCMTH(*KEY) specified the position will be based on key sequence.

When specified the RRN, KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.

*END
Positions to just after the last record in the file. If the file was opened with ACCMTH(*RRN) specified the position will be based on arrival sequence. If the file was opened with ACCMTH(*KEY) specified the position will be based on key sequence. There is no record associated with this position.

When specified the RRN, KEYREL, KEYLIST, KEYSTRUCT, and KEYCOUNT keywords cannot be specified.

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 CL logical variable to receive end-of-file status. If the variable value is equal to '1' (true) then end of file was reached when positioning the file. This variable is set to '0' (false) when end of file is not reached.

End of file is set when a successful *START or *END TYPE is run.

This CL variable is typically declared by either 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 CLF commands would have specified CLFIND(*YES). When using these commands the name of the CL variable declared is &EOF.

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

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

Record not found (RCDNOTFND)

Specifies a CL logical variable to receive record-not-found status. If the variable value is equal to '1' (true) then the requested positioning was not successful. If the variable value is equal to '0' (false) then the requested positioning was successful.

This CL variable is typically declared by either 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 CLF commands would have specified CLFIND(*YES). When using these commands the name of the CL variable declared is &RNF.

If no CL variable is specified and no record is found that meets the position to requirements the application program will not be sent an escape message.

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 positioned to should be locked.

*OPNF
The locking is determined by the USAGE parameter of the OPNFCLF command used to open the specified FILEID. If USAGE(*BOTH) was specified then a lock on the record positioned to will be acquired. Otherwise the record will not be locked.
*NO
The record that is positioned to 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.
Top

Relative record number (RRN)

Specifies the relative record number of the record to be positioned to. This keyword can only be used when TYPE is *RRN.

integer
The relative record number of the record within the file.
Top

Key relation (KEYREL)

Specifies how the key values specified by the KEYLIST, KEYSTRUCT, or KEYCOUNT keyword will be used in positioning to a record within the file. This keyword can only be used when TYPE is *KEY.

*EQ
Position to the first record with the specified key. The key must be specified using either the KEYLIST or the KEYSTRUCT keyword. KEYCOUNT cannot be used.

The end-of-file condition will not be set by this KEYREL value.

*LE
Position to the first record that has a key less than or equal to the specified key. The key must be specified using either the KEYLIST or the KEYSTRUCT keyword. KEYCOUNT cannot be used.

The end-of-file condition will not be set by this KEYREL value.

*GE
Position to the first record that has a key greater than or equal to the specified key. The key must be specified using either the KEYLIST or the KEYSTRUCT keyword. KEYCOUNT cannot be used.

The end-of-file condition will not be set by this KEYREL value.

*GT
Position to the first record that has a key greater than the specified key. The key must be specified using either the KEYLIST or the KEYSTRUCT keyword. KEYCOUNT cannot be used.

The end-of-file condition will not be set by this KEYREL value.

*LT
Position to the first record that has a key less than the specified key. The key must be specified using either the KEYLIST or the KEYSTRUCT keyword. KEYCOUNT cannot be used.

The end-of-file condition will not be set by this KEYREL value.

*NXTEQ
Position to the next record that has a key equal to the key of the current position in the file. You must specify one, and only one, of the KEYLIST, KEYSTRUCT, or KEYCOUNT keywords. When using the KEYLIST or KEYSTRUCT keywords the value specified is not used. You are only identifying how many key fields from the current position are to be tested.

The record-not-found escape message VC2501B will not be sent with this KEYREL value.

*PRVEQ
Position to the previous record with a key equal to the key of the current position in the file. You must specify one, and only one, of the KEYLIST, KEYSTRUCT, or KEYCOUNT keywords. When using the KEYLIST or KEYSTRUCT keywords the value specified is not used. You are only identifying how many key fields from the current position are to be tested.

The record-not-found escape message VC2501B will not be sent with this KEYREL value.

*NXTUNQ
Position to the next record with a unique key from the current position in the file. You must specify one, and only one, of the KEYLIST, KEYSTRUCT, or KEYCOUNT keywords. When using the KEYLIST or KEYSTRUCT keywords the value specified is not used. You are only identifying how many key fields from the current position are to be tested.

The record-not-found escape message VC2501B will not be sent with this KEYREL value.

*PRVUNQ
Position to the previous record with a unique key from the current position in the file. You must specify one, and only one, of the KEYLIST, KEYSTRUCT, or KEYCOUNT keywords. When using the KEYLIST or KEYSTRUCT keywords the value specified is not used. You are only identifying how many key fields from the current position are to be tested.

The record-not-found escape message VC2501B will not be sent with this KEYREL value.

Top

Key field list (KEYLIST)

Specifies the key values to be used when randomly positioning to a record. When using a relative KEYREL (*NXTxx or *PRVxx) this keyword identifies the number of key fields to be used for comparison purposes. Alternative ways to specify key values are to use the KEYSTRUCT or KEYCOUNT keywords. This keyword can only be used when TYPE is *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. Character expressions can also be used.

If the file has a composite key it is not necessary to provide all key values. Positioning 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 POSDBFCLF 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 key value. The key field for file BIGKEY is actually defined as an 8-byte integer 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)
    PosDBFCLF  FileID(BIGKEY) Type(*Key) KeyRel(*EQ) +
                 KeyList(&Char)
    /* or using a character literal value           */
    PosDBFCLF  FileID(BIGKEY) Type(*Key) KeyRel(*EQ) +
                 KeyList('123456789012345')

 

You cannot specify KEYLIST, KEYSTRUCT, and KEYCOUNT keywords with the same command. Only one can be used.

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 positioning to 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

Key field structure (KEYSTRUCT)

Specifies the key values to be used when randomly positioning to a record. When using a relative KEYREL (*NXTxx or *PRVxx) this keyword identifies the number of key fields to be used for comparision purposes. Alternative ways to specify key values are to use the KEYLIST or KEYCOUNT keywords. This keyword can only be used when TYPE is *KEY.

You cannot specify KEYSTRUCT, KEYLIST, and KEYCOUNT keywords with the same command. Only one can be used.

Element 1: Number of key fields

unsigned-integer
Specify the number of key fields within the second element of this keyword 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 with the same type and length as the key fields defined within the keyed access path being used.

This structure can be created using the Declare File Key Structure (DCLFKSCLF) command, the Generate File Key Structure (GENFKSCLF) command, or you can declare your own structure using the Declare CL Variable (DCL) command. When using the CLF commands the default name of the declared structure will be the name of the record format prefixed by the ampersand character '&'.

Top

Key field count (KEYCOUNT)

Specifies the number of key fields to be used from the record currently positioned to when using a KEYREL value of *NXTEQ, *PRVEQ, *NXTUNQ, or *PRVUNQ. Alternative ways to specify key values are to use the KEYLIST or KEYCOUNT keywords. This keyword can only be used when TYPE is *KEY.

unsigned integer
Specify the number of key fields from the current record to be tested for equality/uniqueness.
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 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 POSDBFCLF

Example 1: Positioning by Key

 

    PosDBFCLF  FileID(VC2EMPDPT) Type(*Key) KeyRel(*EQ) +
                 KeyList(&DptID)

 

This command positions the open file identified by FILEID VC2EMPDPT to the first record with the specified department ID (&DPTID). If the record is not found an escape message will be sent as the RCDNOTFND keyword is not being used. The file must have been opened using the OPNFCLF command with ACCMTH(*KEY).

Example 2: Positioning by Key and Reading by Key

This example uses the POSDBFCLF command in the Show_Emps (Show Employees) subroutine. The positioning performed is to the first employee of a given department.

 

    Pgm
    /***********************************************/
    /* Declare working variables                   */
    /* &DPT_COUNT - used to load department records*/
    /*   to subfile                                */
    /* &EMP_COUNT - used to load employee records  */
    /*   to subfile                                */
    /***********************************************/
    Dcl        Var(&Dpt_Count) Type(*Dec)
    Dcl        Var(&Emp_Count) Type(*Dec)
    /***********************************************/
    /* Declare files and indicators:               */
    /* VC2DPT - Department master file             */
    /* VC2EMP - Employee master file               */
    /* VC2EMPDPT - Logical file of employees by    */
    /*   department                                */
    /* VC2DPTDSP1 - Display file                   */
    /* CLF command related indicators              */
    /***********************************************/
    DclFCLF    FileID(VC2DPT)
    DclFCLF    FileID(VC2EMP)
    DclFCLF    FileID(VC2EMPDPT)
    DclFCLF    FileID(DISPLAY) File(VC2DPTDSP1)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Open the files.                             */
    /***********************************************/
    OpnFCLF    FileID(DISPLAY) Usage(*Both)
    OpnFCLF    FileID(VC2DPT) AccMth(*Key)
    OpnFCLF    FileID(VC2EMP) AccMth(*Key)
    OpnFCLF    FileID(VC2EMPDPT) AccMth(*Key)
    /***********************************************/
    /* Initialize department subfile               */
    /***********************************************/
    WrtRcdCLF  RcdFmt(SFLCTLDPT)
    /***********************************************/
    /* Load list of departments into subfile       */
    /***********************************************/
    ReadRcdCLF FileID(VC2DPT) Type(*First) EOF(&EOF)
    DoWhile    Cond(*Not &EOF)
               /************************************/
               /* Get department managers name     */
               /************************************/
               ReadRcdCLF FileID(VC2EMP) +
                 Type(*Key) RcdNotFnd(&RNF) +
                 KeyRel(*EQ) KeyList(&DptMgr)
               /************************************/
               /* If no mgr, set to *NONE          */
               /************************************/
               If Cond(*Not &RNF) Then(ChgVar +
                    Var(&DptMgrName) Value(&EmpFName))
               Else Cmd(ChgVar +
                    Var(&DptMgrName) Value(*None))
               /************************************/
               /* Set depart. subfile record number*/
               /* Write department record          */
               /* Get next department record       */
               /************************************/
               ChgVar Var(&Dpt_Count) Value(&Dpt_Count + 1)
               WrtRRNCLF RcdFmt(SFLDPT) RRN(&Dpt_Count)
               ReadRcdCLF FileID(VC2DPT) Type(*Nxt) +
                 EOF(&EOF)
               EndDo
    /***********************************************/
    /* If VC2DPT is empty then prompt to run the   */
    /* DEV_LOAD sample program                     */
    /***********************************************/
    If         Cond(&Dpt_Count *EQ 0) Then(Do)
               WrtReadCLF RcdFmt(EMPTYFILE)
               ChgVar Var(&IN03) Value('1')
               EndDo
    /***********************************************/
    /* Continue showing the department list until  */
    /* command key 3 is used                       */
    /***********************************************/
    DoWhile    Cond(*Not &IN03)
               /************************************/
               /* Show active command keys and any */
               /* messages that may have been sent */
               /************************************/
               WrtRcdCLF RcdFmt(KEY)
               /************************************/
               /* Clear message indicator          */
               /************************************/
               ChgVar Var(&IN50) Value('0')
               /************************************/
               /* Show Subfile and Control record  */
               /************************************/
               ChgVar Var(&IN21) Value('1')
               WrtReadCLF RcdFmt(SFLCTLDPT)
               /************************************/
               /* Read subfile records to see if   */
               /* user wants to view the employees */
               /* in the department (option 5)     */
               /************************************/
               ReadRcdCLF RcdFmt(SFLDPT) TYPE(*CHG) +
                  EOF(&EOF)
               DoWhile Cond(*Not &EOF)
                  If Cond(&SflOpt = '5') Then(Do)
                     /******************************/
                     /* First remove the '5' if    */
                     /* one was typed in           */
                     /******************************/
                     ChgVar Var(&SflOpt) Value(' ')
                     UpdRcdCLF RcdFmt(SFLDPT)
                     /******************************/
                     /* Now go display employees   */
                     /******************************/
                     CallSubr Subr(Show_Emps)
                     EndDo
                  /*********************************/
                  /* That department is done.  Now */
                  /* check if another was selected */
                  /*********************************/
                  ReadRcdCLF RcdFmt(SFLDPT) Type(*Chg) +
                    EOF(&EOF)
                  EndDo
               EndDo
    /***********************************************/
    /* Close the files as command key 3 was used   */
    /***********************************************/
    CloFCLF    FileID(VC2EMP)
    CloFCLF    FileID(VC2DPT)
    CloFCLF    FileID(VC2EMPDPT)
    CloFCLF    FileID(DISPLAY)
    /***********************************************/
    /* And return to our caller                    */
    /***********************************************/
    Return
    /***********************************************/
    /* Subroutine to display department employees  */
    /***********************************************/
    Subr       Subr(Show_Emps)
    /***********************************************/
    /* Initialize employee subfile                 */
    /***********************************************/
    ChgVar     Var(&IN21) Value('0') /* Clear SFL */
    WrtRcdCLF  RcdFmt(SFLCTLEMP)
    /***********************************************/
    /* Set employee subfile record number to 0     */
    /* in case this isn't the first department     */
    /* the user selected today                     */
    /***********************************************/
    ChgVar     Var(&Emp_Count) Value(0)
    /***********************************************/
    /* Load list of employees into subfile         */
    /***********************************************/
    /***********************************************/
    /* Position to first employee in department    */
    /***********************************************/
    PosDBFCLF  FileID(VC2EMPDPT) Type(*Key) +
                 RcdNotFnd(&RNF) KeyRel(*EQ) +
                 KeyList(&DptID)
    /***********************************************/
    /* If one was found, process all in department */
    /***********************************************/
    If         Cond(*Not &RNF) Then(Do)
               ReadRcdCLF FileID(VC2EMPDPT) Type(*Key) +
                 EOF(&EOF) KeyRel(*NxtEQ) KeyList(&DptID)
               /************************************/
               /* So long as there are employees   */
               /* in department:                   */
               /************************************/
               DoWhile Cond(*Not &EOF)
               /************************************/
               /* Set depart. subfile record number*/
               /* Write department record          */
               /* Get next department record       */
               /************************************/
                  ChgVar Var(&Emp_Count) +
                    Value(&Emp_Count + 1)
                  WrtRRNCLF RcdFmt(SFLEMP) RRN(&Emp_Count)
                  ReadRcdCLF FileID(VC2EMPDPT) +
                    Type(*Key) EOF(&EOF) KeyRel(*NxtEQ) +
                    KeyList(&DptID)
                  EndDo
               /************************************/
               /* With all of the department       */
               /* employees loaded into the        */
               /* subfile, now display the active  */
               /* command keys                     */
               /************************************/
               WrtRcdCLF RcdFmt(KEY)
               /************************************/
               /* Show Subfile and Control record. */
               /* When user hits ENTER or command  */
               /* key 3 return to main line.       */
               /************************************/
               ChgVar Var(&IN21) Value('1')
               WrtReadCLF RcdFmt(SFLCTLEMP)
               EndDo
    Else       Cmd(Do)
    /***********************************************/
    /* No employees found in department            */
    /***********************************************/
               ChgVar Var(&MsgTxt) +
                  Value('No employees in department' +
                    *BCat &DptID)
               ChgVar Var(&IN50) Value('1')
               EndDo
    EndSubr
    EndPgm

 

The source for this example can be found in member DEV_DPTU1 of source file VC2CLSRC in library VC2CLF. The source for file VC2DPT can be found in member VC2DPT of source file QDDSSRC in library VC2CLF. The source for file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF. The source for file VC2EMPDPT can be found in member VC2EMPDPT of source file QDDSSRC in library VC2CLF. The source for file VC2DPTDSP1 can be found in member VC2DPTDSP1 of source file QDDSSRC in library VC2CLF.

All of the referenced objects should currently exist in library VC2CLF. To create this example program into QTEMP you can use the commands

 

    AddLibLE Lib(VC2CLF)
    CrtBndCLF Pgm(QTEMP/DEV_DPTU1) SrcFile(VC2CLSRC)

 

To run DEV_DPTU1 you can use the command

 

    Call Pgm(QTEMP/DEV_DPTU1)

 

DEV_DPTU1 will display a subfile of the departments found in the VC2DPT department master file. From this subfile you can display the employees of one (or more) departments by using option 5. All departments contain employess other than Administrative Support. Command key 3 can be used to exit the program.

Example 3: Working with Various Position Values

 

    Pgm
    /***********************************************/
    /* This program is a learning tool on how      */
    /* the POSDBFCLF and READRCDCLF commands can   */
    /* be used when working with a keyed access    */
    /* path.                                       */
    /*                                             */
    /* The program allows you to position to       */
    /* various locations within the VC2EMPDPT      */
    /* keyed access path and then see what three   */
    /* records would be read from that access      */
    /* path using various READRCDCLF options.      */
    /*                                             */
    /* Each record returned also includes the      */
    /* status of Record Not Found (RNF), End       */
    /* of File (EOF), and Error (ERR) with each    */
    /* run of the READRCDCLF command.              */
    /***********************************************/
    /***********************************************/
    /* Declare the logical file VC2EMPDPT and      */
    /* display file VC2POSDSP.  DCLINDCLF is not   */
    /* used as we will use the indicators defined  */
    /* with the *DSPF for feedback from the        */
    /* POSDBFCLF and READRCDCLF commands.          */
    /***********************************************/
    DclFCLF    FileID(VC2EMPDPT)
    DclFCLF    FileID(RESULTS) File(VC2POSDSP)
    /***********************************************/
    /* Declare &COUNT. This is used to identify    */
    /* the relative record number to be used       */
    /* when loading the subfile of records read.   */
    /***********************************************/
    Dcl        Var(&Count) Type(*UInt)
    /***********************************************/
    /* Open VC2EMPDPT using keys.  Open VC2POSDSP  */
    /* using a FILEID of RESULTS.                  */
    /***********************************************/
    OpnFCLF    FileID(VC2EMPDPT) AccMth(*Key)
    OpnFCLF    FileID(RESULTS) Usage(*Both)
    /***********************************************/
    /* Set the default values this program uses    */
    /* for the POSDBFCLF and READRCDCLF prompts.   */
    /***********************************************/
    ChgVar     Var(&DptID)     Value('MN')
    ChgVar     Var(&PosType)   Value(*KEY)
    ChgVar     Var(&PosKeyUse) Value(*EQ)
    ChgVar     Var(&RdOP)      Value(*NXT)
    ChgVar     Var(&RdKey)     Value(' ')
    /***********************************************/
    /* Clear the subfile and then load one blank   */
    /* record into the subfile                     */
    /***********************************************/
    WrtRcdCLF  RcdFmt(SFLCTL)
    WrtRRNCLF  RcdFmt(SFLRCDS) RRN(1)
    /***********************************************/
    /* Write the enabled cmd key prompt KEY        */
    /*                                             */
    /* Write and then read the subfile and         */
    /* subfile control record (&IN21)              */
    /***********************************************/
    WrtRcdCLF  RcdFmt(KEY)
    ChgVar     Var(&IN21) Value('1')
    WrtReadCLF RcdFmt(SFLCTL)
    /***********************************************/
    /* While command key 3 is not used to exit     */
    /***********************************************/
    DoWhile    Cond(*Not &IN03)
               /*******************************************/
               /* F5 to print VC2EMPDPT in key order?     */
               /* Then print and continue with processing */
               /*******************************************/
               If Cond(&IN05) Then(Call Pgm(Dev_PosPrt))
               /*******************************************/
               /* Clear the subfile                       */
               /*******************************************/
               ChgVar Var(&IN21) Value('0')
               WrtRcdCLF RcdFmt(SFLCTL)
               If Cond(&PosType = *Key) Then(Do)
                  /****************************************/
                  /* If POSDBFCLF TYPE(*KEY)              */
                  /*    1 Make sure we have a valid KEYREL*/
                  /*    2 Position into VC2EMPDPT         */
                  /****************************************/
                    IF (&PosKeyUse = ' ') Then( +
                       ChgVar Var(&PosKeyUse) Value(*EQ))
                    PosDBFCLF FileID(VC2EMPDPT) +
                      Type(&PosType) EOF(&IN51) +
                      RcdNotFnd(&IN50) Err(&IN52) +
                      KeyRel(&PosKeyUse) KeyList(&DptID)
                    EndDo
               Else Cmd(Do)
                  /****************************************/
                  /* If POSDBFCLF not TYPE(*KEY)          */
                  /*    1 Set KEYREL to blank (not used)  */
                  /*      so that the value used is shown */
                  /*      on the display file             */
                  /*    2 Position into VC2EMPDPT         */
                  /****************************************/
                  ChgVar Var(&PosKeyUse) Value(' ')
                  PosDBFCLF FileID(VC2EMPDPT) +
                    Type(&PosType) EOF(&IN51) +
                    RcdNotFnd(&IN50) Err(&IN52)
                  EndDo
               /*******************************************/
               /* Having set the position of VC2EMPDPT    */
               /* now read three records from VC2EMPDPT   */
               /* using the requested READRCDCLF values   */
               /**********************************************/
               DoFor Var(&Count) From(1) To(3)
                  /*******************************************/
                  /* First clear the employee fields         */
                  /* so we only see what was really read     */
                  /* (as opposed to left over values from    */
                  /* prior reads when we find RNF, EOF, or   */
                  /* ERR)                                    */
                  /*******************************************/
                  ChgVar Var(&EmpDpt)   Value(' ')
                  ChgVar Var(&EmpFName) Value(' ')
                  Select
                    When Cond((&RdOP = *NxtEQ) *Or +
                              (&RdOP = *PrvEQ)) Then(Do)
                     /*************************************/
                     /* For *NXTEQ and *PRVEQ there is a  */
                     /* choice on what key to use for the */
                     /* *EQ test.  If the key is not      */
                     /* specified with READRCDCLF then    */
                     /* the key value comes from POSDBFCLF*/
                     /* and the POSDBFCLF KEYREL.  If     */
                     /* specified with READRCDCLF then    */
                     /* the READRCDCLF key is used.       */
                     /*************************************/
                         If Cond(&RdKey = ' ') Then( +
                            ReadRcdCLF FileID(VC2EMPDPT) +
                              Type(*Key) EOF(&IN54) +
                              RcdNotFnd(&IN53) Err(&IN55) +
                              KeyRel(&RdOP) KeyCount(1))
                         Else Cmd( +
                            ReadRcdCLF FileID(VC2EMPDPT) +
                              Type(*Key) EOF(&IN54) +
                              RcdNotFnd(&IN53) Err(&IN55) +
                              KeyRel(&RdOP) KeyList(&RdKey))
                         EndDo
                    When Cond((&RdOP = *NxtUnq) *Or +
                              (&RdOP = *PrvUnq)) Then(Do)
                     /*************************************/
                     /* For *NXTUNQ and *PRVUNQ:          */
                     /*    1 Blank out RDKEY as it is not */
                     /*      used and the display should  */
                     /*      reflect that                 */
                     /*    2 Read the requested record    */
                     /*************************************/
                         ChgVar Var(&RdKey) Value(' ')
                         ReadRcdCLF FileID(VC2EMPDPT) +
                           Type(*Key) EOF(&IN54) +
                           RcdNotFnd(&IN53) Err(&IN55) +
                           KeyRel(&RdOP) KeyCount(1)
                         EndDO
                    OtherWise Cmd(Do)
                     /**************************************/
                     /* If none of the above:              */
                     /*    1 Blank out RDKEY as it is not  */
                     /*      used and the display should   */
                     /*      should reflect that           */
                     /*    2 Read the requested record     */
                     /**************************************/
                         ChgVar Var(&RdKey) Value(' ')
                         ReadRcdCLF FileID(VC2EMPDPT) +
                           Type(&RdOP) EOF(&IN54) +
                           RcdNotFnd(&IN53) Err(&IN55)
                         EndDo
                  EndSelect
                  /*******************************************/
                  /* Write the record read to the subfile    */
                  /* along with the indicators used for      */
                  /* RNF, EOF, and ERR                       */
                  /*******************************************/
                  WrtRRNCLF RcdFmt(SFLRCDS) RRN(&Count)
               EndDo
               /**********************************************/
               /* When we have read three records from       */
               /* VC2EMPDPT:                                 */
               /* 1 Write the enabled cmd key prompt         */
               /* 2 Write and then read the subfile and      */
               /*   subfile control record (&IN21)           */
               /**********************************************/
               WrtRcdCLF RcdFmt(KEY)
               ChgVar Var(&IN21) Value('1')
               WrtReadCLF RcdFmt(SFLCTL)
    EndDo
    /***********************************************/
    /* When F3 is used to exit the application     */
    /* close the files and return                  */
    /***********************************************/
    CloFCLF    FileID(VC2EMPDPT)
    CloFCLF    FileID(RESULTS)
    EndPgm

 

The source for this example can be found in member DEV_POSRD of source file VC2CLSRC in library VC2CLF. The source for file VC2EMPDPT can be found in member VC2EMPDPT of source file QDDSSRC in library VC2CLF. The source for file VC2POSDSP (File ID RESULTS in the program) can be found in member VC2POSDSP of source file QDDSSRC in library VC2CLF.

All of the files used by DEV_POSRD should currently exist in library VC2CLF. To create DEV_POSRD into QTEMP you can use the commands

 

    AddLibLE Lib(VC2CLF)
    CrtBndCLF Pgm(QTEMP/DEV_POSRD) SrcFile(VC2CLSRC)

 

To run the sample program you can use the command

 

    Call Pgm(QTEMP/DEV_POSRD)

 

To aid in understanding how the various records in VC2EMPDPT are sequenced and accessed you may want to use command key 5 on the display. Command key 5 calls the example program DEV_POSPRT that creates a printed report showing the content of the VC2EMPDPT file in keyed sequence.

The source for DEV_POSPRT can be found in member DEV_POSPRT of source file VC2CLSRC in library VC2CLF. DEV_POSPRT uses the external printer file VC2POSPRT that can be found in member VC2POSPRT of source file QDDSSRC in library VC2CLF.

All of the files used by DEV_POSPRT should currently exist in library VC2CLF. To create DEV_POSPRT into QTEMP you can use the commands

 

    AddLibLE Lib(VC2CLF)
    CrtBndCLF Pgm(QTEMP/DEV_POSPRT) SrcFile(VC2CLSRC)

 

Top

Error messages for POSDBFCLF

*ESCAPE Messages

CPF0001
Error found on &1 command.
VC25019
File ID &1 is not open for keyed access.
VC2501A
File &1 is not open for access by relative record number.
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.
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