
PROCEDURE qcp$establish_qcu (
  output,o: file = $output
  status)

  VAR
    ignore: status
    local_status: status
    ck_path: file = :$SYSTEM.$SYSTEM.FIELD_MAINTENANCE
    id_path: file = :$SYSTEM.$SYSTEM.QCU_MAINTENANCE.identification
    deadstart_catalog: string
    level: string
    check: boolean
  VAREND


      IF $file($value(output) open_position) = '$BOI' THEN
        rewind_file $value(output) status=ignore
        ofile = $string($value(output))//'.$ASIS'
      ELSE
        ofile = $string($value(output))
      IFEND




    crev history k=string v=':$SYSTEM.$SYSTEM.FIELD_MAINTENANCE.HISTORY'
    crev clear k=string v='$LOCAL.HISTORY'
    crev temp k=string v=$unique

    $system.accept_line v=level i=id_path
    deadstart_catalog = ':$SYSTEM.$SYSTEM.QCU_MAINTENANCE.'//level//'.deadstart_catalog'


  "  Create the global variables.
    delv csv$estqcu_catalog_specified status=ignore
    delv csv$estqcu_existing_catalog status=ignore

  VAR
    csv$estqcu_catalog_specified: (JOB) boolean = TRUE
    csv$estqcu_existing_catalog: (JOB) file
  VAREND

   crev lc_path k=string
   lc_path = deadstart_catalog
    csv$estqcu_existing_catalog = deadstart_catalog

    IF NOT $file($fname(lc_path),catalog) THEN
       putl '                    STOP'   o=$fname(ofile)
       putl '      There is no system available to establish.'   o=$fname(ofile)
       putl '      It will be necessary to issue GENERATE_'      o=$fname(ofile)
       putl '      CORRECTION_SYSTEM prior to reissueing'        o=$fname(ofile)
       putl '      ESTABLISH_CORRECTION_SYSTEM.'                 o=$fname(ofile)
       putl ' '                                                  o=$fname(ofile)
       EXIT_PROC
    IFEND


    crev work k=string
    crev work1 k=string
    crev count
    delf $fname(temp) status=ignore
    delf $fname(clear) status=ignore
    detf $fname(history) status=ignore
    attf $fname(history) op=$asis
    accl work i=$fname(history) lc=count
     WHILE count > 0 DO
      work1 = $substr(work,1,74)
      work1 = work1//'YES'
      putl work1 o=$fname(temp//'.$eoi')
    accl work i=$fname(history) lc=count
     WHILEND
    rewf $fname(temp) status=ignore
    detf $fname(history) status=ignore
    delf $fname(history) status=ignore
    copf $fname(temp) $fname(history)
    detf $fname(history)  status=ignore


  "  Execute a task to install the deadstart file.

  TASK tn=install_ds_catalog_to_disk
    VAR
      command_status: status
      ignore_status: status
      local_status: status
    VAREND

 MANAGE_FIELD_CHANGES
  put_line ' '
  put_line '     Establishing the Correction System     '
  put_line '                 Please'
  put_line '   Wait on the completion message "** New system established **"'
  put_line ' '

   incc c='establish_deadstart_catalog status=local_status' ..
      status=command_status
      IF NOT command_status.normal THEN
        local_status = command_status
      IFEND
  QUIT

    IF NOT local_status.normal THEN
    putl ' Establish Correction system returned the following error:'
    disv local_status
    IFEND


    delete_variable n=csv$estqcu_catalog_specified
    delete_variable n=csv$estqcu_existing_catalog
  TASKEND


 PROCEND qcp$establish_qcu

