<?xml version="1.0" encoding="UTF-8"?>
<!-- 
  MAGEC RAD - Explanation of OUTPUT PROCEDURE Flowchart (Figure 08)
  Source Diagram: ch05fig08.png (Batch OUTPUT PROCEDURE) 
  Cross-referenced with: diags_main.htm, insert_main.htm, masteridx.htm
  Generated by aiMAGEC for diagram explanation.
  Date: Current session
-->

<outputProcedureFlowchart 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  diagramId="ch05fig08"
  function="OUTPUT PROCEDURE (Batch)"
  docSource="https://magec.com/DOC/diags_main.htm"
  masterIndex="https://magec.com/DOC/masteridx.htm">

  <overview>
    <description>
      This flowchart depicts the logical processing flow for the standard OUTPUT PROCEDURE in a MAGEC-generated batch report program (typically used after a SORT with INPUT PROCEDURE). 
      It handles return of sorted records, control break processing, total accumulation, line counting with headings, and report ending logic.
    </description>
    <note>
      This is a batch OUTPUT PROCEDURE. It processes records returned from the sort, performs control breaks, adds totals, prints detail and heading lines, and ends the report properly.
    </note>
  </overview>

  <flow>
    <!-- Top Level -->
    <step id="start" label="START of OUTPUT PROCEDURE" />

    <step id="report-start" label="CA100-REPORT">
      <branches>
        <branch condition="ZERO RECORDS SORTED from Input Procedure" next="END of OUTPUT PROCEDURE" />
      </branches>
      <next>CA110-RETURN</next>
    </step>

    <step id="return" label="CA110-RETURN">
      <insertionPoint>%RETURN</insertionPoint>
      <next>First Record Decision</next>
    </step>

    <step id="first-rec" label="FIRST REC ?">
      <branches>
        <branch condition="YES" next="CA115-CHECK-FOR-BREAKS" />
        <branch condition="AT END" next="%RPTEND" />
      </branches>
    </step>

    <!-- Main Processing -->
    <step id="check-breaks" label="CA115-CHECK-FOR-BREAKS">
      <insertionPoint>%BREAKS</insertionPoint>
      <branches>
        <branch condition="CTL BREAK" next="DB100-BREAK" />
      </branches>
      <next>CA120-SAVE-KEYS</next>
    </step>

    <step id="save-keys" label="CA120-SAVE-KEYS">
      <insertionPoint>%SVPREV</insertionPoint>
      <next>CA130-ADD-TOTALS</next>
    </step>

    <step id="add-totals" label="CA130-ADD-TOTALS">
      <insertionPoint>%ADDTOT</insertionPoint>
      <next>CA130-ADD-TOTALS (continued)</next>
    </step>

    <step id="move-to-print" label="CA130-ADD-TOTALS">
      <insertionPoint>%MVTOPRT</insertionPoint>
      <next>Line Counter Check</next>
    </step>

    <!-- Line Control -->
    <step id="line-check" label="LINE CTR NOT > MAX ?">
      <branches>
        <branch condition="NO (LINE CTR > MAX)" next="DA200-HDG" />
      </branches>
      <next>Detail Print (implied)</next>
    </step>

    <step id="heading" label="DA200-HDG">
      <insertionPoint>%HDGPRT</insertionPoint>
      <next>Loop back to return</next>
    </step>

    <!-- Control Break Path -->
    <step id="break" label="DB100-BREAK">
      <insertionPoint>%ROLLAC</insertionPoint>
      <next>DC200-BREAK-PRINT</next>
    </step>

    <step id="break-print" label="DC200-BREAK-PRINT">
      <insertionPoint>%BRKPRT</insertionPoint>
      <next>CA190-END</next>
    </step>

    <!-- End Path -->
    <step id="rptend" label="CA190-END">
      <insertionPoint>%RPTEND</insertionPoint>
      <next>ZZ90-EOJ</next>
    </step>

    <step id="eoj" label="ZZ90-EOJ">
      <insertionPoint>%EOJ</insertionPoint>
      <next>END of OUTPUT PROCEDURE</next>
    </step>

    <step id="end" label="END of OUTPUT PROCEDURE" />
  </flow>

  <keyInsertionPoints>
    <point name="%RETURN" />
    <point name="%BREAKS" />
    <point name="%ROLLAC" />
    <point name="%SVPREV" />
    <point name="%ADDTOT" />
    <point name="%MVTOPRT" />
    <point name="%HDGPRT" />
    <point name="%BRKPRT" />
    <point name="%RPTEND" />
    <point name="%EOJ" />
  </keyInsertionPoints>

  <references>
    <link href="https://magec.com/DOC/diags_main.htm">Processing Diagrams - Figure 08 OUTPUT PROCEDURE</link>
    <link href="https://magec.com/DOC/insert_main.htm">Insertion Points Reference</link>
    <link href="https://magec.com/DOC/masteridx.htm">Master Index (search for %RETURN, %BREAKS, %RPTEND, %EOJ, etc.)</link>
  </references>

</outputProcedureFlowchart>