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

Open File using CLF (OPNFCLF)

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

The Open File using CLF (OPNFCLF) command opens a file for subsequent processing by commands such as Read Record using CLF (READRCDCLF), Write Record using CLF (WRTRCDCLF), Update Record using CLF (UPDRCDCLF), and Delete Record using CLF (DLTRCDCLF).

If a precompiler is used when creating the program or module, and at least one DCLFCLF command is processed as part of the precompile processing, then the program or module will include reference information for all files opened using the OPNFCLF command. This information can be accessed using the Display Program References (DSPPGMREF) command and is based on the OPNFCLF keyword parameters FILE and USAGE. If the USAGE keyword value is a parameter the file reference usage information will be identified as unspecified.

Files opened with OPNFCLF are not automatically closed when the program ends. Files should be explicitly closed using the Close File using CLF (CLOFCLF) command when the file is no longer needed by the program.

This command must be run in any program using CLF input or output commands with a file.

Restrictions:

  • This command is valid only within a CL program.
  • When opening a logical file that is based on more than one physical file member ACCMTH(*KEY) must be specified.
  • You must have object operational authority and read data authority to the file specified by the FILE parameter. Additional data authorities may be required based on the CLF commands used with the open file. These additional authorities can be found in the help text for each 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 Required, Positional 1
FILE File Qualified object name Optional, Positional 2
Qualifier 1: File Name, *CALC, *FILEID
Qualifier 2: Library Name, *LIBL, *CURLIB
USAGE File usage *INPUT, *OUTPUT, *BOTH Optional
ACCMTH Access method *RRN, *KEY Optional
SEPINDARA Separate indicator area *NO, *YES Optional
INDARA Indicator area variable Character value Optional
ERR Error found Logical value Optional
FILEDEFN File definition description Character value Optional
MBR Member Name, *FIRST, *ALL Optional
SPLFNAME Spool file name Name, *FILE Optional
SPLFUSRDTA Spool file user data Character value Optional
CMTCTL Use commitment control *NO, *YES Optional
IGNRUSEDLT Ignore REUSEDLT *NO, *YES Optional
ALWNULL Allow field value of null *NO, *YES Optional
ALWEXNDTA Allow extended data types *NO, *YES Optional
CCSID Coded character set ID Integer, *JOB Optional
LVLCHK Record format level check *YES, *NO 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 to be associated with the file specified for the File (FILE) parameter. This identifier, when combined with the OPNPGM parameter, must be unique within the activation group and is used by other CLF commands to reference the file.

This is a required parameter.

simple-name
Specify a file identifier for the File (FILE) being opened.
Top

File (FILE)

Specifies the file to be used for subsequent input/output operations by CLF commands.

Single values

*CALC
The open command will calculate the file to be used.

If the FILEDEFN keyword is specified, the open command will use the name of the file used when creating the file definition.

When using the CLF precompiler support, if the file was declared using the DCLFCLF command then the precompiler will default to using the FILEDEFN. You do not need to specify either the FILE or FILEDEFN keyword if you want to open the same file you declared with DCLFCLF.

When not using the CLF precompiler support *CALC will run as if FILE(*FILEID) was specified.

*FILEID
The value specified for the FILEID parameter will be used as the file name.

Qualifier 1: File

name
Specify the name of the file.

Qualifier 2: Library

*LIBL
All libraries in the library list are searched until the first match is found.
*CURLIB
The current library for the job is used to locate the file. If no current library entry exists in the library list, QGPL is used.
name
Specify the library where the file is located.

If no library qualifier is provided the special value *LIBL will be used.

Top

File usage (USAGE)

Specifies how the application opening the file will be using the file.

*INPUT
The application will be reading records from the file.
*OUTPUT
The application will be writing records to the file.
*BOTH
The application will be both reading and writing records to the file.
Top
Top

Separate indicator area (SEPINDARA)

Specifies if indicators are to be passed in a separate indicator area instead of the Input/Ouput buffers. The file being opened must be created using the same option.

*NO
Indicators are passed in the Input/Output buffers.
*YES
Indicators are passed in a separate indicator area.
Top

Indicator area variable (INDARA)

This parameter is only used if SEPINDARA is *YES.

When using the precompiler commands CRTBNDCLF, CRTCLFMOD, or CRTCLFPGM and a separate indicator area has been created with the either the Declare Indicators using CLF (DCLINDCLF) or the Generate Indicators using CLF (GENINDCLF) command this parameter should not be used. The precompiler will determine the appropriate INDARA to use. If a value is specified it will override the precompiler.

If you are not using a CLF precompiler but are using an indicator area created by either DCLINDCLF or GENINDCLF then specify &CLF_INDS for this parameter.

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

File definition description (FILEDEFN)

An optional parameter that can be used when a file definition has been created using the Generate File Field Definition (GENFFDCLF) command. This parameter specifies the name of the structure generated by the GENFFDCLF command. The CL variable name to be specified is typically the same as the FILEID being opened prefixed by an ampersand (&).

When using the precompiler commands CRTBNDCLF, CRTCLFMOD, or CRTCLFPGM and the file is defined using DCLFCLF this parameter should not be used. The precompiler will determine the appropriate FILEDEFN to use. If a value is specified, it will override the precompiler.

This parameter is only required when the file being opened is defined by the GENFFDCLF command and the open command specifies LVLCHK(*YES).

character-value
Specify the CL variable name corresponding to the structure created by the GENFFDCLF command. This is usually the same as the FILEID prefixed by the ampersand (&) character.
Top

Member (MBR)

Specifies the member used within the database file.

*FIRST
The first member of a database file is used. If the File (FILE) being opened is not a database file *FIRST must be specified.
*ALL
All members of the file are processed in order.
name
Specify the member of the database file that is to be used.
Top

Spool file name (SPLFNAME)

Specifies the name of the spooled output file. This parameter only applies to spooled printer files.

*FILE
The name of the printer file is used for the spooled output file name.
name
Specify the name of the spooled output file.
Top

Spool file user data (SPLFUSRDTA)

Specifies any user-specified data to assist in identifying a spooled output file. This parameter only applies to spooled printer files.

character-value
Specify user-specified text.
Top

Use commitment control (CMTCTL)

Specifies if commitment control is to be in effect for the file. This parameter only applies to database files.

*NO
The file is not opened under commitment control.
*YES
The file is opened under commitment control.
Top

Ignore REUSEDLT (IGNRUSEDLT)

Specifies if the reuse of deleted records within a database file is to be ignored when writing records.

*NO
The file attribute for REUSEDLT is not ignored.
*YES
The file attribute for REUSEDLT is ignored. New records will be written to the end of the file regardless of the REUSEDLT setting of the file being written to.
Top

Allow field value of null (ALWNULL)

Specifies whether a field value of null is allowed.

*NO
Values of null are not allowed. When a CLF command encounters a record containing null values an error will be returned.
*YES
Values of null are allowed.
Top

Allow extended data types (ALWEXNDTA)

Specifies if an open should succeed when extended data types exist in the file.

*NO
The file open should fail if the file contains any user defined data types (UDTs), Row IDs, data links, or LOBs.
*YES
The file open should succeed if the file contains user defined data types (UDTs), Row IDs, data links, or LOBs. This value can only be specified if the file is being opened with USAGE(*INPUT).

Note that while the open will succeed data defined using these extended data types may not be useful or actually returned. Other data in the file however will be available to the application. If your application requires access to the data associated with these extended data types you should contact Bruce Vining Services.

Top

Coded character set ID (CCSID)

Specifies the CCSID to be in effect for translation of character data within the file. Depending on the type of file being opened, additional job and file-related attributes may also need to be specified for character translation to occur.

*JOB
The job CCSID is to be used when converting character data to and from the file and the job.
integer
Specify the CCSID to be used for character conversion. The CCSID specified must have an EBCDIC encoding.
Top

Record format level check (LVLCHK)

Specifies whether the level identifiers for the record formats of the file are checked as part of opening the file.

*YES
The level identifiers are checked when the file is opened. If *YES is specified the FILEDEFN parameter must also be specified if not using the precompiler and DCLFCLF command support.
*NO
The level identifiers are not checked when the file is opened.
Top

Program opening file (OPNPGM)

When initially opening a file this parameter must be set to the default value of *CURPGM. Any other value indicates that a shared open is being performed. Each open instance of a file is uniquely identified by the combination of FILEID and OPNPGM.

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.

If the program name is not *CURPGM all keywords except for FILEID, FILEDEFN, and OPNPGM are ignored.

Single values: Program opening file

*CURPGM
The current program is performing the initial open of the specified file.

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 OPNFCLF

Example 1: Opening a Keyed Database File

 

    OpnFCLF FileID(VC2EMP) Usage(*Both) AccMth(*Key)

 

This example opens the file VC2EMP for both input and output operations. When reading from the file keys may be used for both random and sequential access.

By default LVLCHK is *YES. As the FILEDEFN parameter has not been specified (but is required for LVLCHK(*YES), this OPNFCLF command must be in CL source program that will be processed by a CLF precompiler. The precompiler will add the appropriate FILEDEFN parameter.

Example 2: Opening a File as Externally Described

 

    /***********************************************/
    /* This program takes one (required)           */
    /* parameter, the name of a member within the  */
    /* QCLSRC source file.                         */
    /*                                             */
    /* The program will list the contents of the   */
    /* specified source member.  Call this example */
    /* from the command line in order to see the   */
    /* listing.                                    */
    /***********************************************/
    Pgm        Parm(&Member)
    Dcl        Var(&Member) Type(*Char) Len(10)
    /***********************************************/
    /* Declare our variables:                      */
    /*  The DCLFCLF will provide the external      */
    /*      definition for QCLSRC                  */
    /*  The DCLINDCLF will provide the indicator   */
    /*      to detect End of File (&EOF)           */
    /***********************************************/
    DclFCLF    FileID(QCLSRC)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Test to see if the &MEMBER parameter was    */
    /* passed (only needed for bound programs).    */
    /* If not, end with an error message.          */
    /***********************************************/
    ChgVar     Var(&Member) Value(&Member)
    MonMsg     MsgID(MCH3601) Exec(Do)
               RmvMsg Clear(*All)
               SndPgmMsg  Msg( +
                 'Member name is a required parameter')
               Return
               EndDo
    /***********************************************/
    /* Open the file, this time with (by default)  */
    /*   LVLCHK.                                   */
    /*                                             */
    /* Read the first record of the specified      */
    /*   member.                                   */
    /*                                             */
    /* Enter a DoWhile loop conditioned by End of  */
    /*   File (&EOF).  So long as EOF is not       */
    /*   detected:                                 */
    /*   1. Send the line of source read to the    */
    /*      default (*PRV) call message queue      */
    /*   2. Read the next QCLSRC record and loop   */
    /***********************************************/
    OpnFCLF    FileID(QCLSRC) Mbr(&Member)
    ReadRcdCLF FileID(QCLSRC) EOF(&EOF)
    DoWhile    Cond(*Not &EOF)
               SndPgmMsg Msg(&SrcDta)
               ReadRcdCLF FileID(QCLSRC) EOF(&EOF)
    EndDo
    /***********************************************/
    /* When End of File is detected close the file */
    /* and return.                                 */
    /***********************************************/
    CloFCLF    FileID(QCLSRC)
    EndPgm

 

The source for this example can be found in member DEV_OPNF of source file VC2CLSRC in library VC2CLF.

To compile DEV_OPNF you use the CLF precompiler command Create Bound CLF Program (CRTBNDCLF) or Create CLF Program (CRTCLFPGM). To run the program you can use any of the following commands

 

    Call Pgm(DEV_OPNF) Parm(DEV_OPNF) - list member DEV_OPNF
    Call Pgm(DEV_OPNF) Parm(*First)   - list the first member
    Call Pgm(DEV_OPNF) Parm(*All)     - list all members

 

Example 3: Opening a File as Program Described

 

    /***********************************************/
    /* This program takes one (required)           */
    /* parameter, the name of a member within the  */
    /* QCLSRC source file.                         */
    /*                                             */
    /* The program will list the contents of the   */
    /* specified source member.  Call this example */
    /* from the command line in order to see the   */
    /* listing.                                    */
    /***********************************************/
    Pgm        Parm(&Member)
    Dcl        Var(&Member) Type(*Char) Len(10)
    /***********************************************/
    /* Declare our variables:                      */
    /*  &RCDDTA is a record from QCLSRC.  QCLSRC   */
    /*          should have been created with      */
    /*          RCDLEN(92)                         */
    /*  &SRCDTA will hold the source data portion  */
    /*          of a QCLSRC record                 */
    /*  &EOF    is an indicator used to detect     */
    /*          End of File for QCLSRC.  This      */
    /*          could have been defined with       */
    /*          GENINDCLF.                         */
    /***********************************************/
    Dcl        Var(&RcdDta) Type(*Char) Len(92)
    Dcl        Var(&SrcDta) Type(*Char) Len(80)
    Dcl        Var(&EOF) Type(*Lgl)
    /***********************************************/
    /* Test to see if the &MEMBER parameter was    */
    /* passed (only needed for bound programs).    */
    /* If not, end with an error message.          */
    /***********************************************/
    ChgVar     Var(&Member) Value(&Member)
    MonMsg     MsgID(MCH3601) Exec(Do)
               RmvMsg Clear(*All)
               SndPgmMsg  Msg( +
                 'Member name is a required parameter')
               Return
               EndDo
    /***********************************************/
    /* Open the file without LVLCHK and with our   */
    /*   own buffer.                               */
    /*                                             */
    /* Read the first record of the specified      */
    /*   member.                                   */
    /*                                             */
    /* Enter a DoWhile loop conditioned by End of  */
    /*   File (&EOF).  So long as EOF is not       */
    /*   detected:                                 */
    /*   1. Send the line of source read to the    */
    /*      default (*PRV) call message queue      */
    /*   2. Read the next QCLSRC record and loop   */
    /***********************************************/
    OpnFCLF    FileID(QCLSRC) Mbr(&Member) LvlChk(*No)
    ReadRcdCLF FileID(QCLSRC) EOF(&EOF) RcdBuf(&RcdDta)
    DoWhile    Cond(*Not &EOF)
               ChgVar Var(&SrcDta) +
                 Value(%sst(&RcdDta 13 80))
               SndPgmMsg Msg(&SrcDta)
               ReadRcdCLF FileID(QCLSRC) EOF(&EOF) +
                 RcdBuf(&RcdDta)
               EndDo
    /***********************************************/
    /* When End of File is detected close the file */
    /* and return.                                 */
    /***********************************************/
    CloFCLF    FileID(QCLSRC)
    EndPgm

 

The source for the example can be found in member BAS_OPNF of source file VC2CLSRC in library VC2CLF.

To compile BAS_OPNF you can use the IBM provided commands CRTBNDCL or CRTCLPGM (in addition to the CLF precompiler commands). The precompiler is not necessary as the program is only using CLF runtime support.

To compile BAS_OPNF into QTEMP you can use the command

 

    CrtBndCL Pgm(QTEMP/BAS_OPNF) SrcFile(VC2CLF/VC2CLSRC)

 

To run the program you can use any of the following commands

 

    Call Pgm(BAS_OPNF) Parm(BAS_OPNF) - list member BAS_OPNF
    Call Pgm(BAS_OPNF) Parm(*First)   - list the first member
    Call Pgm(BAS_OPNF) Parm(*All)     - list all members

 

Example 4: Opening Database and Display Files with External Definitions

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP,    */
    /* display file VC2EMPDSP1, and indicators     */
    /* associated with CLF Input/Output commands   */
    /***********************************************/
    DclFCLF    FileID(VC2EMP)
    DclFCLF    FileID(VC2EMPDSP1)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Declare the packed decimal field &RcdCnt    */
    /* that will be used to determine the current  */
    /* record count.  If the file is empty         */
    /* (&RCDCNT = 0), prompt with how to load the  */
    /* VC2DPT file with sample data.               */
    /***********************************************/
    Dcl        Var(&RcdCnt) Type(*Dec) Len(10 0)
    /***********************************************/
    /* Open VC2EMP and verify that records have    */
    /* been loaded into the file.  If not, tell    */
    /* the user how to load records.               */
    /***********************************************/
    OpnFCLF    FileID(VC2EMP) Usage(*Both) AccMth(*Key)
    RtvFInfCLF FileID(VC2EMP) NbrRcds(&RcdCnt)
    If         Cond(&RcdCnt = 0) Then(Do)
               OpnFCLF FileID(VC2FEMPTY) Usage(*Both) +
                         LvlChk(*No)
               WrtReadCLF FileID(VC2FEMPTY) RcdFmt(EmpEmp)
               CloFCLF FileID(VC2FEMPTY)
               CloFCLF FileID(VC2EMP)
               Return
               EndDo
    /***********************************************/
    /* Having verified that records exist now open */
    /* the display file for this program.          */
    /***********************************************/
    OpnFCLF    FileID(VC2EMPDSP1) Usage(*Both)
    /***********************************************/
    /* Enter a DOWHILE loop that is exited when    */
    /* command key 3 is pressed.                   */
    /*                                             */
    /* Within the loop:                            */
    /* 1 Write and read the VC2EMPDSP1 *DSPF       */
    /*   record format PROMPT.  PROMPT asks for    */
    /*   employee number.  A valid employee        */
    /*   number would be 00001.  The user can      */
    /*   press ENTER or command key 3.             */
    /* 2 If command key 3 was pressed leave the    */
    /*   DoWhile loop                              */
    /* 3 Read the employee record for the          */
    /*   employee number entered.                  */
    /* 4 If no record is found (&RNF is '1') a     */
    /*   message is displayed based on &IN50       */
    /* 5 If a record is found record format CHANGE */
    /*   is written and read.                      */
    /*   CHANGE allows the user to maintain        */
    /*   employee information (ENTER), delete the  */
    /*   employee (F23), return to PROMPT without  */
    /*   updating the employee record (F12), or    */
    /*   exit the application (F3).                */
    /* 6 The user is then returned to the PROMPT   */
    /*   display to enter the next employee        */
    /*   number                                    */
    /***********************************************/
    DoWhile    Cond(*Not &IN03)
               WrtReadCLF RcdFmt(PROMPT)
               If Cond(&IN03) Then(Leave)
               ReadRcdCLF FileID(VC2EMP) TYPE(*Key) +
                  RcdNotFnd(&RNF) KeyRel(*EQ) +
                  KeyList(&EmpNbr)
               If Cond(&RNF) Then(Do)
                  ChgVar Var(&IN50) Value('1')
                  Iterate
                  EndDo
               WrtReadCLF RcdFmt(CHANGE)
               Select
                  When Cond(&IN03) Then(Leave)
                  When Cond(&IN12) Then(Do)
                       RlsRcdCLF VC2EMP
                       Iterate
                       EndDo
                  When Cond(&IN23) Then(DltRcdCLF VC2EMP)
                  OtherWise Cmd(UpdRcdCLF FileID(VC2EMP))
                  EndSelect
               EndDo
    /***********************************************/
    /* When F3 is used to exit the DoWhile loop    */
    /* close the files and return                  */
    /***********************************************/
    CloFCLF    FileID(VC2EMP)
    CloFCLF    FileID(VC2EMPDSP1)
    EndPgm

 

This example opens the VC2EMP physical file for file maintenance. As the program allows a user to view, update, and delete records in the VC2EMP database the database file is opened for keyed IO and both read and write.

DEV_EMPU1, when initially called, verifies that there are records in the VC2EMP file. If not, the program displays a prompt to inform the caller that records need to be loaded prior to running the program. The display file used for this prompt, VC2FEMPTY, is not declared within the program using the DCLFCLF command. Because DCLFCLF was not used the developer needs to supply both the FILEID and the RCDFMT keywords when using the WRTREADCLF command with the record format EMPEMP. The developer does not have to specify both keywords when using the WRTREADCLF command with record formats of the VC2EMPDSP1 display file. In the case of VC2EMPDSP1 the developer used the DCLFCLF command and the precompiler is able to determine the FILEID to use based on only the RCDFMT keyword being provided by the developer.

The source for the example can be found in member DEV_EMPU1 of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF. The source for display file VC2EMPDSP1 can be found in member VC2EMPDSP1 of source file QDDSSRC in library VC2CLF. The source for display file VC2FEMPTY can be found in member VC2FEMPTY of source file QDDSSRC in library VC2CLF.

All objects referenced by DEV_EMPU1 should currently exist in library VC2CLF. To compile example DEV_EMPU1 into QTEMP you can use the commands

 

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

 

To test the program you can use the command

 

    Call Pgm(QTEMP/DEV_EMPU1)

 

From the prompt screen you can enter an employee number such as 52. After using the ENTER key you should see the details of employee 52's VC2EMP record. From this screen you can use command key 23 to delete the record, ENTER to update the record with any changes you may have keyed in, command key 12 to exit the screen without updating the record, and command key 3 to exit the program.

Example 5: Opening a Display File with a Separate Indicator Area

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP,    */
    /* display file VC2EMPDSP2 that is defined     */
    /* with INDARA specified, and indicators       */
    /* for both a separate indicator area and for  */
    /* CLF I/O related commands                    */
    /***********************************************/
    DclFCLF    FileID(VC2EMP)
    DclFCLF    FileID(VC2EMPDSP2)
    DclIndCLF  CLFInd(*Yes) IndAra(*Yes)
    /***********************************************/
    /* Open the two files.                         */
    /*                                             */
    /* VC2EMPDSP2 is opened with a SEPINDARA(*YES) */
    /***********************************************/
    OpnFCLF    FileID(VC2EMP) Usage(*Both) AccMth(*Key)
    OpnFCLF    FileID(VC2EMPDSP2) Usage(*Both) +
                 SepIndAra(*Yes)
    /***********************************************/
    /* Enter a DOWHILE loop that is exited when    */
    /* command key 3 is pressed.                   */
    /*                                             */
    /* Within the loop:                            */
    /* 1 Write and read the VC2EMPDSP2 *DSPF       */
    /*   record format PROMPT.  PROMPT asks for    */
    /*   employee number.  A valid employee        */
    /*   number would be 00001.  The user can      */
    /*   press ENTER or command key 3.             */
    /* 2 If command key 3 was pressed leave the    */
    /*   DoWhile loop                              */
    /* 3 Read the employee record for the          */
    /*   employee number entered.                  */
    /* 4 If no record is found (&RNF is '1') a     */
    /*   message is displayed based on &IN50       */
    /* 5 If a record is found record format CHANGE */
    /*   is written and read.                      */
    /*   CHANGE allows the user to maintain        */
    /*   employee information (ENTER), delete the  */
    /*   employee (F23), return to PROMPT without  */
    /*   updating the employee record (F12), or    */
    /*   exit the application (F3).                */
    /* 6 The user is then returned to the PROMPT   */
    /*   display to enter the next employee        */
    /*   number                                    */
    /***********************************************/
    DoWhile    Cond(*Not &IN03)
               WrtReadCLF RcdFmt(Prompt)
               If Cond(&IN03) Then(Leave)
                  ReadRcdCLF FileID(VC2EMP) Type(*Key) +
                    RcdNotFnd(&RNF) KeyRel(*EQ) +
                    KeyList(&EmpNbr)
               If Cond(&RNF) Then(Do)
                  ChgVar Var(&IN50) Value('1')
                  Iterate
                  EndDo
               WrtReadCLF RcdFmt(Change)
               Select
                  When Cond(&IN03) Then(Leave)
                  When Cond(&IN12) Then(Do)
                       RlsRcdCLF VC2EMP
                       Iterate
                       EndDo
                  When Cond(&IN23) Then(DltRcdCLF VC2EMP)
                  OtherWise Cmd(UpdRcdCLF FileID(VC2EMP))
                  EndSelect
               EndDo
    /***********************************************/
    /* When F3 is used to exit the DoWhile loop    */
    /* close the files and return                  */
    /***********************************************/
    CloFCLF    FileID(VC2EMP)
    CloFCLF    FileID(VC2EMPDSP2)
    EndPgm

 

This example demonstrates the use of a separate indicator area when using a display file. The only significant changes from the DEV_EMPU1 sample program are:

  • changing the display file from VC2EMPDSP1 to VC2EMPDSP2
  • adding INDARA(*YES) to the DCLINDCLF command
  • adding SEPINDARA(*YES) to the OPNFCLF command for display file VC2EMPDSP2

The source for the example can be found in member DEV_EMPUS of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF. The source for display file VC2EMPDSP2 can be found in member VC2EMPDSP2 of source file QDDSSRC in library VC2CLF.

The display file DC2EMPDSP2 should currently exist in library VC2CLF. To compile example DEV_EMPUS into QTEMP you can use the commands

 

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

 

To test the program you can use the command

 

    Call Pgm(QTEMP/DEV_EMPUS)

 

From the prompt screen you can enter an employee number such as 52. After using the ENTER key you should see the details of employee 52's VC2EMP record. From this screen you can use command key 23 to delete the record, ENTER to update the record with any changes you may have keyed in, command key 12 to exit the screen without updating the record, and command key 3 to exit the program.

Example 6: Opening Database and Printer Files with External Definitions

 

    Pgm
    /***********************************************/
    /* This program creates a printed report       */
    /* listing employees in key sequence using     */
    /* the VC2EMPDPT access path (Dept/First name) */
    /***********************************************/
    /***********************************************/
    /* Declare two working variables:              */
    /* &CURLIN - the current line number printed   */
    /* &PAGOVR - the overflow line number for a    */
    /*           page                              */
    /***********************************************/
    Dcl        Var(&CurLin) Type(*Dec) Len(3 0)
    Dcl        Var(&PagOvr) Type(*Dec) Len(3 0)
    /***********************************************/
    /* Declare our files and indicators            */
    /* VC2EMPDPT - Employees by department         */
    /* VC2POSPRT - External printer file           */
    /* CLF Indicators - &EOF used in program       */
    /***********************************************/
    DclFCLF    FileID(VC2EMPDPT)
    DclFCLF    FileID(VC2POSPRT)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Open the files                              */
    /***********************************************/
    OpnFCLF    FileID(VC2EMPDPT) AccMth(*Key)
    OpnFCLF    FileID(VC2POSPRT) Usage(*Output)
    /***********************************************/
    /* Retrieve the page overflow line number      */
    /***********************************************/
    RtvFInfCLF FileID(VC2POSPRT) PrtFOvrFlw(&PagOvr)
    /***********************************************/
    /* Write titles for report on first page       */
    /***********************************************/
    WrtRcdCLF  RcdFmt(HEADING)
    /***********************************************/
    /* Read the first record from VC2EMPDPT        */
    /***********************************************/
    ReadRcdCLF FileID(VC2EMPDPT) EOF(&EOF)
    DoWhile    Cond(*Not &EOF)
               /**********************************************/
               /* While we have not reached End of File      */
               /* on VC2EMPDPT:                              */
               /* 1 Retrieve the current print line number   */
               /* 2 If the current print line number is      */
               /*   greater than or equal to the overflow    */
               /*   line number then start a new page and    */
               /*   re-write titles on the page              */
               /* 3 Write the detail employee print line     */
               /* 4 Read the next employee record            */
               /* 5 Continue in this loop until End of File  */
               /**********************************************/
               RtvFInfCLF FileID(VC2POSPRT) CurPrtLine(&CurLin)
               If Cond(&CurLin *GE &PagOvr) Then( +
                  WrtRcdCLF RcdFmt(HEADING))
               WrtRcdCLF RcdFmt(DETAILS)
               ReadRcdCLF FileID(VC2EMPDPT) EOF(&EOF)
               EndDo
    /***********************************************/
    /* At End of File close the files and return   */
    /***********************************************/
    CloFCLF    VC2EMPDPT
    CloFCLF    VC2POSPRT
    EndPgm

 

The example program opens the VC2EMPDPT logical file and creates a report using the external printer file VC2POSPRT. The report lists all employees in the CLF provided sample database. The VC2EMPDPT logical file is keyed by employee first name within department.

The source for the example can be found in member DEV_POSPRT of source file VC2CLSRC in library VC2CLF. The source for logical file VC2EMPDPT can be found in member VC2EMPDPT of source file QDDSSRC in library VC2CLF. The source for printer file VC2POSPRT can be found in member VC2POSPRT of source file QDDSSRC in library VC2CLF.

The logical file VC2EMPDPT and printer file VC2POSPRT should currently exist in library VC2CLF. To compile the DEV_POSPRT program into QTEMP you can use the commands

 

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

 

To run the program you can call it using the command

 

    Call Pgm(QTEMP/DEV_POSPRT)

 

Example 7: Opening a Database File Under Commitment Control

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP and */
    /* indicators used with CLF I/O Commands       */
    /***********************************************/
    DclFCLF    FileID(VC2EMP)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Declare &ANSWER variable.  This is used to  */
    /* control whether program commits or rolls    */
    /* back database changes                       */
    /***********************************************/
    Dcl        Var(&Answer) Type(*Char) Len(1)
    /***********************************************/
    /* Setup logic that would not typically be     */
    /* in an application program.  For             */
    /* 1 End journaling of VC2EMP if it is active  */
    /*   (it should not be)                        */
    /* 2 Delete journal CLFJRN in VC2CLF if it     */
    /*   exists (it should not)                    */
    /* 3 Delete journal receiver CLFJRNRCV in      */
    /*   VC2CLF if it exists (it should not)       */
    /* 4 Create journal receiver CLFJRNRCV         */
    /* 5 Clears physical file VC2EMP and VC2DPT    */
    /* 6 Creates example program DEV_LOAD (that    */
    /*   loads records into the VC2EMP and         */
    /*   VC2DPT database files) into QTEMP         */
    /* 7 Calls DEV_LOAD                            */
    /* 8 Starts journaling of VC2EMP               */
    /* 9 Starts commitment control                 */
    /***********************************************/
    EndJrnPF   File(VC2CLF/VC2EMP)
               MonMsg MsgID(CPF0000)
    DltJrn     Jrn(VC2CLF/CLFJRN)
               MonMsg MsgID(CPF0000)
    DltJrnRcv  JrnRcv(VC2CLF/CLFJRNRCV) DltOpt(*IgnInqMsg)
               MonMsg MsgID(CPF0000)
    CrtJrnRcv  JrnRcv(VC2CLF/CLFJRNRCV)
    CrtJrn     Jrn(VC2CLF/CLFJRN) JrnRcv(VC2CLF/CLFJRNRCV)
    ClrPFM     File(VC2CLF/VC2EMP)
    ClrPFM     File(VC2CLF/VC2DPT)
    CrtBndCLF  Pgm(QTEMP/DEV_LOAD) SrcFile(VC2CLF/VC2CLSRC)
    Call       Pgm(QTEMP/DEV_LOAD)
    StrJrnPF   File(VC2CLF/VC2EMP) Jrn(VC2CLF/CLFJRN) +
                 Images(*Both)
    StrCmtCtl  LckLvl(*Chg)
    /***********************************************/
    /* With setup done, the application program:   */
    /* 1 Opens the VC2EMP database file for both   */
    /*   input and output, keyed access, and under */
    /*   commitment control                        */
    /* 2 Reads by key the employee record for      */
    /*   employee number 52                        */
    /* 3 If employee 52 is not found then the      */
    /*   previous setup logic failed and the       */
    /*   program displays an error message         */
    /* 4 If employee 52 is found the program:      */
    /*   4A Deletes the employee                   */
    /*   4B Prompts the user to commit the         */
    /*      deletion of employee 52                */
    /*   4C If the user responds 'Y' the delete    */
    /*      is committed                           */
    /*      If the user responds 'N' the delete    */
    /*      is rolled back                         */
    /* 5 Reads by key the employee record for      */
    /*   employee number 52                        */
    /* 6 Displays a message to the user about      */
    /*   whether or not the record was found       */
    /***********************************************/
    OpnFCLF    FileID(VC2EMP) Usage(*Both) AccMth(*Key) +
                 CmtCtl(*Yes)
    ReadRcdCLF FileID(VC2EMP) Type(*Key) RcdNotFnd(&RNF) +
                 KeyRel(*EQ) KeyList(52)
    If         Cond(&RNF) Then(SndUsrMsg MsgID(VC25051) +
                 MsgF(VC2CLF/VC2MSG))
    Else       Cmd(Do)
                  DltRcdCLF  FileID(VC2EMP)
                  SndUsrMsg  Msg('Commit delete?  Y or N') +
                    Values(Y N) MsgRpy(&Answer)
                  If Cond(&Answer *EQ Y) Then(Commit)
                  Else Cmd(RollBack)
                  ReadRcdCLF FileID(VC2EMP) Type(*Key) +
                    RcdNotFnd(&RNF) KeyRel(*EQ) KeyList(52)
                  If Cond(&RNF) Then(SndUsrMsg +
                       MsgID(VC25052) MsgF(VC2CLF/VC2MSG))
                  Else Cmd(SndUsrMsg MsgID(VC25053) +
                       MsgF(VC2CLF/VC2MSG))
               EndDo
    /***********************************************/
    /* Having completed the transaction the        */
    /* program now:                                */
    /* 1 Closes the VC2EMP database file           */
    /* 2 Ends commitment control                   */
    /* 3 Ends journaling of VC2EMP                 */
    /* 4 Deletes the journal CLFJRN                */
    /* 5 Deletes the journal receiver CLFJRNRCV    */
    /* 6 Returns                                   */
    /***********************************************/
    CloFCLF    FileID(VC2EMP)
    EndCmtCtl
    EndJrnPF   File(VC2CLF/VC2EMP)
    DltJrn     Jrn(VC2CLF/CLFJRN)
    DltJrnRcv  JrnRcv(VC2CLF/CLFJRNRCV) DltOpt(*IgnInqMsg)
    EndPgm

 

The source for the example can be found in member DEV_CMTCTL of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.

To compile DEV_CMTCTL into QTEMP you can use the command

 

    CrtBndCLF Pgm(QTEMP/DEV_CMTCTL) SrcFile(VC2CLF/VC2CLSRC)

 

To run the program you can use the command

 

    Call Pgm(QTEMP/DEV_CMTCTL)

 

Example 8: Sharing a FILEID Across Programs

This example includes two programs. The first program, DEV_SHROPN, opens the VC2EMP database file for input processing and reads one record. The second program, DEV_SHRCLO, reads one record from the open FILEID of DEV_SHROPN and then closes the file. The record read by DEV_SHRCLO is actually the second record of the VC2EMP file as it's position in the file is determined by the last user of the shared FILEID. In this case the program DEV_SHROPN.

This is the source for the DEV_SHROPN program.

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP and */
    /* indicators used with CLF I/O Commands       */
    /***********************************************/
    DclFCLF    FileID(VC2EMP)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Open the Employee master file VC2EMP in     */
    /*   arrival sequence                          */
    /* Read the first record in the file           */
    /* Send a message showing what record was read */
    /***********************************************/
    OpnFCLF    FileID(VC2EMP) ERR(&ERR)
    If         Cond(&ERR) Then(Do)
               SndPgmMsg  Msg( +
                'Error doing shared open from DEV_SHROPN')
               Return
               EndDo
    ReadRcdCLF FileID(VC2EMP)
    SndPgmMsg  Msg('DEV_SHROPN found' *BCat &EmpFName)
    /***********************************************/
    /* Call the DEV_SHRCLO example program.        */
    /*                                             */
    /* DEV_SHRCLO will use the open of VC2EMP      */
    /*   performed in this program and, after      */
    /*   reading one record, close VC2EMP          */
    /***********************************************/
    Call       Pgm(DEV_SHRCLO)
    /***********************************************/
    /* Upon return from DEV_SHRCLO attempt to read */
    /*   the next record from the VC2EMP file.     */
    /*                                             */
    /* An error should be returned from READRCDCLF */
    /*   as VC2EMP has been closed.                */
    /* The program will send a message based on    */
    /*   the &ERR indicator returned by READRCDCLF */
    /***********************************************/
    ReadRcdCLF FileID(VC2EMP) ERR(&ERR)
    If         Cond(*Not &ERR) Then(SndPgmMsg +
                  msg('DEV_SHRCLO did not close VC2EMP'))
    Else       Cmd(SndPgmMsg Msg( +
                  'The file was closed by DEV_SHRCLO'))
    /***********************************************/
    /* The program now returns.                    */
    /*                                             */
    /* DEV_SHROPN could use the CLOFCLF command    */
    /* to close the file even though it is not     */
    /* open.  Closing a file that is not open      */
    /* will result in a diagnostic message, but    */
    /* not a severe error.                         */
    /***********************************************/
    EndPgm

 

The source for this example can be found in member DEV_SHROPN of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.

To compile this example you can use the command

 

    CrtBndCLF Pgm(VC2CLF/DEV_SHROPN) SrcFile(VC2CLF/DEV_SHROPN)

 

This example program does need to be compiled into the VC2CLF library as that library name is hardcoded in program DEV_SHRCLO for the OPNPGM keyword of several CLF commands.

This is the source for the DEV_SHRCLO program.

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP and */
    /* CLF-related indicators                      */
    /***********************************************/
    DclFCLF    FileID(VC2EMP)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Open the VC2EMP file using the open         */
    /*   done in VC2CLF/SHROPN                     */
    /***********************************************/
    OpnFCLF    FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN) +
                 ERR(&ERR)
    If         Cond(&ERR) Then(Do)
               SndPgmMsg  Msg( +
                'Error doing shared open from DEV_SHRCLO')
               Return
               EndDo
    /***********************************************/
    /* Read the next record from VC2EMP.           */
    /*                                             */
    /* As DEV_SHROPN read one record (Rebecca)     */
    /*   this read should be the second record     */
    /*   in arrival sequence (Bruce)               */
    /* The program sends a message showing what    */
    /*   record was read                           */
    /***********************************************/
    ReadRcdCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN)
    SndPgmMsg  Msg('DEV_SHRCLO found' *BCat &EmpFName)
    /***********************************************/
    /* DEV_SHRCLO now closes the file initially    */
    /*   opened by VC2CLF/SHROPN.  This also       */
    /*   closes the file for VC2CLF/SHROPN         */
    /***********************************************/
    CloFCLF    FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN)
    EndPgm

 

The source for this example can be found in member DEV_SHRCLO of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.

To compile this example you can use the command

 

    CrtBndCLF Pgm(VC2CLF/DEV_SHRCLO) SrcFile(VC2CLF/VC2CLSRC)

 

After creating both DEV_SHROPN and DEV_SHRCLO you can call the sample programs with the command

 

    Call Pgm(VC2CLF/DEV_SHROPN)

 

Top

Error messages for OPNFCLF

*ESCAPE Messages

VC25017
File ID &2 not opened.
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.
Top
 
Joomla 1.5 Templates by Joomlashack