TAA Tools
SORTDB2         SORT DATA BASE 2                       TAADBIR

The Sort Data  Base 2 command  provides a command interface  for FMTDTA
(Reformat  Utility  command)  in  support  of  From/To  positions  (the
SORTDB  TAA Tool  requires externally  described field  names).  Simple
sort field  and selection  criteria may  be specified.   Using  SORTDB2
can avoid  having to know or  use the FMTDTA  specifications to perform
simple sorts.

In  the following  SORTDB2 syntax  shown, the list  parameters (SORTFLD
and SEL1) will be more  meaningful if seen using the command  prompter.

A typical command would be:

             SORTDB2       INFILE(xxx) SORTFLD((34 42))

This  would  sort  the  named file  on  positions  34-42  in  ascending
sequence.   All records in the file would be  sorted and written to the
file SORTOUT in  QTEMP which would  have the same format  as the  input
file.

Another typical command would be:

             SORTDB2       INFILE(xxx) SORTFLD((71 80 C D))
                             SEL1(55 55 *N C *EQ P)

This would select  all records with a 'P'  in position 55 and  sort the
selected records on positions 71-80 in descending sequence.

The  command operates  on either  a  physical or  logical file.    If a
logical  file is used, it  can only have a single  format.  The command
defaults to access the first  member of a file.  A specific  member can
also be named.

The  command assumes  that  a FILE  sort  will occur  meaning that  the
records  will be sorted (not just the  control fields), all fields will
be included  in  the output  and the  control  fields will  not  appear
separately at  the beginning of  the record.  The  effect is as  if the
existing  file   was  read,  records  meeting  the  selection  criteria
selected and  placed  in a  different  physical file  (using  the  same
format) and that file is rearranged in the designated sequence.

A restriction  exists  that all  sort fields  must  designate the  same
sequence (A=Ascending or D=Descending).

Typical sequence of commands
----------------------------

By   default,  SORTDB2  will   create  the   SORTOUT  file   in  QTEMP.
Therefore,  a  typical  series  of  commands  to  sort  FILEX  and then
process the sorted results would be:

             SORTDB2       INFILE(FILEX) ...
             OVRDBF        FILEX (TOFILE(QTEMP/SORTOUT)
             CALL          PGM(xxx) /* Processes FILEX */

Alternative sorting functions
-----------------------------

The SORTDB2 TAA  Tool command provides a  similar front end to  FMTDTA,
but  uses   externally  described  field  names   rather  than  From/To
positions.

OPNQRYF  allows  the request  for a  sort  function with  the parameter
ALWCPYDTA(*OPTIMIZE).  This does not  guarantee a sort, but it will  be
used if there is a sufficient number of records to be sequenced.

FMTDTA  is  the  command  name  of   the  command  that  executes  sort
specifications  entered as  source statements.   The function  is known
as the 'Reformat Utility'.

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

   INFILE        The qualified name  of the  input file.   The  library
                 value defaults  to *LIBL.   *CURLIB may also  be used.

   SORTFLD       The sort  fields to be used.   Up to 10  fields may be
                 entered.  Each field is a list of parameters.

        FROMPOS       The  From position  of the field.   It  must be a
                      number within the record.

        TOPOS         The To  position  of the  field.   It  must be  a
                      number  within   the  record  and   be  equal  or
                      greater than the From position value.

        FLDTYPE       The   Field  type.     The   default  is   C  for
                      Character.  P should be  entered if the field  is
                      in packed  format.   Z should  be entered if  the
                      field is in zoned format.

        SEQUENCE      Whether  to   sort  in  ascending  or  descending
                      sequence.  The  default is  A for  ascending.   D
                      should be entered  for descending sequence.   All
                      fields must use the same sequence.

        FLDNAME       The name  of the field being sorted.   This is an
                      optional   value  that   is  intended   for  your
                      documentation.   The  name  only appears  in  the
                      listing of the FMTDTA specs.

   SEL1          The first selection field.

        FROMPOS       The From  position of  the field.   It must  be a
                      number within the record.

        TOPOS         The  To  position of  the field.    It must  be a
                      number  within  the  record   and  be  equal   or
                      greater than the From position value.

        FLDNAME       The name  of the field  being selected.   This is
                      an  optional  value  that  is  intended for  your
                      documentation.   The  name only  appears  in  the
                      listing of the FMTDTA specs.

        FLDTYPE       The  Field   type.     The  default   is  C   for
                      Character.   P should be entered if  the field is
                      in  packed format.   Z  should be  entered if the
                      field is in zoned format.

        RELATION      The relation of  the comparison.  *EQ,  *NE, *LT,
                      *LE, *GT, or *GE may be specified.

        VALUE         The  value to  be  compared  to.   It  must be  a
                      constant  (not a  field  name).   Negative values
                      should be entered with a trailing minus sign.

   ANDOR1        An entry of  *AND or *OR.   It generates  Column 7  of
                 the  Record  Specifications.   The  default  is  *AND.
                 This   allows  you   to  determine   the  relationship
                 between the 1st and 2nd selection statements.

   SEL2          2nd selection statement.

   ANDOR2        Relationship between the 2nd and 3rd selections.

   SEL3          3rd selection statement.

   ANDOR3        Relationship between the 3rd and 4th selections.

   SEL4          4th selection statement.

   EXECSORT      A  *YES/*NO  option  which   allows  you  to   control
                 whether  the sort  is  executed  or whether  only  the
                 sort  specifications  are  output.    The  default  is
                 *YES.

                 If  *NO is  specified, the  sort specifications appear
                 in   the  file   QTEMP/FMTTMP   member-FMTSPC   unless
                 OUTSRCF or  OUTSRCMBR are  specified.  This  option is
                 of  value  in a  testing  environment so  you  can see
                 what will  be generated.   It is  also of  value if  a
                 function  is needed  which  is  supported by  Reformat
                 Utility   specifications  but   not  by   the  SORTDB2
                 command.      You   can    generate   some   of    the
                 specifications  needed   and  then  modify   for  your
                 specific case.

   PRTSPECS      Option  to control whether  the FMTDTA  command should
                 print   the  sort  specifications.    The  default  is
                 *ERROR meaning  the specifications  should be  printed
                 only  if the  FMTDTA command  fails.   This  occurs by
                 printing  the file  (the spool  file name will  be the
                 name of the OUTSRCMBR) and  then deleting the file  if
                 the  command  completes  successfully.   An  entry  of
                 *YES or *NO may also be made.

   OUTFILE       The  qualified name  of the  output  file to  be used.
                 The default  is  QTEMP/SORTOUT.   This  file  will  be
                 created  using the  same  format  as  the INFILE.    A
                 specific  file  can  be  named.   The  FMTDTA  command
                 clears  the file before adding records.   If a file is
                 created, the SIZE parameter is set to *NOMAX.

   INMBR         Member of  the  INFILE to  be used.    The default  is
                 *FIRST.

   OUTMBR        Member  of the  OUTFILE to  be used.   The  default is
                 *FIRST.

   OUTSRCF       The  name of  the source  file which  will be  used to
                 hold the FMTDTA specifications.   This parameter  will
                 be  used regardless  of  the  status of  the  EXECSORT
                 parameter.    The  default is  QTEMP/FMTTMP.    If the
                 default is not used, the source file must exist.

   OUTSRCMBR     The name of the  source member which  will be used  to
                 hold the FMTDTA  specifications.  This  parameter will
                 be  used  regardless of  the  status  of the  EXECSORT
                 parameter.   The default  is FMTSPC.   The member will
                 be added  if  it  does not  exist  and cleared  if  it
                 does.

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

SORTDB2   is  a   simple   front  end   to   create  Reformat   Utility
specifications  and  execute  them.    Not  all  functions  within  the
Reformat Utility are supported.

All sort fields must use the same sequence.

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

The following TAA Tools must be on your system:

     CHKOBJ3         Check object 3
     DUPFILFMT       Duplicate file format
     EDTVAR          Edit variable
     EXTLST          Extract list
     MOVCHRDEC       Move character to decimal
     RTVDBFA         Retrieve data base file attributes
     SNDCOMPMSG      Send Completion message
     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
   ------        ----    ---------      ----------    ----------

   SORTDB2       *CMD                   TAADBIR       QATTCMD
   TAADBIRC      *PGM       CLP         TAADBIRC      QATTCL
   TAADBIRR      *PGM       RPG         TAADBIRR      QATTRPG
					

Added to TAA Productivity tools August 1, 1998


Home Page Up to Top