TAADBFW         RETRIEVE DELETED RECORDS               TAADBFW

 The Retrieve  Deleted Records command  allows the retrieval  of deleted
 records  from a  physical file.   Some  restrictions  exist such  as no
 variable  length  records,  null fields,  or  REUSEDLT(*YES).   Deleted
 records cannot be retrieved if RGZPFM occurs or CLRPFM.

 A typical command would be:

         RTVDLTRCD   FROMFILE(xxx) TOFILELIB(yyy)

 This would extract the deleted  records in the FROMFILE and  write them
 to the same named file in the library specified for TOFILELIB.

 When a  record is deleted  in a data  base file, the data  values still
 exist,  but  the system  places a  special hex  value  in front  of the
 record specifying that  it is deleted.   The Operating System  prevents
 any access to a deleted record thru its normal interfaces.

 When  the file  is  saved, all  the information  from  both active  and
 deleted  records are saved.   The RTVDLTRCD command saves  the file you
 specified to a  save file  and then  searches for  the deleted  records
 and writes them to the same file name in a different library.

 When a file  is cleared, the end of  file indicator is set back  to the
 beginning  of  the  file  and  the  records cannot  be  retrieved  with
 RTVDLTRCD.    When a  file  is reorganized,  the  data is  copied  to a
 temporary  file  without  the  deleted  records.    Therefore,  deleted
 records cannot be retrieved after RGZPFM.

 There are a few things to consider:

   **   RTVDLTRCD can  only be  used by  the owner of  the file,  if the
        owner  is the group profile of the  current user, or a user with
        *ALLOBJ authority.

   **   A file of  the same  name as  the file you  are retrieving  from
        must  not  exist  in  the  TOFILELIB.     A  new  file  will  be
        automatically created using the format of the FROMFILE.

   **   An option  exists to allow a relative  record number field to be
        added to the new  file.  This will  contain the relative  record
        number of where the record was found in the FROMFILE.

   **   Files  with  variable  length fields  or  null  fields  are  not
        supported.

   **   No  date information is  kept by the  system on when  the record
        was deleted.

   **   Files  with Date  (L), Time  (T), or  Timestamp (Z)  type fields
        are supported.   Although the  system keeps  the data for  these
        fields  in  a  different  format   that  is  seen  in  the  data
        management  buffer, RTVDLTRCD simulates what  the system does to
        map the data  into a  record buffer before  writing the  record.
        There  is  a restriction  where  these  types of  fields  cannot
        exist  in  the  first  5  positions  of  the  record.   See  the
        following discussions.

 If the records  retrieved contain only  blanks or zeros,  see the  next
 two sections.

 How RTVDLTRCD operates internally
 ---------------------------------

 The file is checked  to ensure it contains deleted records  and if none
 exist, an error message occurs.

 The file  definition is checked  to determine if any  field types (such
 as  variable  length)  exist  and  if  so,  RTVDLTRCD  sends  an  error
 message.

 If Date, Time, or  Timestamp fields exist, the actual record  length of
 the  record  when Saved  is  calculated (this  will  be  less than  the
 external record length as seen by DSPFD).

 A  duplicate file definition  is created in  QTEMP and  a single record
 is initialized  in  this file.    The record  is  then updated  so  the
 characters *TAA* exist in positions 1 - 5.

 The  real  file data  is  then  copied  (added  to) to  this  duplicate
 version.   A save  file is  created in QTEMP  and the QTEMP  version of
 the file is saved.

 The save file data is then read  by a program that scans for the  first
 record (the *TAA* record).   Once it is found, the  program knows where
 to start in the save file data to check for records.

 Each  record is preceded  by a single  byte that determines  whether it
 is  a 'live' or 'deleted'  record.  When a  deleted record is found, it
 is written to  the file in the  TOFILELIB parameter.  Special  handling
 must occur  if any Date,  Time, or Timestamp  fields exist as  the data
 must  be  reformatted  to appear  in  the buffer  as  expected  by data
 management.

 Determining if deleted records contain blanks or zeros
 ------------------------------------------------------

 In some  cases  RTVDLTRCD may  produce a  new  file that  contains  all
 blanks and zeros for  data.  This may be due to  an application program
 which initializes the format of the record before deleting it.

 You  can determine if the  deleted records actually  contain blanks and
 zeros by using the CHKDLTRCD command  (part of the RTVDLTRCD tool)  for
 most files.  See the alternative discussion for files that contain:

         - Null values
         - Date/time fields
         - Variable length fields
         - Reuse deleted records

 Do the following:

   **   Use  PRTDLTRCD for  the file  and  member.   This  will print  a
        listing of where  the deleted records are.   Try to find a range
        where   several  deleted  records   exist  consecutively.    For
        example, if  the listing  shows  a 'Start  RR Nbr'  of 1000  and
        'Ending  RR Nbr'  of  1099, there  are  100 consecutive  deleted
        records  beginning at relative record number  1000.  If you have
        a reasonable range  of consecutive  deleted records, you  should
        have  the  information  you  need to  make  a  determination  if
        blanks and zeros exist.

   **   Determine the  relative record number of  the first record prior
        to a group of  consecutive deleted records.   In the example  of
        100  consecutive deleted  records  beginning at  1000,  relative
        record number 999 is the first active prior record.

   **   Determine a  unique value in  this active record.   Knowing what
        the   first  active  data  record   looks  like  will  help  you
        determine where  the deleted records  begin when  displayed.   A
        good tool to use is DSPDB:

              DSPDB    FILE(xxx) FROMRCD(nnn)

        Identify a unique  value in the record such as  few bytes from a
        name  field.  You need  to know the  approximate position in the
        record where the  unique value  exists and how  long the  record
        is.

   **   Enter the  following command using  the FROMRCD as  the relative
        record  number   of  the  first  active   record  prior  to  the
        consecutive group of deleted records  and the TORCD as the  last
        relative record number in the group.

              CHKDLTRCD     FILE(xxx) MBR(yyy) FROMRCD(nnn) TORCD(nnn)

        This will  create the TEMPFILE  in QTEMP,  by copying the  range
        of  relative  record  numbers   you  specified.    A  save  file
        (TEMPSAVF)  is then created in QTEMP,  and the created data base
        file is  saved.   The save  file is  then copied  to the  RCD528
        file in QTEMP and the file will be displayed using DSPPFM.

   **   Instructions  will appear about  how to  use the  DSPPFM display
        to  determine the  data in  your deleted records.   You  need to
        scan for  the  unique value  in  the  first active  record  (the
        beginning  of  the   file  has  a  good   deal  of  Save/Restore
        information that you want to bypass).

        Use  F10 to  display the  data in  hexadecimal.   Then determine
        whether the following deleted  records contain blanks or  zeros.

 Alternative method of determining if blanks or zeros exist
 ----------------------------------------------------------

 In  some  cases,  the previously  described  technique  will  not  work
 because  the  file  allows  null  fields,  variable length  fields,  or
 date/time  fields.  If  this is the  case or you  suspect that the file
 has good data  in the deleted  records that is  not being retrieved  by
 RTVDLTRCD, consider doing the following.

   **   Use  PRTDLTRCD as described  earlier to  find a  consecutive set
        of deleted record relative record numbers.

   **   You  will need  an arrival sequence  file to  access the records
        from.  If you do not have one, consider the use of CRTLFSRC.

             CRTLFSRC    LFFILE(xxx) PFILE(yyy) KEYFLD(*NONE)

        This will create  a logical  file in arrival  sequence based  on
        the PF  in the  same library.   QDDSSRC  is used  as the  source
        file.

   **   Determine a  unique value or values in  the record that precedes
        the the group  of deleted  records.   It could  be a  name or  a
        value.   A good  tool to use  is EDTDBF  on an  arrival sequence
        file such as:

             EDTDBF     FILE(xxx)

        When  the display appears,  use F14  to prompt for  the relative
        record  number  just  prior  to the  group  of  deleted records.
        Determine what unique values  exist that will help  you identify
        the record.  Character or zoned fields are required.

   **   Create a save file you can save the file to such as:

             CRTSAVF     FILE(sss)

   **   Use SAVOBJ to save the physical file to the save file.

             SAVOBJ      FILE(xxx) LIB(yyy) DEV(*SAVF)
                           SAVF(sss)

   **   Create a  physical file with  a length of  528 bytes.   A length
        of 528 is required when copying from a save file.

             CRTPF       FILE(PF528) RCDLEN(528)

   **   Use CPYFRMSAVF from the save file:

             CPYFRMSAVF  FILE(sss) TOFILE(PF528) MBROPT(*ADD)

   **   Use  DSPPFM and scan for  the unique value.   It may be possible
        that the unique value will span  one of the 528 byte records  so
        you may need to shorten the value when scanning.

   **   If  you   found  the  preceding   active  record,   the  records
        following should  be the deleted records.   Check the values for
        blanks/zeros  or  valid  data.     If  valid  data  exists   and
        RTVDLTRCD is  not extracting  the records,  report the error  to
        the TAA Productivity Tools owner.

 Restriction on Date (L) Time (T) and Timestamp (Z) fields
 ---------------------------------------------------------

 The special  data base fields  are supported, but  a restriction exists
 that  these types of fields  cannot begin in positions  1-5 of the data
 base record.    These positions  are reserved  for  the special  record
 written prior to copying the file.

 It should be possible for recovery to occur by doing the following:

   **   Duplicate  the DDS  for  the file  and  add a  dummy 5  position
        field at the beginning of the file.

   **   Create the new file in a work library.

   **   Use  CPYF with  FROMRCD(1)  FMTOPT(*MAP) COMPRESS(*NO)  from the
        real file to the work library.

   **   Use CRTDUPOBJ  to create  a  second version  of your  real  file
        (without the dummy field).

   **   Use RTVDLTRCD against the file in the work library.

   **   Use  CPYF  with  FMTOPT(*MAP  *DROP) from  the  file  output  by
        RTVDLTRCD to the new 2nd version of your file.

 Operating on a locked file
 --------------------------

 Because  a SAVOBJ  must  occur to  access the  records,  RTVDLTRCD will
 fail if the file is open for update.

 CPYF should be  considered in  this case  to copy  the file  to a  work
 file   and  retain   the   deleted  records.      Use  FROMRCD(1)   and
 COMPRESS(*NO) when copying.

 Working with the deleted records
 --------------------------------

 In some  situations, you may want  to recover only some  of the deleted
 records that have been retrieved.  You could do the following:

   **   Specify  RELRCD(*YES)  on  the  RTVDLTRCD  command.    This will
        provide  you  with   a  simple  unique   key  for  each   record
        retrieved.

   **   Get a  printed listing  of the deleted  records and  include the
        relative record number.  You could use the TAA tool DSPDBF.

   **   Determine what deleted records you want to recover.

   **   If  you only  want a  few, you  could use  CPYF with  the INCREL
        parameter and specify  the field  name for  the relative  record
        number.  For  example, assume you retrieved  the deleted records
        from FILEA  in LIB1 and wrote the records to  LIB2.  A new FILEA
        is  automatically  created  in   LIB2  with  just  the   deleted
        records.   It uses  the same  format plus a  field for  relative
        record  number.    Assume  you  created  FILEA2  in  LIB2  as  a
        duplicate  of FILEA  in LIB2 and  want to copy  record number 26
        (this was the  record at relative record  number 26 in FILEA  in
        LIB1).

             CPYF    FROMFILE(LIB2/FILEA)
                       TOFILE(LIB2/FILEA2)
                       MBROPT(*ADD)
                       INCREL((*IF TAAREL *EQ 26))

   **   If you  want to use most  of the deleted records,  you could use
        DFU to delete those that you did not want.

   **   When  you have a  net file of  the records you  want to recover,
        you can use CPYF to copy  back to the original file.  Note  that
        the records  will not  be written  back to  the original  record
        numbers.   If you need  to reuse the exact  same relative record
        numbers, you could  write a  program to  do so  using the  TAARR
        field.

 RTVDLTRCD Command parameters                          *CMD
 ----------------------------

    FROMFILE      The qualified  file name of  the file to  retrieve the
                  deleted records  from.  The library  value defaults to
                  *LIBL.

    TOFILELIB     The  library where  a duplicate  file will  be created
                  to hold  the  deleted records.    The same  file  name
                  will  be  used.    The  file must  not  exist  in  the
                  TOFILELIB.   The format  of the original  file is used
                  (Also see the  RELRCD parameter).   The new file  will
                  be created in arrival sequence (no key fields).

    FROMMBR       The member  of the FROMFILE to  be used.   The default
                  is *FIRST.

    RELRCD        A  *YES/*NO   value  that  defaults  to   *NO.    *YES
                  specifies that  you  want  a  relative  record  number
                  field to  be added  to each  record in  the new  file.
                  The  field (TAARR)  will contain  the  relative record
                  number  of where the record was  in the FROMFILE.  The
                  relative record  number  field will  be added  at  the
                  end of all  other fields in the format  and is defined
                  as packed with 13 digits and 0 decimals.

 CHKDLTRCD Command parameters                          *CMD
 ----------------------------

    FROMFILE      The  qualified  file name  of  the file  to  check for
                  deleted records.   The library  qualifier defaults  to
                  *LIBL.  *CURLIB may also be used.

    FROMRCD       The 'from relative  record' number to check.   See the
                  tool   documentation   section   on  'Determining   if
                  deleted records contain blanks or zeros'.

    TORCD         The 'to relative  record' number  to check.   See  the
                  tool   documentation  section   on   'Determining   if
                  deleted records contain blanks or zeros'.

    MBR           The  member  name  to  be  checked.   The  default  is
                  *FIRST  for the first  member of the  file.  *LAST may
                  be specified to check the last member in the file.

    ALWACTIVE     Whether  to  allow active  records  in  the  range  of
                  FROMRCD/TORCD.

                  *YES is  the default to assume that  you are beginning
                  the  copy  with the  first  active record  prior  to a
                  group of consecutive deleted records.

                  *NO may be  specified if the  range of records  should
                  include only deleted records.

 Restrictions
 ------------

   **   The  RTVDLTRCD command  can only  be used  by the  owner of  the
        file or a user with *ALLOBJ authority.

   **   The  deleted records must still  exist in the file.   This means
        that you have not done a CLRPFM, RGZPFM etc.

   **   If  the  file  is  specified  as  REUSEDLT(*YES)  you  may  have
        already  added a  new record  on  top of  a  deleted record  you
        would like to recover.

   **   Only  a physical data  file can be  specified.  Source  files or
        logical  files may not be used  (The typical use of source files
        is with  SEU which uses  a work  space so that  all records  are
        written  back  when  SEU  ends  so that  there  are  no  deleted
        records).

   **   Files  with  variable  length  fields  or  null  fields are  not
        supported.

   **   Graphic type fields are not supported.

   **   A minimum record size of 5 bytes is supported.

   **   A maximum record size of 4000 bytes is supported.

   **   The maximum number of fields in the file cannot exceed 998.

 Prerequisites
 -------------

 To help  control the use  of the  command, it  must be  created by  the
 Security Officer  or a  member of  his group.   The command  is created
 with the public excluded.

 The following TAA Tools must be on your system:

      CHKOBJ3      Check object 3
      CPYFRMSAVF   Copy from save file
      CVTDAT2      Convert date 2
      EDTVAR       Edit variable
      DUPFILFMT    Duplicate file format
      HLRMVMSG     HLL Remove message
      PAUSE        Pause
      RSNLSTMSG    Resend last message
      RTVDBFA      Retrieve data base file attributes
      RTVFLDARR    Retrieve field array
      RTVPFSRC     Retrieve PF source
      SNDCOMPMSG   Send completion message
      SNDDIAGMSG   Send diagnostic message
      SNDESCMSG    Send escape message
      SNDSTSMSG    Send status message
      WRTSRC       Write source

 Implementation
 --------------

 None, the tool is ready to use.

 Objects used by the tool
 ------------------------

    Object        Type        Attribute      Src member    Src file
    ------        ----        ---------      ----------    ----------

    RTVDLTRCD     *CMD                       TAADBFW       QATTCMD
    CHKDLTRCD     *CMD                       TAADBFW4      QATTCMD
    TAADBFWC      *PGM           CLP         TAADBFWC      QATTCL
    TAADBFWC2     *PGM           CLP         TAADBFWC2     QATTCL
    TAADBFWC3     *PGM           CLP         TAADBFWC3     QATTCL
    TAADBFWC4     *PGM           CLP         TAADBFWC4     QATTCL
    TAADBFWR      *PGM           RPG         TAADBFWR      QATTRPG
    TAADBFWR2     *PGM           RPG         TAADBFWR2     QATTRPG
    TAADBFWR3     *PGM           RPG         TAADBFWR3     QATTRPG
    TAADBFWR5     *PGM           RPG         TAADBFWR5     QATTRPG
    TAADBFWR9     *PGM           RPG         TAADBFWR9     QATTRPG

 Structure
 ---------

 RTVDLTRCD       Cmd
   TAADBFWC        CL Pgm
      TAADBFWR2      RPG pgm to check for var len fields etc
      TAADBFWC2      CL Pgm  Checks authority
      TAADBFWR       RPG Pgm  Reads save file data
         TAADBFWC2      CL Pgm   Checks authority
         TAADBFWR5      RPG Pgm  Handles reformatting of Date/Time etc
           TAADBFWR9      RPG Pgm  Determines yyyymmdd for disk format
           TAADBFWC3      CL Pgm   Does CVTDAT2 from yyyymmdd

 CHKDLTRCD       Cmd
   TAADBFWC4       CL Pgm

Added to TAA Productivity Tools April 1, 1995


Home Page

Powered by AS/400Powered by AS/400 Last modified on January 12, 2010 © 1995, 2010 - Jim Sloan, Inc.