PROCEDURE dum$process_active_job_list, process_active_job_list, proajl (
  ajl_ordinal, ao: any of
      key (all a) keyend
      integer
    anyend = all
  include_monitor, im: boolean = TRUE
  output, o: file = $output
  status)

" This procedure performs an analysis of all tasks in all jobs
" which are currently active (have ajl entries), plus monitor.

  VAR
    cctqm: string 0..256 = '???????????????????????????????? !"#$%&''()*+,-./0123456789:;<=>?@'//..
          'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~?????????????????????'//..
          '???????????????????????????????????????????????????????????????????????????????????'//..
          '?????????????????????????'
    jmv$jcb: integer = 300000000(16)              "($sa(jmv$jcb))
    job_fixed_seg_num: integer = 14(16)           "relative to monitor address space
    job_monitor_xcb_offset: integer = 100(16)     "from start of job fixed
  VAREND

  VAR
    adr: integer
    ajl: integer
    ajl_entry_size: integer
    ajl_ord: integer
    ajl_p: integer
    field_length: integer
    field_offset: integer
    function: integer
    gtid: integer
    jcb: integer
    job_monitor_xcb: integer
    job_name: integer
    last_ajl_ordinal: integer
    len: integer
    line: string
    line2: string
    link: integer
    local_file: file = $fname('$local.'//$unique)
    local_status: status
    mcr: integer
    monitor_functions: ARRAY 0..74 OF string
    number_of_entries: integer
    output_file: file
    pva: integer
    start_ajl_ordinal: integer
    str2: string
    system_ajl_ordinal: integer
    task_name: integer
    task_xcb: integer
    temp_file: file = $fname('$local.'//$unique)
    title_string: string
    top_of_page_needed: boolean = TRUE
    user_id: integer
  VAREND

  IF $file(output open_position) = '$BOI' THEN
    delete_file f=output status=local_status
    set_file_attributes f=output fc=list
  IFEND
  output_file = output.$eoi
  set_file_attributes f=temp_file fc=unknown

  put_line l='1COMMAND: PROCESS_ACTIVE_JOB_LIST' o=output_file
  put_line l=' ' o=output_file

  change_default e=monitor am=pva
  IF include_monitor THEN
    display_call e=monitor do=(f s) t='monitor call chain' o=temp_file
    copy_file i=temp_file o=output_file
  IFEND

  ost$execution_control_block field=SAVE9 offset=field_offset length=field_length
  task_name = field_offset/8                            "offset into the XCB
  ost$execution_control_block field=GLOBAL_TASK_ID offset=field_offset length=field_length
  gtid = field_offset/8                                 "offset into the XCB to GTID
  ost$execution_control_block field=LINK offset=field_offset length=field_length
  link = field_offset/8                                 "offset into xcb
  jmt$job_control_block field=JOBNAME offset=field_offset length=field_length
  job_name = field_offset/8                             "offset into job control block
  jmt$job_control_block field=USER_ID offset=field_offset length=field_length
  user_id = field_offset/8                              "offset into job control block

  ajl_p = $symbol_address(jmv$ajl_p)
  ajl = $memory(ajl_p)
  IF $nil_pva(ajl) THEN
    put_line l=' The active job list has not yet been established.' o=output_file
    EXIT PROCEDURE
  IFEND

  ajl_entry_size = $memory(ajl_p+14 4)
  system_ajl_ordinal = $memory(ajl_p+10 4)
  number_of_entries = $memory(ajl_p+6 4) / ajl_entry_size

  last_ajl_ordinal = system_ajl_ordinal + number_of_entries - 1
  change_processor_register ..
        jps=$rma(((system_ajl_ordinal + job_fixed_seg_num)*100000000(16))+job_monitor_xcb_offset)
  change_default e=job

  create_monitor_func_file f=local_file
  accept_line v=monitor_functions i=local_file
  detach_file f=local_file

  IF $value_kind(ajl_ordinal) = 'INTEGER' THEN
    start_ajl_ordinal = ajl_ordinal
    IF start_ajl_ordinal > last_ajl_ordinal THEN
      put_line l=' The selected ordinal is beyond the end of the active job list.' o=output_file
      EXIT PROCEDURE
    IFEND
    last_ajl_ordinal = start_ajl_ordinal
  ELSE
    start_ajl_ordinal = system_ajl_ordinal
  IFEND

  FOR ajl_ord = start_ajl_ordinal TO last_ajl_ordinal DO
    jcb = ((ajl_ord + job_fixed_seg_num) * 100000000(16))
    pva = jcb + job_monitor_xcb_offset
    include_line sl='display_value v=$rma(jcb monitor) o=$null' status=local_status
    IF local_status.normal THEN
      jcb = $memory(jcb 1 m)
    ELSE
      jcb = 0
    IFEND

    IF jcb = 255 THEN
      put_line l='1*************************************************************************' o=output_file
      put_line l=' processing ajl ordinal '//$strrep(ajl_ord,16) o=output_file
      top_of_page_needed = FALSE

      job_monitor_xcb = $rma(pva monitor)
      change_processor_register jps=job_monitor_xcb

      IF ajl_ord <> system_ajl_ordinal THEN
        put_line l=' job name = '//$trim($translate(cctqm $memory_string(jmv$jcb+job_name 31))) o=output_file
      IFEND
      put_line l=' user id = '//$trim($translate(cctqm $memory_string(jmv$jcb+user_id 31))) o=output_file
      put_line l=' -------------------------------------------------------------------------' o=output_file

      task_xcb = $memory($symbol_address(job_xcb_list))
      IF ($memory(task_xcb+88 2)*10000(16)+$memory(task_xcb+96 2)) = 7fffffff(16) THEN
        task_xcb = $memory(task_xcb+link)
      IFEND

      process_tasks: ..
      REPEAT
        change_processor_register jps=$rma(task_xcb)
        IF $job(mode) = 'INTERACTIVE' THEN
          line2 = 'Task name = '//$trim($translate(cctqm $memory_string((task_xcb+task_name) 31)))
          IF top_of_page_needed THEN
            line2 = '1'//line2
          ELSE
            line2 = ' '//line2
            top_of_page_needed = TRUE
          IFEND
          put_line l=line2 o=output_file
          put_line l=' GTID = '//$strrep($memory(task_xcb+gtid 3) 16) o=output_file
          mcr = $process_register(mcr) / 10(16)
          IF mcr = ((mcr / 2) * 2) THEN
            function = $memory(task_xcb+088(16) 1)
            IF (function > 0) AND (function < 75) THEN
              put_line l=' monitor request = '//monitor_functions(function) o=output_file
              adr = task_xcb+17*8
              line = '    '
              for i=1 to 8
                str2 = '00000000'//$strrep($memory(adr 4) 16)
                len = $strlen(str2)
                line = line//'  '//$substr(str2 len-7 8)
                adr = adr + 4
              forend
              put_line l=line o=output_file
            IFEND
          IFEND
        IFEND
        title_string = $strrep(ajl_ord)//' '//$memory_string((task_xcb+task_name) 31)
        display_call e=job o=temp_file t=$substring(title_string 1 31 ' ')
        copy_file i=temp_file o=output_file
        EXIT process_tasks WHEN $rma(task_xcb) = job_monitor_xcb
        task_xcb = $mem(task_xcb+link)
        put_line l=' -------------------------------------------------------------------------' o=output_file
      UNTIL $nil_pva(task_xcb)
    IFEND
  FOREND

  detach_file f=temp_file status=local_status

PROCEND dum$process_active_job_list
