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 for Processing (OPEN)

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

The Open File for Processing (OPEN) command opens a file for further processing by the application.

If at least one file is declared using the FILE command reference information for all files opened using the OPEN command will be reflected in the application program and module. This information can be accessed using the Display Program References (DSPPGMREF) command and is based on the OPEN keyword parameters FILE and USAGE. If the USAGE keyword value is a parameter the file reference usage information will be identified as unspecified.

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

Restrictions:

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

Parameters

KeywordDescriptionChoicesNotes
FILEID File identifier Simple name Optional, Positional 1
USAGE File usage *INPUT, *OUTPUT, *BOTH Optional
ACCMTH Access method *RRN, *KEY Optional
ERR Error found Logical value Optional
FILE File Qualified object name Optional
Qualifier 1: File Name, *CALC, *FILEID
Qualifier 2: Library Name, *LIBL, *CURLIB
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
SEPINDARA Separate indicator area *NO, *YES Optional
INDARA Indicator area variable 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 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

Access method (ACCMTH)

Specifies if the application will be accessing records using key values or by relative positions.

*RRN
Relative record numbers are used to process the file.
*KEY
Key values are used to process the file. Keyed operations are only valid for database files.
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 (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.

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.

If the file was not declared using the DCLFCLF command *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 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 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

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 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.

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)

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

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

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

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

Single values: Program opening file

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

Qualifier 1: Program opening file

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

Qualifier 2: Library

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

Examples for OPEN

Example 1: Opening a Keyed Database File

 

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

 

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

Example 2: Opening a File as Externally Described

 

    /******************************************************/
    /* This program has 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)                     */
    /******************************************************/
    File       FileID(QCLSRC)
    Inds       CLFInd(*Yes)
    /******************************************************/
    /* Test to see if the &MEMBER parameter was passed    */
    /* (only needed for ILE 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          */
    /******************************************************/
    Open       FileID(QCLSRC) Mbr(&Member)
    Read       FileID(QCLSRC) EOF(&EOF)
    DoWhile    Cond(*Not &EOF)
               SndPgmMsg Msg(&SrcDta)
               Read QCLSRC EOF(&EOF)
               EndDo
    /******************************************************/
    /* When End of File close the file and return         */
    /******************************************************/
    Close      QCLSRC
    EndPgm

 

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

To compile RPG_OPNF into QTEMP you can use the command

 

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

 

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

 

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

 

Example 3: Opening Database and Display Files with External Definitions

 

    Pgm
    /******************************************************/
    /* Declare the Employee master file VC2EMP, display   */
    /* VC2EMPDSP1, and CLF related indicators             */
    /******************************************************/
    File       FileID(VC2EMP)
    File       FileID(VC2EMPDSP1)
    Inds       CLFInd(*Yes)
    /******************************************************/
    /* Declare the packed decimal field &RcdCnt. This     */
    /* will be used to determine the current record count */
    /* of VC2EMP. If the file is empty (&RCDCNT = 0),     */
    /* prompt with how to load the 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 */
    /******************************************************/
    Open       FileID(VC2EMP) Usage(*Both) AccMth(*Key)
    RtvFInfCLF VC2EMP NbrRcds(&RcdCnt)
    If         Cond(&RcdCnt = 0) Then(Do)
               Open VC2FEMPTY Usage(*Both) LvlChk(*No)
               Exfmt FileID(VC2FEmpty) RcdFmt(EMPEMP)
               Close VC2FEMPTY
               Close VC2EMP
               Return
               EndDo
    /******************************************************/
    /* Having verified that records exist now open the    */
    /* display file for the program.                      */
    /******************************************************/
    Open       VC2EMPDSP1 Usage(*Both)
    /******************************************************/
    /* Enter a DOWHILE loop until F3 is used              */
    /*                                                    */
    /* Within the loop:                                   */
    /* 1 Write and read the VC2EMPDSP1 *DSPF record       */
    /*   format PROMPT. PROMPT asks for an employee       */
    /*   number. A valid employee would be 1. The user    */
    /*   can press ENTER or F3 from PROMPT.               */
    /* 2 If F3 is pressed leave the DoWhile loop          */
    /* 3 Otherwise 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)
               Exfmt RcdFmt(PROMPT)
               If Cond(&IN03) Then(Leave)
                  Chain &EmpNbr VC2EMP RcdNotFnd(&RNF)
               If Cond(&RNF) Then(Do)
                  ChgVar Var(&IN50) Value('1')
                  Iterate
                  EndDo
               Exfmt RcdFmt(CHANGE)
               Select
                  When Cond(&IN03) Then(Leave)
                  When Cond(&IN12) Then(Do)
                       UnLock VC2EMP
                       Iterate
                       EndDo
                  When Cond(&IN23) Then(Delete VC2EMP)
                  OtherWise Cmd(Update VC2EMP)
                  EndSelect
               EndDo
    /******************************************************/
    /* When F3 is used close the files and return         */
    /******************************************************/
    Close      VC2EMP
    Close      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.

RPG_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 EXFMT command with the record format EMPEMP. The developer does not have to specify both keywords when using the EXFMT 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 RPG_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 RPG_EMPU1 should currently exist in library VC2CLF. To compile example RPG_EMPU1 into QTEMP you can use the commands

 

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

 

To test the program you can use the command

 

    Call Pgm(QTEMP/RPG_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 4: 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                    */
    /***********************************************/
    File       FileID(VC2EMP)
    File       FileID(VC2EMPDSP2)
    Inds       CLFInd(*Yes) IndAra(*Yes)
    /***********************************************/
    /* Open the two files.                         */
    /*                                             */
    /* VC2EMPDSP2 is opened with a SEPINDARA(*YES) */
    /***********************************************/
    Open       FileID(VC2EMP) Usage(*Both) AccMth(*Key)
    Open       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)
               ExFmt RcdFmt(PROMPT)
               If Cond(&IN03) Then(Leave)
               Chain &EmpNbr FileID(VC2EMP) +
                        RcdNotFnd(&RNF)
               If Cond(&RNF) Then(Do)
                  ChgVar Var(&IN50) Value('1')
                  Iterate
                  EndDo
               ExFmt RcdFmt(CHANGE)
               Select
                  When Cond(&IN03) Then(Leave)
                  When Cond(&IN12) Then(Do)
                       UnLock VC2EMP
                       Iterate
                       EndDo
                  When Cond(&IN23) Then(Delete VC2EMP)
                  OtherWise Cmd(Update VC2EMP)
                  EndSelect
               EndDo
    /***********************************************/
    /* When F3 is used to exit the DoWhile loop    */
    /* close the files and return                  */
    /***********************************************/
    Close      VC2EMP
    Close      VC2EMPDSP2
    EndPgm

 

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

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

The source for the example can be found in member RPG_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 RPG_EMPUS into QTEMP you can use the commands

 

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

 

To test the program you can use the command

 

    Call Pgm(QTEMP/RPG_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 5: 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            */
    /******************************************************/
    File       FileID(VC2EMPDPT)
    File       FileID(VC2POSPRT)
    Inds       CLFInd(*Yes)
    /******************************************************/
    /* Open the files                                     */
    /******************************************************/
    Open       FileID(VC2EMPDPT) AccMth(*KEY)
    Open       VC2POSPRT Usage(*Output)
    /******************************************************/
    /* Retrieve the page overflow line number             */
    /******************************************************/
    RtvFInfCLF FileID(VC2POSPRT) PrtFOvrFlw(&PagOvr)
    /******************************************************/
    /* Write titles for report on first page              */
    /******************************************************/
    Write      RcdFmt(HEADING)
    /******************************************************/
    /* Read the first record from VC2EMPDPT               */
    /******************************************************/
    Read       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 until End of File            */
               /*******************************************/
               RtvFInfCLF VC2POSPRT CurPrtLine(&CurLin)
               If Cond(&CurLin *GE &PagOvr) Then( +
                  Write RcdFmt(HEADING))
               Write RcdFmt(DETAILS)
               Read VC2EMPDPT EOF(&EOF)
               EndDo
    /******************************************************/
    /* At End of File close the files and return          */
    /******************************************************/
    Close      OPNID(VC2EMPDPT)
    Close      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 databases. The VC2EMPDPT logical file is keyed by employee first name within department.

The source for the example can be found in member RPG_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 RPG_POSPRT program into QTEMP you can use the commands

 

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

 

Example 6: Opening a Database File Under Commitment Control

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP and */
    /* indicators used with CLF I/O Commands       */
    /***********************************************/
    File       FileID(VC2EMP)
    Inds       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 file) 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       */
    /***********************************************/
    Open       FileID(VC2EMP) Usage(*Both) AccMth(*Key) +
                 CmtCtl(*Yes)
    Chain      (52) VC2EMP RcdNotFnd(&RNF)
    If         Cond(&RNF) Then(SndUsrMsg MsgID(VC25051) +
                 MsgF(VC2CLF/VC2MSG))
    Else       Cmd(Do)
                  Delete  FileID(VC2EMP)
                  SndUsrMsg  Msg('Commit delete?  Y or N') +
                    Values(Y N) MsgRpy(&Answer)
                  If Cond(&Answer *EQ Y) Then(Commit)
                  Else Cmd(RollBack)
                  Chain (52) VC2EMP RcdNotFnd(&RNF)
                  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                                   */
    /***********************************************/
    Close      OpnID(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 RPG_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.

The VC2EMP database file should currently exist in library VC2CLF. To create RPG_CMTCTL into QTEMP you can use the commands

 

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

 

To run RPG_CMTCTL you can use the command

 

    Call Pgm(QTEMP/RPG_CMTCTL)

 

Top

Error messages for OPEN

*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