.PROC,REPFILE*I,
LFN "- Local File Name"                = (*F),
PFN "- Permanent File Name"            = (*N=,*F),
CT "- Catalog Type"                    = (*N=S,P,S,PU,SPRIV,PUBLIC,PR,PRIVATE),
M "- Mode of file access"              = (*N=R,E=E,R=R,EXECUTE=E,READ=R),
DEFINE "- YES causes DIRECT file made" = (*N=NO,YES,NO),
UN  "- PERMANENT FILE ID"              = (*N=,*F),
.
.HELP
 The REPFILE procedure REPlaces local FILEs as either INDIRECT or
 DIRECT permanent files depending upon validation limits.
 When possible, INDIRECT files are created to conserve disk space.

 Parameter   Default   Description
   Name       Value

   lfn                 local file name by which the file is accessed
  [pfn]       lfn      permanent file name of the stored file
  [ct]         s       file catalog type, which limits access
  [m]          r       access mode of the file
  [define]     no      YES value causes DIRECT access file creation
   un                  permanent file id (NOS/BE systems only)

.HELP,LFN
 The LFN parameter selects the name by which the file is accessed.
.HELP,PFN
 The PFN parameter selects the name by which the file is stored.
 The default is the value specified for the LFN parameter.
.HELP,CT
 The CT parameter specifies the file permissions of the saved file.
 Options are:  S | SPRIV        - for semiprivate files (default value)
               PU | PUBLIC      - for public files
               P | PR | PRIVATE - for private files
 This parameter is ignored on NOS/BE.
.HELP,M
 The M parameter selects the Mode of access for the file.
 Options are:  R | READ     - for read access (default value)
               E | EXECUTE  - for execute access
 This parameter is ignored on NOS/BE.
.HELP,DEFINE
 The DEFINE parameter forces creation of a DIRECT access file.
 Options are: no  - create an INDIRECT access file (default value)
              yes - create a DIRECT access file
 This parameter is ignored on NOS/BE.
.HELP,UN
 The UN parameter specifies the permanent file ID under which the
 file is cataloged.
 This parameter must not be specified on NOS.
.ENDHELP
.IFE,$PFN$.EQ.$$,NOPFN.
  REVERT,EX.REPFILE,LFN,LFN,CT,M,DEFINE,UN.
.ENDIF,NOPFN.
.IFE,SYS=NOS,NOSSYS.
  .IFE,$UN$.NE.$$,BEID.
    REVERT,ABORT. UN PARAMETER ILLEGAL FOR NOS REPFILE
  .ENDIF,BEID.
.IFE,FILE(LFN,AS),FILELOC.
  $REWIND,LFN.
    $PURGE,PFN/NA.
  .IFE,$DEFINE$.EQ.$NO$,FILEIND.
    $SAVE,LFN=PFN/#CT=CT,#M=M,NA.
    $GET,YYYREPF=PFN/NA.
  .ENDIF,FILEIND.
  $IFE,.NOT.FILE(YYYREPF,AS),INDFAIL.
    $#DEFINE,YYYREPF=PFN/#CT=CT,#M=M.
    $COPYEI,LFN,YYYREPF.
    $REWIND,LFN.
    $UNLOAD,YYYREPF.
    $REVERT. LFN REPLACED --> PFN(*D)
  $ELSE,INDFAIL.
    $UNLOAD,YYYREPF.
    $REVERT. LFN REPLACED --> PFN(*I)
  $ENDIF,INDFAIL.
.ELSE,FILELOC.
  $REVERT,ABORT. FILE LFN NOT FOUND
.ENDIF,FILELOC.
$EXIT.
$UNLOAD,YYYREPF.
$IFE,(EF.EQ.TIE).OR.(EF.EQ.TAE),TERMINATED.
  $EXIT. REPFILE *TERMINATED*
$ELSE,TERMINATED.
  $REVERT,ABORT. REPFILE FAILED
$ENDIF,TERMINATED.
.ELSE,NOSSYS.
.IFE,$UN$.EQ.$$.REVERT,ABORT. USERNAME NOT SPECIFIED FOR REPFILE.
.IFE,FILE(LFN,AS),FILELOC.
  .IFE,FILE(LFN,PF),PFILE.
    REVERT. LFN ALREADY PERMANENT.
  .ELSE,PFILE.
    .IFE,OT.EQ.TXO.DFLIST,OFF.
    CATALOG,LFN,PFN,ID=UN.
    RETURN,LFN.
    ATTACH,LFN,PFN,ID=UN,MR=1.
    SKIP,CATERR.
      EXIT(U)
      DISCONT,OUTPUT.
      .IFE,OT.EQ.TXO.DFLIST,ON.
      SET(EF=0)
      BKSP,OUTPUT.
      REVERT,ABORT. REPFILE CATALOG ERROR
    ENDIF,CATERR.
    PURGE,YYYREL1,PFN,ID=UN,LC=1.
    SKIP,PURERR.
      EXIT(U)
      DISCONT,OUTPUT.
      SET(EF=0)
      BKSP,OUTPUT.
    ENDIF,PURERR.
    RETURN,YYYREL1.
    .IFE,OT.EQ.TXO.DFLIST,ON.
    REVERT. LFN REPLACED --> PFN
  .ENDIF,PFILE.
.ELSE,FILELOC.
  REVERT,ABORT. FILE LFN NOT FOUND
.ENDIF,FILELOC.
EXIT.
  .IFE,OT.EQ.TXO.DFLIST,ON.
  REVERT,ABORT. REPFILE FAILED
.ENDIF,NOSSYS.
/EOR
