<?xml version="1.0" encoding="UTF-8"?>
<!--
  MAGEC RAD - Logical Application (LAP) / Function Code / MMP Entity Relationship XML
  Source:  https://magec.com/DOC/sec_main.htm      (Security Reference Manual)
           https://magec.com/DOC/sectut_main.htm   (Security Administration Tutorial)
           https://magec.com/DOC/install_main.htm  (Installation Guide - file specs)
           https://magec.com/DOC/markdown/04-glossary.md.txt
           https://magec.com/DOC/markdown/01-ai-assistant-facts.md.txt
  Diagram: ch10fig01.png
  Title in diagram:  "LAP 01 -- Accounts Receivable"
  Left caption:   "Any number of Function Codes (CUSADD, IVCADD, CHECKS, CUSCHG)
                   can belong to one Logical Application (LAP)."
  Right caption:  "Any number of Function Codes can be processed by one MAGEC
                   Message Processor (MMP)."
  Generated by: aiMAGEC
-->

<MAGEC_Security_ERD
  title="MAGEC RAD Security Model: LAP → Function Codes → MMPs"
  source_diagram="ch10fig01.png"
  documentation_root="https://magec.com/DOC/">

  <!-- ═══════════════════════════════════════════════════════════════════
       DIAGRAM INTERPRETATION
       Three entity tiers are shown, with two distinct relationships:

         Tier 1 (top box):       LAP 01 — Accounts Receivable
                                 One Logical Application (LAP)

         Tier 2 (middle row):    Function Codes — CUSADD, CUSCHG,
                                 IVCADD, CHECKS   (four examples shown,
                                 many more are possible)

         Tier 3 (bottom row):    MMPs — MMP3A4, MMP55X, MMP325
                                 (three examples; CUSADD+CUSCHG share
                                 MMP3A4; IVCADD uses MMP55X; CHECKS
                                 uses MMP325)

       Relationship A:  LAP  ──<  Function Codes  (one-to-many)
         "Any number of Function Codes can belong to one LAP."

       Relationship B:  MMP  ──<  Function Codes  (one-to-many, reversed)
         "Any number of Function Codes can be processed by one MMP."

       The diagram therefore encodes BOTH:
         — Grouping of Function Codes under a LAP for security/menu
         — Sharing of a single MMP by multiple Function Codes for efficiency
       ═══════════════════════════════════════════════════════════════════ -->

  <!-- ═══════════════════════════════════════════════════════════════════
       ENTITY DEFINITIONS
       ═══════════════════════════════════════════════════════════════════ -->

  <Entities>

    <!-- ─────────────────────────────────────────────────
         ENTITY 1: LAP — Logical Application
         ───────────────────────────────────────────────── -->
    <Entity id="LAP" label="Logical Application">
      <FullName>Logical Application (LAP)</FullName>
      <DiagramExample>LAP 01 — Accounts Receivable</DiagramExample>
      <DictionaryFile>LAP — Logical Application file</DictionaryFile>
      <PhysicalSpecs>
        <LogicalRecordLength>77 bytes</LogicalRecordLength>
        <CISize>2048</CISize>
        <KeyDisplacement>36</KeyDisplacement>
        <KeyLength>2 characters (LAP number, e.g., 01)</KeyLength>
      </PhysicalSpecs>
      <Description>
        A Logical Application is a high-level grouping of related Function
        Codes — essentially, a named department or subsystem within the
        enterprise (e.g., "Accounts Receivable", "Payroll", "Inventory").

        MAGEC supports up to 50 Logical Applications (LAPs 01–50). Each
        operator has an individual Authorization Level (0–9) for each of the
        up to 50 LAPs in their security profile. This allows fine-grained
        access control: an operator might be level 5 in Accounts Receivable
        (LAP 01) but level 0 (no access) in Payroll (LAP 02).

        The MAGEC automated **MENU function dynamically generates and displays
        a menu of all Function Codes for which the logged-on operator holds the
        required Authorization Level in that LAP. The menu is thus driven
        entirely by the intersection of LAP/Function-Code security parameters
        and the operator's profile — no hardcoded menus exist.
      </Description>
      <AuthorizationLevelRange>
        0 = no access (lowest) through 9 = full access (highest).
        Each operator holds one level per LAP (up to 50 LAPs).
      </AuthorizationLevelRange>
      <HierarchyLevel>1 — Top (grouping entity)</HierarchyLevel>
      <DocRef>https://magec.com/DOC/sec_main.htm#sec007000</DocRef>
      <DocRef2>https://magec.com/DOC/sectut_main.htm#sectut004001</DocRef2>
    </Entity>

    <!-- ─────────────────────────────────────────────────
         ENTITY 2: Function Code
         ───────────────────────────────────────────────── -->
    <Entity id="FunctionCode" label="Function Code">
      <FullName>Function Code</FullName>
      <DiagramExamples>
        <Example code="CUSADD" meaning="Customer Add — adds a new customer record"/>
        <Example code="CUSCHG" meaning="Customer Change — updates an existing customer record"/>
        <Example code="IVCADD" meaning="Invoice Add — adds a new invoice record"/>
        <Example code="CHECKS" meaning="Checks — processes check/payment transactions"/>
      </DiagramExamples>
      <Description>
        A Function Code is the 6-character alphanumeric code that an operator
        types into the SFUNCT field (top-left of any MAGEC screen) to invoke a
        specific online operation. It is the primary unit of security control
        in MAGEC.

        Each Function Code is defined to:
          1. Belong to one Logical Application (LAP) — for menu grouping
             and authorization control.
          2. Be processed by one MMP (MAGEC Message Processor) — the
             generated COBOL/CICS online program that executes the function.

        The same MMP can handle multiple Function Codes (e.g., CUSADD and
        CUSCHG both map to MMP3A4 in the diagram). The MMP uses the Function
        Code value (stored in SFUNCT) to determine which processing path
        (add, change, delete, browse, etc.) to execute within its logic.

        Each Function Code definition in the security system also specifies:
          — The LAP it belongs to
          — The minimum Authorization Level required to invoke it
          — Whether it appears on the automated **MENU display
        The MAGEC automated menu system is driven by the security parameters
        defined for the operator versus for each Function Code.
      </Description>
      <EnteredIn>SFUNCT — the 6-character Function Code field on the top
        line of every MAGEC screen (also abbreviated SKEY area on top line).
      </EnteredIn>
      <NamingConvention>
        Conventionally: 3-char Data Class prefix + operation suffix.
        Examples: CUS=Customer, IVC=Invoice; ADD=add, CHG=change,
        BRW=browse, DEL=delete, INQ=inquiry, TOT=totals report, etc.
        The diagram also shows CHECKS as a less-structured example,
        indicating Function Codes need not strictly follow the prefix convention.
      </NamingConvention>
      <HierarchyLevel>2 — Middle (junction/association entity)</HierarchyLevel>
      <DocRef>https://magec.com/DOC/sec_main.htm#sec010006</DocRef>
      <DocRef2>https://magec.com/DOC/sec_main.htm#sec011000</DocRef2>
    </Entity>

    <!-- ─────────────────────────────────────────────────
         ENTITY 3: MMP — MAGEC Message Processor
         ───────────────────────────────────────────────── -->
    <Entity id="MMP" label="MAGEC Message Processor (MMP)">
      <FullName>MAGEC Message Processor (MMP)</FullName>
      <DiagramExamples>
        <Example id="MMP3A4" handlesFC="CUSADD, CUSCHG"
          note="One MMP handles both Customer Add and Customer Change"/>
        <Example id="MMP55X" handlesFC="IVCADD"
          note="Dedicated MMP for Invoice Add"/>
        <Example id="MMP325" handlesFC="CHECKS"
          note="Dedicated MMP for Checks processing"/>
      </DiagramExamples>
      <DictionaryFile>MMP — MMP definition file</DictionaryFile>
      <PhysicalSpecs>
        <LogicalRecordLength>100 bytes</LogicalRecordLength>
        <CISize>2048</CISize>
        <KeyDisplacement>0</KeyDisplacement>
        <KeyLength>3 characters (MMP number, e.g., 3A4, 55X, 325)</KeyLength>
      </PhysicalSpecs>
      <Description>
        An MMP (MAGEC Message Processor) is a COBOL/CICS online program
        generated by the MMPCREAT jobstream from the MAGEC dictionary
        specifications (SHD, SCF, and Algorithm definitions). It is the
        actual running program that responds to operator input for one or
        more Function Codes.

        Key design point: A single MMP can serve multiple Function Codes.
        The MMP tests the value in SFUNCT (the Function Code the operator
        entered) and branches to the appropriate processing logic (add path,
        change path, browse path, delete path, etc.). This reduces the
        number of CICS programs that must be loaded and maintained.

        The MMP operates in pseudo-conversational mode — MAGECCP saves
        and restores the TWA (Task Work Area) between operator interactions,
        making the application appear conversational to the user without
        tying up CICS resources during operator Think Time.

        Internally, the MMP delegates all file I/O to MAGECIO via the
        Request Area (TWA-DB-REQUEST), and all session control to MAGECCP.
        The developer never codes direct CICS/VSAM commands.
      </Description>
      <GeneratedBy>MMPCREAT jobstream (batch program generation)</GeneratedBy>
      <KeyField>3-character MMP number (alphanumeric, e.g., 3A4, 55X, 325)</KeyField>
      <HierarchyLevel>3 — Bottom (executing program entity)</HierarchyLevel>
      <DocRef>https://magec.com/DOC/sec_main.htm#sec011014</DocRef>
      <DocRef2>https://magec.com/DOC/install_main.htm</DocRef2>
    </Entity>

  </Entities>

  <!-- ═══════════════════════════════════════════════════════════════════
       RELATIONSHIPS
       Two distinct one-to-many relationships shown in ch10fig01.png
       ═══════════════════════════════════════════════════════════════════ -->

  <Relationships>

    <!-- Relationship A: LAP owns many Function Codes -->
    <Relationship id="R1" label="LAP groups Function Codes">
      <Parent ref="LAP"/>
      <Child  ref="FunctionCode"/>
      <Type>One-to-Many</Type>
      <DiagramCaption>
        "Any number of Function Codes (CUSADD, IVCADD, CHECKS, CUSCHG)
        can belong to one Logical Application (LAP)."
      </DiagramCaption>
      <Cardinality>
        <ParentSide>One LAP (e.g., LAP 01 — Accounts Receivable)</ParentSide>
        <ChildSide>Many Function Codes (CUSADD, CUSCHG, IVCADD, CHECKS,
          and any other function in that subsystem)</ChildSide>
      </Cardinality>
      <Purpose>
        Security and menu grouping. The LAP is the unit by which operators
        are granted or denied access to groups of related functions. The
        **MENU function dynamically builds the operator's menu from all
        Function Codes in the LAP for which the operator has the minimum
        required Authorization Level.
      </Purpose>
      <JoinKey>
        LAP number stored in each Function Code's security definition.
        Operators hold an Authorization Level (0-9) per LAP number.
      </JoinKey>
      <DocRef>https://magec.com/DOC/sec_main.htm#sec011018</DocRef>
      <DocRef2>https://magec.com/DOC/sectut_main.htm#sectut004001</DocRef2>
    </Relationship>

    <!-- Relationship B: MMP handles many Function Codes -->
    <Relationship id="R2" label="MMP processes many Function Codes">
      <Parent ref="MMP"/>
      <Child  ref="FunctionCode"/>
      <Type>One-to-Many</Type>
      <DiagramCaption>
        "Any number of Function Codes can be processed by one MAGEC
        Message Processor (MMP)."
      </DiagramCaption>
      <Cardinality>
        <ParentSide>One MMP (e.g., MMP3A4)</ParentSide>
        <ChildSide>One or more Function Codes (e.g., CUSADD and CUSCHG
          are both handled by MMP3A4 in the diagram example)</ChildSide>
      </Cardinality>
      <Purpose>
        Runtime dispatch and efficiency. A single generated MMP program
        can handle logically related Function Codes (typically the full
        standard set for a Data Class: ADD, CHG, DEL, INQ, BRW, etc.).
        The MMP inspects SFUNCT at runtime to route execution to the
        correct processing path (ADD logic, CHG logic, DEL logic, etc.).
        This reduces the number of CICS programs in the PCT and minimizes
        storage requirements.
      </Purpose>
      <JoinKey>
        MMP number stored in each Function Code's definition. MAGECCP
        resolves the Function Code to its MMP number, then issues the
        CICS XCTL or equivalent to invoke that MMP.
      </JoinKey>
      <DocRef>https://magec.com/DOC/sec_main.htm#sec011014</DocRef>
      <DocRef2>https://magec.com/DOC/sec_main.htm#sec010006</DocRef2>
    </Relationship>

  </Relationships>

  <!-- ═══════════════════════════════════════════════════════════════════
       DIAGRAM INSTANCE — mapping the specific diagram entities
       ═══════════════════════════════════════════════════════════════════ -->

  <DiagramInstance source="ch10fig01.png">

    <LAPInstance id="LAP01" name="Accounts Receivable">
      <FunctionCodeInstance code="CUSADD" description="Customer Add"     MMP="MMP3A4"/>
      <FunctionCodeInstance code="CUSCHG" description="Customer Change"  MMP="MMP3A4"/>
      <FunctionCodeInstance code="IVCADD" description="Invoice Add"      MMP="MMP55X"/>
      <FunctionCodeInstance code="CHECKS" description="Checks/Payments"  MMP="MMP325"/>
    </LAPInstance>

    <MMPInstance id="MMP3A4"
      note="Handles both CUSADD and CUSCHG — a common MAGEC pattern
            where add and change share one generated MMP, with internal
            branching on SFUNCT value."/>
    <MMPInstance id="MMP55X"
      note="Dedicated MMP for Invoice Add function."/>
    <MMPInstance id="MMP325"
      note="Dedicated MMP for Checks processing function."/>

    <KeyObservation>
      The diagram deliberately shows MMP3A4 serving TWO function codes
      (CUSADD and CUSCHG) to illustrate that sharing a single MMP across
      multiple Function Codes is a standard MAGEC efficiency pattern,
      not an exception. MMP55X and MMP325 each serve one Function Code
      in this example, which is also valid.
    </KeyObservation>

  </DiagramInstance>

  <!-- ═══════════════════════════════════════════════════════════════════
       OPERATIONAL NOTES
       ═══════════════════════════════════════════════════════════════════ -->

  <OperationalNotes>

    <Note id="N1">
      The MAGEC automated **MENU function dynamically generates the menu
      screen from the dictionary — no hardcoded menu programs are needed.
      It shows only the Function Codes in the current LAP for which the
      logged-on operator has sufficient Authorization Level.
      Ref: https://magec.com/DOC/sec_main.htm#sec011018
    </Note>

    <Note id="N2">
      Operators hold an Authorization Level (0–9) for each of up to 50
      LAPs. The lesser of the terminal's maximum level and the operator's
      profile level applies at runtime (double-gating security).
      Ref: https://magec.com/DOC/markdown/04-glossary.md.txt (Authorization Level)
    </Note>

    <Note id="N3">
      The SFUNCT field (6 characters, top-left of every MAGEC screen) is
      where the operator enters the Function Code. MAGECCP intercepts this,
      validates the operator's authorization, resolves the MMP number, and
      dispatches to the correct MMP via CICS XCTL or equivalent.
      Ref: https://magec.com/DOC/sec_main.htm#sec010006
    </Note>

    <Note id="N4">
      A standard set of nine Function Codes is provided per Data Class
      by MAGEC (ADD, CHG, DEL, INQ, BRW, LOC, FND, SCN, and more).
      The developer may also define custom Function Codes beyond this
      standard set.
      Ref: https://magec.com/DOC/app_main.htm#app017001
    </Note>

    <Note id="N5">
      All Spooler online functions are defined as belonging to Logical
      Application number 48. This illustrates that LAPs are used system-wide,
      not only for custom application functions.
      Ref: https://magec.com/DOC/splr_main.htm
    </Note>

    <Note id="N6">
      The MMP definition file (3-char key) contains the high-level
      definitions for each MAGEC Message Processor (online program).
      Each MMP is registered in the CICS PCT so CICS can dispatch it.
      Ref: https://magec.com/DOC/install_main.htm
    </Note>

  </OperationalNotes>

</MAGEC_Security_ERD>