<?xml version="1.0" encoding="UTF-8"?>
<!-- 
  MAGEC RAD - Explanation of INPUT PROCEDURE Flowchart (Figure 07)
  Source Diagram: ch05fig07.png (Batch INPUT PROCEDURE) 
  Cross-referenced with: diags_main.htm, insert_main.htm, masteridx.htm
  Generated by aiMAGEC for diagram explanation.
  Date: Current session
-->

<inputProcedureFlowchart 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  diagramId="ch05fig07"
  function="INPUT 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 INPUT PROCEDURE in a MAGEC-generated batch program (typically used with SORT or report generation). 
      It reads records from the primary file (via browse), performs logical joins, selection logic, optional bypassing, and releases qualified records to the sort/work file.
    </description>
    <note>
      This is a batch INPUT PROCEDURE. It handles initial record retrieval, end-of-file conditions, record selection, and release to sort. 
      It supports %SELECT logic for filtering and %MYTOSRT for releasing records to the sort process.
    </note>
  </overview>

  <flow>
    <!-- Top Level -->
    <step id="start" label="START of INPUT PROCEDURE">
      <next>PROCEDURE DIVISION</next>
    </step>

    <step id="preinit" label="PROCEDURE DIVISION">
      <insertionPoint>%PREINIT</insertionPoint>
      <next>AA100-BEGIN</next>
    </step>

    <step id="initws" label="AA100-BEGIN">
      <insertionPoint>%INITWS</insertionPoint>
      <next>BA102-START-BROWSE</next>
    </step>

    <step id="start-browse-lock" label="BA102-START-BROWSE">
      <insertionPoint>%MGLOCKY</insertionPoint>
      <next>BA102-START-BROWSE (continued)</next>
    </step>

    <step id="start-browse-read" label="BA102-START-BROWSE">
      <insertionPoint>%MGREDLE</insertionPoint>
      <next>Initial Read Decision</next>
    </step>

    <!-- Initial Read Decision -->
    <step id="initial-read" label="REC FOUND ?">
      <branches>
        <branch condition="NOT FOUND (no input data)" next="%EOF" />
        <branch condition="REC FOUND" next="BA110-READ-NEXT" />
      </branches>
    </step>

    <!-- Main Read Loop -->
    <step id="read-next" label="BA110-READ-NEXT">
      <insertionPoint>%MGREDNX</insertionPoint>
      <next>%JOIN</next>
    </step>

    <step id="logical-join" label="JA100-LOGICAL-JOIN">
      <insertionPoint>%JOIN</insertionPoint>
      <next>BA115-SELECT</next>
    </step>

    <step id="select" label="BA115-SELECT">
      <insertionPoint>%SELECT</insertionPoint>
      <next>BA150-RELEASE</next>
    </step>

    <!-- Release Decision -->
    <step id="release-decision" label="BA150-RELEASE">
      <branches>
        <branch condition="BYPASS INDICATED" next="BA110-READ-NEXT (loop)" />
        <branch condition="END INDICATED" next="%EOF" />
        <branch condition="PROCESS INDICATED" next="%MYTOSRT" />
      </branches>
    </step>

    <step id="mytosrt" label="Release to Sort">
      <insertionPoint>%MYTOSRT</insertionPoint>
      <next>BA110-READ-NEXT (loop back)</next>
    </step>

    <!-- End -->
    <step id="eof" label="%EOF">
      <insertionPoint>%EOF</insertionPoint>
      <next>END of INPUT PROCEDURE</next>
    </step>

    <step id="end" label="END of INPUT PROCEDURE" />
  </flow>

  <keyInsertionPoints>
    <point name="%PREINIT" />
    <point name="%INITWS" />
    <point name="%MGLOCKY" />
    <point name="%MGREDLE" />
    <point name="%MGREDNX" />
    <point name="%JOIN" />
    <point name="%SELECT" />
    <point name="%MYTOSRT" />
    <point name="%EOF" />
  </keyInsertionPoints>

  <references>
    <link href="https://magec.com/DOC/diags_main.htm">Processing Diagrams - Figure 07 INPUT 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 %MGREDNX, %SELECT, %MYTOSRT, %EOF, etc.)</link>
  </references>

</inputProcedureFlowchart>