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

Delete Record using CLF (DLTRCDCLF)

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

The Delete Record using CLF (DLTRCDCLF) command is used by a CL program to delete a record in a database file. The command deletes the currently locked record of the file.

Restrictions:

  • This command is valid only within a CL program.
  • The file identified by the FILEID parameter must have been previously opened using the Open File using CLF (OPNFCLF) command with USAGE(*BOTH).
  • The record being deleted must have been previously read.
  • This command is only valid for database and DDM files.
  • The user must have delete (*DLT) data authority to the file.
  • 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
ERR Error found Logical value 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.

This is a required parameter.

simple-name
Specify a name that matches the FILEID parameter value of a previous OPNFCLF command.
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

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 DLTRCDCLF

Example 1: Delete a Database Record

 

    DltRcdCLF  FileID(EMPMST)

 

This command deletes the currently locked record from the file opened with a FILEID of EMPMST.

Example 2: Delete a Database Record

The DLTRCDCLF command is run when the user presses command key 23 from the CHANGE record format.

 

    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 3: Detecting an Error

 

    Pgm
    /***********************************************/
    /* Declare the Employee master file VC2EMP     */
    /* and indicators associated with CLF Input    */
    /* and Output commands                         */
    /***********************************************/
    DclFCLF    FileID(VC2EMP)
    DclIndCLF  CLFInd(*Yes)
    /***********************************************/
    /* Open the VC2EMP file                        */
    /***********************************************/
    OpnFCLF    FileID(VC2EMP) Usage(*Both) +
                 AccMth(*Key)
    /***********************************************/
    /* Delete a record in VC2EMP without having    */
    /* previously read a record from the file      */
    /*                                             */
    /***********************************************/
    /*                                             */
    /* This is an error -- a record must be read   */
    /* for update before attempting to delete it   */
    /*                                             */
    /***********************************************/
    DltRcdCLF  FileID(VC2EMP) ERR(&ERR)
    /***********************************************/
    /* Check the &ERR variable that was used with  */
    /* the ERR keyword in the previous DLTRCDCLF   */
    /* command.                                    */
    /* If ON ('1') an error was found with         */
    /*    DLTRCDCLF                                */
    /* If OFF ('0') no error was found with        */
    /*    DLTRCDCLF                                */
    /***********************************************/
    If         Cond(&ERR) Then(SndUsrMsg Msg('Delete +
                 operation failed'))
    Else       Cmd(SndUsrMsg Msg('Test program failed'))
    /***********************************************/
    /* Close the file and return                   */
    /***********************************************/
    CloFCLF    FileID(VC2EMP)
    EndPgm

 

This example demonstrates one way to check for an error when using the DLTRCDCLF command. If the ERR parameter is not used then escape message VC25038 will be sent if an error is encountered. The program could then use the MONMSG command to detect that an error has been encountered.

The source for this example can be found in member DEV_DLTERR 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 example DEV_DLTERR use either Create Bound CLF Program (CRTBNDCLF) or Create CLF Program (CRTCLFPGM).

Top

Error messages for DLTRCDCLF

*ESCAPE Messages

VC25011
File &1 is not open for update.
VC2502E
File ID &1 is not open.
VC25038
Delete operation to file ID &2 not successful.
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