z390 Portable Mainframe Assembler and Emulator

z390 ZSORT Sort Utility
 

Automated Software Tools Corporation
ZSORT Examples SORT References SORT Product Links

ZSORT Overview

The z390 ZSORT internal sort facility is an open source J2SE java component of z390 which supports sorting of any number of fixed or variable length records of any size up to the limits of memory and 64 bit file system. 

ZSORT is implemented via SVC x'A1' which has 3 function calls: one to initialize internal sort request, one to submit unsorted record, and one to retrieve sorted records.  Unsorted records are loaded into dynamically allocated table in memory and sorted.  If the unsorted records exceed size of table, then multiple blocks of sorted records are written to a work file and then merged.  If all the records fit in table, then they are sorted and returned without requiring use of sort work files.  When required, the merging is performed using two dynamically allocated sort work files with DDNAME's SORTWK01 and SORTWK02.  The sorted strings are merged from one work file to another doubling the size of the sorted strings on each pass until all the records are sorted on last merge pass.  All file I/O is blocked to minimize disk seeking on single disk systems.  User can define location of SORTWK01 and SORTWK02 if multiple physical disk drives are desired.

A set of regression tests are executed via rt\RTSORT.BAT including test of all 7 sort key types.  The utilities sort\TESTSRT3.MLC and TESTSRT4.MLC can be used to generate, sort, and verify any number of records.  A million records can be sorted in 28 seconds.  Statistics on each sort execution are recorded on the statistics file if option STATS is specified.

The initial sort method used to sort table is a shell sort.  All comments, suggestions, and contributions for improving this open source J2SE java sort utility are welcome.  You can join the discussion on z390@yahoogroups.com or send private email to don@higgins.net.

 

ZSORT Macro Interface

The ZSORT utility function can be called from z390 assembler using standard call interface with full work parameters in list pointed to by register 1.  The first positional macro parameter contains the operation code and options:  The operations include:

  • ISORT - initialize for internal sort using PUT to insert unsorted records and GET to retrieve sorted records
  • PUT - insert unsorted record following ISORT
  • GET - return sorted record following last PUT, returns RC=4 at end of sorted records

The following key work macro parameters are required for ISORT operations are:

  • FIELDS= - any number of key fields defined as (offset,length,type,A/D,,,,)
    • Offset to start of key starts at 1 and cannot be greater than LRECL.  For variable length records the offset does not include the 4 byte prefix.
    • Length of key plus offset must not exceed LRECL
    • Type of sort key field:
      • AC - ASCII characters (same as CH)
      • BI  - unsigned binary (same as CH)
      • CH - EBCDIC characters (same as CH)
      • FI   - signed binary such as half word, full word, or quad word integers
      • FL  - floating point HFP, BFP, or DFP short, long, or extended
      • PD - packed decimal
      • ZD - zoned decimal
    • A/D - ascending or descending key sequence
  • LRECL= - length of record (may be maximum length of variable length records)
  • MEMORY= - amount of memory available for sort table (If not specified, the maximum available contiguous memory block within the memory allocated to step by MEM option will be used.)
  • Alternatively the execute form MF=(E,addr) can be used.  See linklib\SORT.MLC for example.

The PUT and GET operations only require the keyword REC= defining address of record area.

Here is an example of internal sort interface:

     ZSORT ISORT,LRECL=80.MEMORY=10000000,FIELDS=(1,80,CH,A)
     .......
     ZSORT PUT,REC=(R2)
     .......
 ZSORT GET,REC=(R2)
     CHI      R15,4
     BE         END_OF_FILE
     .......

 

Here is example of REPRO utility used to create alternate index  (Still in development as of v1.5.01c)

Run REPRO with INFILE set to VSAM cluster data file and OUTFILE set to name of alternate index in catalog:

SET INFILE=TESTCAT.MYFILE
SET OUTFILE=TESTCAT.MYFILEX1
EXEC REPRO

 

Here is example of zcobol internal file sort

See zcobol\demo\DEMOSRT1.CBL for COBOL file sort.

See zcobol\demo\DEMOSRT2.CBL for COBOL internal sort using input/output procedure paragraphs.

 

ZSORT SORT Utility (Available in v1.5.01c)

The open source z390 SORT utility program in linklib\SORT.MLC is designed to be compatible with DFSORT and SYNCSORT.  SORT currently supports fixed and variable length files with ascending or descending single binary keys.  The input and output files are defined via SORTIN and SORTOUT DDNAME's.  Work files if required may be defined using SORTWK01 and SORTWK02 DDNAME's.  The input control record is defined using SYSIN DDNAME.  For example:

SET SORTIN=TESTFILE.IN[RECFM=F,BLKSIZE=80]
SET SORTOUT=TESTFILE.OUT
SET SYSIN=TESTFILE.INI
EXEC SORT

The SYSIN file must be ASCII line sequential file format containing SORT command defining any number of sort key fields as follows:

   SORT FIELDS=(offset,length,type,A/D,,,,)      See SORT FIELD= definition above for options.

Use the STATS option to output statistics on sort performance on the STA statistics file.  For example, here is output from one of the regression tests in rt\RTSORT.BAT:

10:20:53 SORT EZ390 ZSORT ID=1 started=10:20:50 ended=10:20:53
10:20:53 SORT EZ390 ZSORT ID=1 lrecl=4 keys=1
10:20:53 SORT EZ390 ZSORT ID=1 records=100000 memory= 4000
10:20:53 SORT EZ390 ZSORT ID=1 record compares=1487600 moves=2223800
10:20:53 SORT EZ390 ZSORT ID=1 sorted blocks=100 merge passes=7
10:20:53 SORT EZ390 ZSORT ID=1 block writes=2503 reads2401

Note in the above example, the optional parm PARM(1000) was passed to the SORT utility to force the maximum memory table size to 1000 records which in turn forced the sort to perform 7 merge passes to complete the sort of 100,000 reecords in 3 seconds.

Additional functionality will be added to this z390 SORT utility program and to the ZSORT function based on future user requests.

 
 

IBM, CICS, HLASM, MVS, OS/390, VSAM, z9, z10, and z/OS are registered trademarks
 of International Business Machines Corporation

This page last updated Wednesday May 23, 2012.   Webmaster  Sitemap
Copyright 2011 Automated Software Tools Corporation