TAA Tools
CPYDBFDAT       COPY DATA BASE DATE                    TAADBMS

The Copy  Data Base  Date command copies  records in  a data  base file
based  on  a comparison  of  a field  value  and a  specified  date and
operator.    Different date  formats  are valid  for  character, zoned,
packed, date, or time stamp fields.

You must have all rights to the To file to use CPYDBFDAT.

You can  create  the To  file  with CPYDBFDAT.    If the  file  already
exists, it must have the same level ID as the From file.

Purging a file of old records
-----------------------------

Assume you  only want to  retain the records  in a master file  where a
date  field contains a  date beginning January  1st of some  year.  The
records with prior dates should be dropped.

You could  use CPYDBFDAT to  copy the  current records  to a  temporary
file, and  then the  CPYF command using  MBROPT(*REPLACE) to  copy back
to the master file.

An  alternative is to use  the DLTDBFDAT command which  will delete the
old records from an existing file.

Typical command
---------------

A typical  command to  copy the  records based  on field  DATE1 if  the
value of the  field in *MDY format is  greater than or equal to  Jan 1,
2005 would be:

             CPYDBFDAT  FROMFILE(xxx) TOFILE(yyy) DATFLD(DATE1)
                          DATFMT(*MDY) CMPDATE(010105)
                          REPLACE(*YES)

The DATE1 field  would be checked for a valid  length and type based on
the  *MDY  value for  DATFMT.   For example,  if it  is a  character or
zoned field,  it must have  a length  of 6 bytes.   If  it is a  packed
field,  it must have  6 digits.   If  DATFMT(*USA) had  been specified,
the DATE1 field must be an L field type.

The  default is to compare  the date specified against  the field value
for a *GE  condition.  This  would mean that  all records containing  a
value of Jan 1, 2005 or later would be copied.

Blank and invalid dates
-----------------------

If the named  DATFLD has any blank  dates, the record is  copied to the
file  and  a  diagnostic  message  is  written  before  the  completion
message.  The  Date type fields  (L) and  Time Stamp fields  (Z) use  a
date of 1900-01-01 as a  blank date.  These will also  cause the record
to be copied and the diagnostic message to occur.

If the  named DATFLD has any  invalid dates, the records  are copied to
the  To file and a diagnostic  message is written before the completion
message.

To determine the  records containing the  bad dates, use the  DLTDBFDAT
command with ACTION(*CHECK) and NBRRCDS(*MAX).  See also CHKDBFDAT.

CPYDBFDAT escape messages you can monitor for
---------------------------------------------

None.  Escape messages from based on functions will be re-sent.

CPYDBFDAT Command parameters                         *CMD
----------------------------

   FROMFILE      The  qualified name  of the  From file  containing the
                 dates.    The  library value  defaults  to  *LIBL.   A
                 specific library or *CURLIB may also be used.

   TOFILE        The qualified  name  of the  To  file to  contain  the
                 copied  records.    The   library  value  defaults  to
                 *LIBL.   A  specific library  or  *CURLIB may  also be
                 used.

                 The file may be created with the CRTFILE(*YES).

                 If the  file already  exists, it  must have  the  same
                 level ID  as the  From file  and the MBROPT  parameter
                 must be specified as *ADD or *REPLACE.

   DATFLD        The name  of the field  to be checked.   It must  be a
                 field  in  the  named  file  and  must  be  a  type  A
                 (Character), S  (Zoned), P  (Packed), L  (Date), or  Z
                 (Timestamp).   It must have a  length that corresponds
                 to  the DATFMT value.   For  example, if DATFMT(*YYMD)
                 is specified and the field  is A = Character, it  must
                 have a length of 8 bytes.

   DATFMT        The date  format of  the field  to be  compared.   The
                 value must  be *MDY, *DMY, *YMD,  *MDYY, *DMYY, *YYMD,
                 *CYMD, *ISO, *USA, *EUR, *JIS, or *TIMSTM.

   CMPDATE       The date to  compare to determine  if the record  will
                 be copied.  The  date should be entered in  job format
                 regardless   of  the  format   of  the  field   to  be
                 compared.

                 All  2 digit year dates  must be in a  range of Jan 1,
                 1940 to Dec  31, 2039.   All 4  digit year dates  must
                 be in a range of Aug 24, 1928 to May 9, 2071.

   SELOP         The select  operation to use  when comparing.   *GE is
                 the  default.   *EQ,  *NE,  *LE,  *GT, or  *LT  may be
                 specified.

   CENFLD        The name  of  the  field which  contains  the  century
                 value as an independent field.

                 *NONE  is   the  default   meaning  the   DATFLD  name
                 contains the entire date.

                 A  field name may  be entered to  describe the century
                 field to be  used in  the date comparison.   This  may
                 only be  used with a  DATFMT value  of *MDY, *DMY,  or
                 *YMD.   The field must  be a type  A = Character,  S =
                 Zoned,  or P = Packed and  be one byte (or one digit).

                 A  separate  century   field  is  typical   of  system
                 outfiles  such  as  the  QADSPOBJ  format  of  DSPOBJD
                 which  uses ODCCEN  (one byte  century) and  ODCDAT (6
                 byte date  in *MDY  format) for  the  date the  object
                 was created.

   SEPARATORS    A  *YES/*NO value  for whether  the data  in the  data
                 base has separator characters such as a /.

                 *NO  is the default.   *NO  must be specified  for the
                 decimal type  fields P  (Packed) or  S (Zoned).    *NO
                 must be  specified for  L (Date)  or Z (Timestamp)  as
                 they have an implied separator.

                 *YES may  be specified if  the field in  the data base
                 has  separators,  but  must  use  the  following rules
                 (the  actual separator  character  is  ignored,  /  is
                 used in the examples):

                 The *CYMD type must be 9 bytes and appear as:

                      ccc/mm/dd

                 The *MDY,  *DMY, and  *YMD types must  be 8  bytes and
                 appear as:

                      xx/xx/xx

                 The  *MDYY or *DMYY types must  be 10 bytes and appear
                 as:

                      xx/xx/xxxx

                 The *YYMD type must be 10 bytes and appear as:

                      yyyy/mm/dd

   FROMMBR       The member  name of  the  From file.   *FIRST  is  the
                 default.   *LAST  or  a specific  member  name may  be
                 specified.

   TOMBR         The  member  name  of the  To  file.    *FIRST is  the
                 default.   *LAST  or a  specific  member name  may  be
                 specified.   *LAST may  not be  used if  CRTFILE(*YES)
                 is specified.

   MBROPT        The member option to be used.

                 *NONE  is  the  default,  but  may  only  be  used  if
                 CRTFILE(*YES) is specified.

                 *REPLACE  may be specified  to cause the  To member to
                 be cleared before any  records are added to  the file.

                 *ADD  may  be  specified  to  add records  to  the  To
                 member.

   CRTFILE       A  *YES/*NO option for  whether the To  file should be
                 created during the command.

                 *NO  is  the  default  meaning  the  To  file  already
                 exists and  must have  the same level  ID as  the From
                 file.

                 *YES  may be  specified to  create  the To  file using
                 the same format as the From file.


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

You must have all rights to the To file to use CPYDBFDAT.

The From file  to be processed  must not have  a record length  greater
than 9999 bytes and the number of fields cannot exceed 999.

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

The following TAA Tools must be on your system:

     CHKDBFMBR       Check data base file member
     CVTDAT2         Convert date 2
     DLTDBFDAT       Delete data base file date
     EDTVAR          Edit variable
     HLRMVMSG        HLL Remove message
     RSNLSTMSG       Resend last message
     RTVDBFA         Retrieve data base file attributes
     RTVFLDA         Retrieve field attributes
     RTVFMT          Retrieve format
     SNDCOMPMSG      Send completion message
     SNDDIAGMSG      Send diagnostic message
     SNDESCINF       Send escape information
     SNDESCMSG       Send escape message
     SNDSTSMSG       Send status message

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

None, the tool is ready to use.

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

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

   CPYDBFDAT     *CMD                   TAADBMS       QATTCMD
   TAADBMSC      *PGM       CLP         TAADBMSC      QATTCL
   TAADBMSR      *PGM       RPG         TAADBMRR      QATTRPG
					

Added to TAA Productivity tools April 15, 2010


Home Page Up to Top