PROCEDURE activate_drje (
  control_facility_name, cfn: name = station_controller_1
  job_class, jc: name = batch
  notify_after_aborting, naa: boolean = TRUE
  print_listing_after_aborting, plaa: boolean = TRUE
  status)

" Define constants local to this activation procedure.

  "$FORMAT=OFF"
  VAR
    drje_product_catalog: (READ) file = $system.network_transfer_facility.dynamic_remote_job_entry
  VAREND

  VAR
    drje_abort_file: (READ) file = drje_product_catalog.abort_file
    drje_job_log: (READ) file = drje_product_catalog.drje_job_log
    drje_message_template_library: (READ) file = $system.osf$site_command_library
    drje_product_library: (READ) file = drje_product_catalog.drje_library
  VAREND
  "$FORMAT=ON"

" Declare variables local to this activation procedure.

  "$FORMAT=OFF"
  VAR
    local_status: status
  VAREND
  "$FORMAT=ON"

" Verify the procedure has been called by a system operator job.

  IF NOT $job_validation(system_operation) THEN
    EXIT procedure WITH $status(false, 'RA', 0, 'DRJE/VE can only be activated by a system operator.')
  IFEND

" Verify DRJE is installed.

  IF (NOT $first($file_attributes(drje_product_library, registered)).registered) THEN
    EXIT procedure WITH $status(false, 'RA', 0, 'The DRJE/VE product is not installed.')
  IFEND

" Check for the presence of an existing DRJE job.

  MANAGE_JOBS
    select_job name=$dynamic_remote_job_entry job_state=(deferred, queued, initiated) ..
          user_information='DRJE@'//control_facility_name status=local_status
    IF local_status.normal THEN
      IF $size(jmv$selected_jobs) > 0 THEN
        EXIT procedure WITH $status(false, 'NF', nfe$drje_already_active, control_facility_name)
      IFEND
    ELSE
      EXIT procedure WITH local_status
    IFEND
  QUIT

" Delete any existing cycles of the DRJE abort file.

  REPEAT
    delete_file file=drje_abort_file status=local_status
  UNTIL NOT local_status.normal

" Generate the DRJE abort file.

  TASK ring=11
COLLECT_TEXT output=drje_abort_file until='*** END_ABORT_COMMANDS ***' substitution_mark='?' ..
          status=local_status

  VAR
    dump_file: file
  VAREND

    dump_file = $fname('?drje_product_catalog?.drje_dump_'//$date('Y2M2D2')//'_'//$time('H24MMSS'))

    set_file_attributes file=dump_file fc=list pf=continuous

    put_line line='1***** ABORT DUMP OF DRJE' o=dump_file.$eoi
    put_line line='       '//$date(iso)//' '//$time(millisecond) o=dump_file.$eoi

    put_line line='       '//$job(os_version)//' - '//$default_family//' - CYBER '//..
$processor(model_number, 0)//' Serial '//$processor(serial_number, 0) o=dump_file.$eoi

    put_lines lines=('', ' ***** TRACEBACK:', '') o=dump_file.$eoi
    display_call count=all start=1 display_option=all_calls o=dump_file.$eoi
*** END_ABORT_COMMANDS ***
    IF NOT local_status.normal THEN
      IF local_status.condition = ame$file_not_known THEN

" The DRJE abort file commands could not be generated. Map the abnormal status value AME$FILE_NOT_KNOWN to
" PFE$UNKNOWN_PERMANENT_FILE to provide the caller with a more appropriate error message.

        local_status = $status(false, 'PF', pfe$unknown_permanent_file, $string(drje_abort_file))
      IFEND
      EXIT procedure WITH local_status
    IFEND
  TASKEND

" Submit DRJE job.

  JOB user_job_name=$dynamic_remote_job_entry job_abort_disposition=terminate job_class=job_class ..
        job_recovery_disposition=terminate output_disposition=drje_job_log substitution_mark='?' ..
        user_information='DRJE@'//control_facility_name

    "$FORMAT=OFF"
    VAR
      ignore_status: status
      local_status: status
      nfv$notify_after_aborting: (JOB) boolean = ?notify_after_aborting?
      nfv$print_listing_after_abort: (JOB) boolean = ?print_listing_after_aborting?
    VAREND
    "$FORMAT=ON"

    change_message_level il=full status=ignore_status
    change_working_catalog c=$local

" Capture the job output to the job's job log.

    create_file_connection sf=$output file=$job_log

" Add the CREATE_DEVICE_CONNECTION message templates to the command list.

    create_command_list_entry entry=?drje_message_template_library? placement=after status=local_status
    IF local_status.normal OR (local_status.condition = $status_code(cle$duplicate_command_list_ent)) THEN

" Execute DRJE program.

      "$FORMAT=OFF"
      execute_task parameters='cfn=?control_facility_name?' libraries=(?drje_message_template_library?, ..
            ?drje_product_library?) starting_procedure=nfp$dynamic_remote_job_entry load_map_options=all ..
            preset_value=zero termination_error_level=warning abort_file=?drje_abort_file? debug_mode=false ..
            arithmetic_overflow=true arithmetic_loss_of_significance=true divide_fault=true ..
            exponent_overflow=true exponent_underflow=true fp_indefinite=true fp_loss_of_significance=false ..
            invalid_bdp_data=true status=local_status
      "$FORMAT=ON"

    IFEND
    IF NOT local_status.normal THEN
      display_value v=' ****DRJE/VE aborted with the following status:'
      display_value v=local_status

      IF nfv$print_listing_after_abort THEN
        put_line l=' **************************************************************************' ..
              o=$local.drje_failure_report
        put_line l=' **************************************************************************' ..
              o=$local.drje_failure_report.$eoi
        put_line l=' *                                                                        *' ..
              o=$local.drje_failure_report.$eoi
        put_line l=' *   This job log reflects an abnormal termination of the DYNAMIC REMOTE  *' ..
              o=$local.drje_failure_report.$eoi
        put_line l=' *   JOB ENTRY application.  It should be examined by a site analyst.     *' ..
              o=$local.drje_failure_report.$eoi
        put_line l=' *                                                                        *' ..
              o=$local.drje_failure_report.$eoi
        put_line l=' **************************************************************************' ..
              o=$local.drje_failure_report.$eoi
        put_line l=' **************************************************************************' ..
              o=$local.drje_failure_report.$eoi

        display_log do=all o=$local.drje_failure_report.$eoi

        print_file file=$local.drje_failure_report
      IFEND

      IF nfv$notify_after_aborting THEN
        send_operator_message m='DRJE/VE job failed, See ?drje_job_log?' oc=system_operator
      IFEND
    IFEND
  JOBEND

PROCEND activate_drje
