.PROC,REPLIB*I,
G "- Group file containing records"    = (*F),
L "- Library file receiving records"   = (*N=#FILE,*F),
T "- Type of record being replaced"    = (*N=,ABS,CAP,OPL,OPLC,OPLD,OVL,
                                               PP,PPU,PROC,REL,TEXT,ULIB),
UN "- permanent file ID"               = (*N=,*F),
.
.HELP
 The REPLIB procedure REPlaces records on a LIBrary file.
 On NOS systems, it requires CATALOG binaries with GENCAT entry point.

 Parameter   Default   Description
   Name       Value

   g                   file containing records to replace
  [l]                  library file for record replacement
  [t]                  type of record being replaced on library
  [un]                 permanent file id (NOS/BE systems only)

.HELP,G
 The G parameter names a file from which records are replaced.
.HELP,L
 The L parameter names the file to which records are replaced.
 The default value is the file containing this procedure.
.HELP,T
 The T parameter selects the type of record to replace from the file
 specified by the G parameter. No type checking is done unless a value
 is specified for the record type.
.HELP,UN
 The UN parameter specifies the permanent file ID of file L and G. It
 is specified for NOS/BE systems only.
.ENDHELP
.IFE,$G$.EQ.$L$,ERROR.
  REVERT,ABORT. CANNOT REPLACE G --> L
.ENDIF,ERROR.
GETFILE,G,G,UN,READ,A=YES.
.IFE,$T$.NE.$$,CHECKTYPE.
  GTR,G,YYYYUPD,,,,NA.T/*
  IFE,FILE(YYYYUPD,AS),FOUNDTYPE.
    UNLOAD,YYYYUPD.
  ELSE,FOUNDTYPE.
    .IFE,FILE(G,.NOT.AS),FILEPRM.
      UNLOAD,G.
    .ENDIF,FILEPRM.
    REVERT,ABORT. NO T RECORDS ON G
  ENDIF,FOUNDTYPE.
.ENDIF,CHECKTYPE.
GETFILE,L,L,UN.
REWIND,G.
.IFE,SYS=NOS,NOSSYS.
$IF,(FILE(L,AS)).AND.(FILE(L,.NOT.WR)).GETFILE,L,L.
UPDVER,DATE+,TIME+,G,L,REPLACE.
DISLIB,ALL,T,G,,O=YYYYUPD,DO=D.
$SKIPEI,YYYYUPD.
$UNLOAD,YYYYERR.
$GTR,G,YYYYERR,,,,NA.PROC/DISVER
$IFE,FILE(YYYYERR,AS),CHECKVER.
  $IFE,$G$.NE.$DISVER$,NEWVER.
    $NOTE(YYYYUPD,NR)+*IGNORE PROC/DISVER
    $NOTE(YYYYUPD,NR)+*FILE DISVER
    $NOTE(YYYYUPD,NR)+*B *,PROC/DISVER
  $ENDIF,NEWVER.
  $UNLOAD,YYYYERR.
$ELSE,CHECKVER.
  $NOTE(YYYYUPD,NR)+*FILE DISVER
  $NOTE(YYYYUPD,NR)+*B *,PROC/DISVER
$ENDIF,CHECKVER.
$PACK(YYYYUPD)
$LIBEDIT,P=L,N=L,B=G,#L=YYYYERR,LO=E,I=YYYYUPD,U=L,NI,D.
$SKIP,NOERROR.
  $EXIT.
  $REWIND,G,YYYYERR.
  $COPYEI,YYYYERR,OUTPUT.
  $UNLOAD,YYYYERR,ZZZZZG2.
  $UNLOAD,DISVER,YYYSCR2,YYYYUPD.
  $REVERT,ABORT. REPLACE G --> L FAILED
$ENDIF,NOERROR.
$REWIND,YYYYERR.
$COPYEI,YYYYERR,OUTPUT.
$UNLOAD,YYYYERR,ZZZZZG2.
  $UNLOAD,DISVER,YYYSCR2,YYYYUPD.
$IFE,.NOT.((FILE(L,PM)).AND.(FILE(L,WR))),REWRITE.
  REPFILE,L,L,DEFINE=YES.
$ENDIF,REWRITE.
.IFE,FILE(L,AS),ADDLIB.
  $LIBRARY,L/D.
  $LIBRARY,L/A.
.ELSE,ADDLIB.
  $UNLOAD,L.
.ENDIF,ADDLIB.
.ELSE,NOSSYS.
  GETFILE,G,G,UN,A=YES.
  REQUEST,LLLLNEW,SN.
  COPYL(L,G,LLLLNEW,,RAT)
  IFE,FILE(L,PF),REPPF.
    RETURN,L.
    REPFILE,LLLLNEW,L,,,,UN.
    RETURN,LLLLNEW.
    .IFE,FILE(L,AS).GETFILE,L,L,UN,A=YES.
  ELSE,REPPF.
    REWIND,L,LLLLNEW.
    COPYBF,LLLLNEW,L.
  ENDIF,REPPF.
  SKIP,NOERROR.
    EXIT.
    UNLOAD,LLLLNEW.
    NOTE(OUTPUT,NR)+ REPLACE G --> L FAILED
    REVERT,ABORT. REPLACE G --> L FAILED
  ENDIF,NOERROR.
  UNLOAD,LLLLNEW.
.ENDIF,NOSSYS.
.IFE,FILE(G,.NOT.AS),NOTLOCAL.
  PURGE,G.
.ENDIF,NOTLOCAL.
UNLOAD,G.
REVERT. REPLACED G --> L
/EOR
