.PROC,SORLIB*I,
L "- Library file name"                = (*N=#FILE,*F),
UN "- User Name containing library"    = (*N=,*F),
.
.HELP
 The SORLIB procedure SORts records on a LIBrary file.
 Requires CATALOG binaries with GENCAT entry point.

 Parameter   Default   Description
   Name       Value

  [l]                  library file containing the records
  [un]                 user name in which library resides

.HELP,L
 The L parameter names the file containing records to sort.
 The default value is the file containing this procedure.
.HELP,UN
 The UN parameter specifies the User Name location of the file.
 The default value is the User Name in which this procedure executes.
.ENDHELP
GETFILE,L,L,UN,A=YES.
DISLIB,ALL,,L,UN,O=YYYYINP,DO=D.
$SORT5.FROM=YYYYINP TO=YYYYOUT KEY=(21..21,11..17)
CRELIB,L,#L=L,I=YYYYOUT,N=L.
$UNLOAD,YYYYOLD,YYYYINP,ZZZZZDG,YYYYOUT.
$SKIP,NOERROR.
  $EXIT.
  .IFE,FILE(L,.NOT.AS),FILEPRM.
    $UNLOAD,L.
  .ENDIF,FILEPRM.
  $UNLOAD,YYYYOUT,YYYYINP,ZZZZZDG,YYYYOLD.
  $IFE,(EF.EQ.TIE).OR.(EF.EQ.TAE),TERMINATED.
    $EXIT. SORLIB *TERMINATED*
  $ENDIF,TERMINATED.
  $REVERT,ABORT. SORT OF L FAILED
$ENDIF,NOERROR.
.IFE,FILE(L,.NOT.AS),FILEPRM.
  $UNLOAD,L.
.ELSE,FILEPRM.
  $LIBRARY,L/D.
  $LIBRARY,L/A.
.ENDIF,FILEPRM.
$REVERT. LIBRARY L SORTED
/EOR
