<?xml version="1.0" encoding="UTF-8"?>
<!--
  MAGEC RAD - Dictionary Entity Relationship XML
  Source:  https://magec.com/DOC/db_main.htm
           https://magec.com/DOC/markdown/04-glossary.md.txt
           https://magec.com/DOC/markdown/01-ai-assistant-facts.md.txt
  Diagram: ch09fig01.png  (Data Definition Reference Manual, Chapter 9)
  Generated by: aiMAGEC
-->

<MAGEC_Dictionary_ERD
  title="MAGEC RAD Data Dictionary Entity Relationship"
  source_diagram="ch09fig01.png"
  documentation="https://magec.com/DOC/db_main.htm">

  <!-- ═══════════════════════════════════════════════════════
       ENTITY DEFINITIONS
       Each entity corresponds to a MAGEC dictionary file.
       ═══════════════════════════════════════════════════════ -->

  <Entities>

    <Entity id="DCL" file="DCL" label="Data Class">
      <Description>
        The top-level dictionary object. Defines a logical view of a physical
        file — a collection of Elements grouped into a record. DCL is always
        required for MAGECIO to access any file. One DCL record exists per
        logical file (Data Class). The 3-character Data Class code becomes the
        prefix for all Element names and the Audit Stamp element name.
      </Description>
      <KeyField>3-character Data Class code (e.g., CUS, ORD, INV)</KeyField>
      <DocRef>https://magec.com/DOC/db_main.htm#db004000</DocRef>
      <Cardinality>One per logical file</Cardinality>
      <HierarchyLevel>1 — Root</HierarchyLevel>
    </Entity>

    <Entity id="KYF" file="KYF" label="Key File Definition">
      <Description>
        Defines keys (primary and alternate/secondary) for a Data Class. The
        KYF definition is mandatory for all files; MAGEC will
        Abend with DB99 if it is missing. After a successful DCLADD, MAGEC
        automatically presents the KYFADD screen for the primary key. Multiple
        KYF records may exist per DCL (one per key). The DD Name (z/OS DD
        statement) linking the physical VSAM dataset to CICS is held here.
        Primary keys conventionally end in K1 (e.g., CUSK1).
      </Description>
      <KeyField>Data Class code + Key suffix (e.g., CUSK1, CUSK2)</KeyField>
      <DocRef>https://magec.com/DOC/db_main.htm#db005006</DocRef>
      <Cardinality>One-to-many per DCL (primary + optional alternates)</Cardinality>
      <HierarchyLevel>2 — Child of DCL</HierarchyLevel>
    </Entity>

    <Entity id="ELT" file="ELT" label="Element Definition">
      <Description>
        Defines a logical grouping (portion) of a record — identified by a
        Displacement into the record and a Length. The Element is the smallest
        unit that MAGECIO can retrieve. ELT definitions are mandatory and must exist before DIT entries can be
        created. Element names are exactly 5 characters: first 3 = Data Class
        code, last 2 = element sequence (e.g., CUS01, CUS02). The Audit Stamp
        element is named DCLxx00 (e.g., CUS00) and is 36 bytes.
      </Description>
      <KeyField>5-character Element name (Data Class code + 2-digit seq)</KeyField>
      <DocRef>https://magec.com/DOC/db_main.htm#db003002</DocRef>
      <Cardinality>One-to-many per DCL</Cardinality>
      <HierarchyLevel>2 — Child of DCL</HierarchyLevel>
    </Entity>

    <Entity id="DIT" file="DIT" label="Data Item Definition">
      <Description>
        Defines individual fields (data items) within an Element. The Data Item
        is the MAGEC and COBOL equivalent of a "field." Each DIT record belongs
        to a specific ELT. DIT definitions drive automatic COBOL copybook
        generation, automatic screen editing, and Domain inheritance. DIT
        entries enable many automated MAGEC features including date editing,
        default value assignment, and DB2 host variable generation.
      </Description>
      <KeyField>Data Item name (COBOL dataname, prefixed by Data Class)</KeyField>
      <DocRef>https://magec.com/DOC/db_main.htm#db008000</DocRef>
      <Cardinality>One-to-many per ELT</Cardinality>
      <HierarchyLevel>3 — Child of ELT</HierarchyLevel>
    </Entity>

    <Entity id="BUS" file="(Library member)" label="Business Rules">
      <Description>
        COBOL-source routines stored in the MAGEC library, associated with an
        ELT. A Business Rule is triggered (invoked by MAGECIO) whenever a
        program updates or adds data for the specified Element. Primary purpose
        is data integrity enforcement: cross-field and cross-file validations,
        assigning automatic key values, setting defaults, and cascading updates
        or deletes. Business Rules can reference screen fields via -IFEXIST
        control commands and include other copybooks via -MAGECINC.
      </Description>
      <KeyField>Library member name (naming convention driven by ELT name)</KeyField>
      <DocRef>https://magec.com/DOC/db_main.htm#db017001</DocRef>
      <Cardinality>Zero-to-many per ELT</Cardinality>
      <HierarchyLevel>3 — Child of ELT (sibling of DIT)</HierarchyLevel>
    </Entity>

    <Entity id="CPY" file="(Library member)" label="COBOL Copybook">
      <Description>
        A stored COBOL source-code definition generated from the DIT
        definitions of an Element. Copybooks are stored on the MAGEC library
        and are automatically included (expanded) by MMPCREAT and MBPCREAT
        into generated MMP and MBP programs via -MAGECINC statements. They
        define the Working Storage data layout for each Element and ensure
        data independence — programs are insensitive to physical record changes
        because they reference the dictionary-driven copybook, not hard-coded
        layouts. Both Element copybooks and Screen Mask copybooks exist.
      </Description>
      <KeyField>Library member name (derived from Element name)</KeyField>
      <DocRef>https://magec.com/DOC/db_main.htm#db007000</DocRef>
      <Cardinality>One per ELT (generated artifact)</Cardinality>
      <HierarchyLevel>3 — Child of ELT (sibling of DIT and Business Rules)</HierarchyLevel>
    </Entity>

  </Entities>

  <!-- ═══════════════════════════════════════════════════════
       RELATIONSHIPS
       Describes the parent-child links shown in the diagram.
       ═══════════════════════════════════════════════════════ -->

  <Relationships>

    <Relationship id="R1">
      <Parent ref="DCL"/>
      <Child  ref="KYF"/>
      <Type>One-to-Many</Type>
      <Mandatory>
        Yes — KYF is mandatory for all files.
        DB99 abend occurs if missing when an MMP accesses the file.
      </Mandatory>
      <Description>
        A Data Class (DCL) owns one or more Key definitions (KYF): at minimum
        the Master/Primary Key (e.g., CUSK1), and optionally one or more
        Alternate/Secondary Keys for browse functions. MAGEC automatically
        prompts for KYFADD immediately after a successful DCLADD.
      </Description>
    </Relationship>

    <Relationship id="R2">
      <Parent ref="DCL"/>
      <Child  ref="ELT"/>
      <Type>One-to-Many</Type>
      <Mandatory>
        Yes — ELT definitions are mandatory and
        must exist before DIT entries can be defined.
        DB99 abend occurs if missing when an MMP accesses the file.
      </Mandatory>
      <Description>
        A Data Class (DCL) contains one or more Elements (ELT). Each ELT
        defines a displacement and length window into the physical record.
        The first ELT is typically the 36-byte Audit Stamp (e.g., CUS00).
      </Description>
    </Relationship>

    <Relationship id="R3">
      <Parent ref="ELT"/>
      <Child  ref="DIT"/>
      <Type>One-to-Many</Type>
      <Mandatory>
        Required to enable automated features (copybook generation, screen
        editing, DB2 host variable generation, domain inheritance, etc.).
      </Mandatory>
      <Description>
        Each Element (ELT) contains one or more Data Items (DIT) — the
        individual COBOL fields. DIT entries must reference a valid ELT.
        They drive automatic copybook generation and automatic screen edit
        validation in generated MMP programs.
      </Description>
    </Relationship>

    <Relationship id="R4">
      <Parent ref="ELT"/>
      <Child  ref="BUS"/>
      <Type>One-to-Many (optional)</Type>
      <Mandatory>
        No — Business Rules are optional. Zero or more may exist per ELT.
      </Mandatory>
      <Description>
        Business Rules are associated with an ELT and are invoked by MAGECIO
        whenever data for that Element is added or updated. They enforce
        referential integrity, cross-field validations, and automatic key
        assignment. Stored as COBOL source members in the MAGEC library.
      </Description>
    </Relationship>

    <Relationship id="R5">
      <Parent ref="ELT"/>
      <Child  ref="CPY"/>
      <Type>One-to-One (generated)</Type>
      <Mandatory>
        Generated artifact — produced by the MAGECLBR or MMPCREAT process
        from the DIT definitions belonging to the ELT.
      </Mandatory>
      <Description>
        Each Element (ELT) produces one COBOL Copybook stored on the MAGEC
        library. The copybook is automatically included into every generated
        MMP or MBP that accesses the Element via -MAGECINC. This mechanism
        provides data independence: changing the physical record requires only
        regenerating the copybook, not recoding the programs.
      </Description>
    </Relationship>

  </Relationships>

  <!-- ═══════════════════════════════════════════════════════
       READING ORDER (matches diagram top-to-bottom)
       ═══════════════════════════════════════════════════════ -->

  <HierarchySummary>
    <Level order="1" entity="DCL"
           note="Must be defined first. Root of all dictionary objects for a file."/>
    <Level order="2a" entity="KYF"
           note="Defined immediately after DCL. At least one (primary key) required."/>
    <Level order="2b" entity="ELT"
           note="Defined after DCL. Multiple Elements per file. Audit Stamp ELT is first."/>
    <Level order="3a" entity="DIT"
           note="Defined under each ELT. Individual COBOL fields. Drives copybook generation."/>
    <Level order="3b" entity="BusinessRules"
           note="Optional COBOL source members triggered by MAGECIO on ELT add/update."/>
    <Level order="3c" entity="CobolCopybook"
           note="Generated artifact per ELT. Included in MMP/MBP via -MAGECINC. Ensures data independence."/>
  </HierarchySummary>

  <!-- ═══════════════════════════════════════════════════════
       OPERATIONAL NOTES
       ═══════════════════════════════════════════════════════ -->

  <OperationalNotes>
    <Note id="N1">
      After any DCL, KYF, or ELT change, issue the LOAD Function Code in
      the SFUNCT field to reload MAGEC's main-memory dictionary tables without
      restarting CICS.
      Ref: https://magec.com/DOC/db_main.htm#db004002
    </Note>
    <Note id="N2">
      DB99 abend occurs when an MMP attempts file access and the DCL, KYF,
      or ELT definition is missing from the dictionary.
      Ref: https://magec.com/DOC/markdown/01-ai-assistant-facts.md.txt
    </Note>
    <Note id="N3">
      DB93 abend occurs when an Element name or Key name is inconsistent
      with its owning Data Class code.
      Ref: https://magec.com/DOC/markdown/01-ai-assistant-facts.md.txt
    </Note>
    <Note id="N4">
      The diagram shows multiple KYF and ELT boxes stacked to indicate that
      multiple instances (primary + alternates for KYF; multiple Elements for
      ELT) are permitted under a single DCL.
    </Note>
    <Note id="N5">
      MAGECIO — not the application programs — handles all physical file I/O.
      Programs communicate via the Request Area in the TWA. The dictionary
      hierarchy (DCL → KYF + ELT → DIT) is what MAGECIO reads at runtime to
      service those I/O requests.
      Ref: https://magec.com/DOC/db_main.htm
    </Note>
  </OperationalNotes>

</MAGEC_Dictionary_ERD>