ontoloji.orgOpen Reference Hub
ERP & SQL Ontology14 min read·Updated: 2026-12-05·Türkçe sürüm →

Logo Tiger STLINE & Sales View SQL Forensics: Karmakoli, TRCODE 14, 120.GR & UINFO1 Traps

Why 63% of initial industrial ERP AI errors stem from undocumented column semantics: Karmakoli bundle proration, TRCODE 14 tonnage inflation, UINFO1 = 1 weight bugs, and 120.GR revenue contamination.

Executive Summary — Key Takeaways
  • 01Empirical rollout data across industrial ERP deployments shows 60–62% of plant natural-language questions compile to relational SQL, and 63% of initial AI errors come from undocumented column and view semantics.
  • 02In LG_XXX_YY_STLINE, naive SUM(TOTAL) double-counts Karmakoli mixed bundles (LINETYPE 6 & 7), while failing to zero AMOUNT on Price-Difference Invoices (TRCODE = 14) inflates physical tonnage.
  • 03Reporting views that hardcode UINFO1 = 1 or expose MT_KG helper columns corrupt pipe/profile METRE -> KG weights and leak raw piece counts (BIRIM_KODU = 'AD.') into steel tonnage.
  • 04120.GR.XXXXX inter-branch transfers inflate external turnover by 18–35%, FATURA_OZEL_KODU mutates from salesperson ID to "601" on exports, and LOGICALREF resets across fiscal years unless keyed by (FIRMNR, PERIODNR, LOGICALREF).

1. The 63% Schema-Mismatch Reality in Industrial ERP AI Rollouts

Production telemetry from manufacturing and metal service center ERP deployments establishes two sobering baselines: 60–62% of factory and executive natural-language questions compile directly to SQL, yet 63% of initial AI accuracy failures trace back to undocumented column, status-code, and SQL view semantics rather than syntax errors.

Even when an integrator has built seemingly clean reporting views (VW_SALES_SUMMARY) with readable column names like MIKTAR (Quantity), TUTAR (Amount), MT_KG, and FATURA_OZEL_KODU, raw Text-to-SQL agents fail silently. Beneath those tidy names lie mixed-bundle parent rows, retroactive price-adjustment invoices with phantom quantities, inter-branch ledger transfers, and primary keys that reset every January.

Why Clean SQL View Column Names Deceive LLMs

An undocumented integrator SQL view is often more dangerous to an LLM than raw LG_XXX_YY_STLINE tables: the view author’s shortcuts—such as hardcoding UINFO1 = 1 or falling back to raw piece counts inside MT_KG—look like authoritative truth in INFORMATION_SCHEMA.COLUMNS.

2. LG_XXX_YY_STLINE Financial & Bundle Math: Karmakoli, TRCODE 14 & Conditional CLIENTREF

Every material movement, dispatch, and invoice line in Logo Tiger flows through LG_XXX_YY_STLINE. Reconciling AI-generated revenue and tonnage to audited financial statements requires compiling four non-obvious invariants into every query:

  • Karmakoli Mixed Bundles (LINETYPE = 6 Parent & LINETYPE = 7 Component Lines): On mixed-bundle sales, LINETYPE = 6 stores the commercial bundle header and header-level distributed discount (DISTDISC), while LINETYPE = 7 rows record the physical component items deducted from stock. Summing all rows double-counts revenue (~2x); filtering only LINETYPE = 7 loses bundle discounts. Component rows must self-join back to the parent (KK) via PREVLINEREF = KK.LOGICALREF and PREVLINENO = KK.INVOICELNNO (with KKS summing sibling components if KK.TOTAL is zero) to prorate DISTDISC ((STLINE.TOTAL / NULLIF(KK.TOTAL, 0)) * KK.DISTDISC) and reconstruct exact VATMATRAH.
  • Price-Difference Invoices (Fiyat Farkı Faturası, TRCODE = 14 + DECPRDIFF = 1) & Promotions (LINETYPE = 1): Logo stores a non-zero reference AMOUNT (MIKTAR) on TRCODE = 14 invoices so unit-price difference multiplication works on the invoice form—even though zero physical goods moved. Unless SQL forces AMOUNT = 0 on TRCODE = 14, retroactive price adjustments inflate shipped tonnage by hundreds of tons! Net totals must flip negative on sales returns (TRCODE IN (2, 3)) AND downward price-difference invoices (TRCODE = 14 AND DECPRDIFF = 1), while promotion lines (LINETYPE = 1) keep physical stock quantity but zero out unit price and net revenue.
  • Conditional CLIENTREF Routing, LG_SLSMAN & SPECODES Collation: Joining customer master LG_XXX_CLCARD requires INVOICE.CLIENTREF when STLINE.LINETYPE IN (0, 4, 11) (billed material, service, subcontracting/fixed-asset lines) versus STFICHE.CLIENTREF otherwise. Cross-firm salespeople in LG_SLSMAN carry FIRMNR = -1 (filtering FIRMNR = XXX drops active reps), and LG_XXX_SPECODES joins require COLLATE database_default to avoid Turkish_CI_AS vs. SQL_Latin1_General_CP1_CI_AS crashes.
  • Cross-Year LOGICALREF (KAYIT_ADRESI) Resets: Fiscal-period tables (LG_301_01_STLINE, LG_301_02_STLINE, INVOICE, STFICHE) reset LOGICALREF back to 1 in every new fiscal period (YY) and firm (XXX) shard. Keying warehouse tables or entity caches by LOGICALREF / KAYIT_ADRESI alone collides unrelated cross-year records unless keyed by (FIRMNR, PERIODNR, LOGICALREF).
Production Logo Tiger STLINE Ontology SQL: Karmakoli Proration, TRCODE 14 Zero-Quantity Guard & ITMUNITA Weight
SELECT
    CONCAT('301_', '01_', CAST(STL.LOGICALREF AS VARCHAR(20))) AS CANONICAL_LINE_ID,
    CLC.CODE AS CUSTOMER_CODE,
    ITM.CODE AS ITEM_CODE,
    -- 1. Tonnage Guard: Force physical quantity to 0 on Price-Difference (TRCODE = 14), Service (4) & Bundle Header (6)
    CASE
        WHEN INV.TRCODE = 14 OR STL.LINETYPE IN (4, 6) THEN 0.0
        WHEN INV.TRCODE IN (2, 3) THEN -1.0 * STL.AMOUNT
        ELSE STL.AMOUNT
    END AS NET_PHYSICAL_QTY,
    -- 2. True KG Conversion: Join LG_XXX_ITMUNITA (LINENR = 2) instead of trusting hardcoded UINFO1 = 1
    CASE
        WHEN INV.TRCODE = 14 OR STL.LINETYPE IN (4, 6) THEN 0.0
        WHEN UOM.CODE = 'KG' THEN STL.AMOUNT * (CASE WHEN INV.TRCODE IN (2, 3) THEN -1.0 ELSE 1.0 END)
        WHEN UOM.CODE = 'MT' AND ITMU_KG.CONVFACT1 > 0
            THEN (STL.AMOUNT * (ITMU_KG.CONVFACT1 / NULLIF(ITMU_KG.CONVFACT2, 0)))
                 * (CASE WHEN INV.TRCODE IN (2, 3) THEN -1.0 ELSE 1.0 END)
        ELSE NULL -- Never leak raw piece counts (BIRIM_KODU = 'AD.') into kilogram totals!
    END AS VERIFIED_NET_KG,
    -- 3. Zero unit price on Promotion lines (LINETYPE = 1)
    CASE WHEN STL.LINETYPE = 1 THEN 0.0 ELSE STL.PRICE END AS EFFECTIVE_UNIT_PRICE,
    -- 4. Karmakoli (LINETYPE = 7) DISTDISC Proration, Promotion Zeroing & DECPRDIFF Sign Inversion
    CASE
        WHEN STL.LINETYPE IN (1, 6) THEN 0.0
        ELSE (
            CASE
                WHEN STL.LINETYPE = 7 AND KK.LOGICALREF IS NOT NULL
                    THEN STL.TOTAL - ((STL.TOTAL / COALESCE(NULLIF(KK.TOTAL, 0), NULLIF(KKS.COMP_GROSS_TOTAL, 0))) * KK.DISTDISC)
                ELSE STL.VATMATRAH
            END
        ) * (
            CASE
                WHEN INV.TRCODE IN (2, 3) OR (INV.TRCODE = 14 AND INV.DECPRDIFF = 1) THEN -1.0
                ELSE 1.0
            END
        )
    END AS RECONCILED_NET_REVENUE
FROM LG_301_01_STLINE AS STL
LEFT JOIN LG_301_01_STFICHE AS STF ON STF.LOGICALREF = STL.STFICHEREF
LEFT JOIN LG_301_01_INVOICE AS INV ON INV.LOGICALREF = STL.INVOICEREF
-- Self-join Karmakoli bundle header (KK, LINETYPE = 6) + sibling gross fallback (KKS)
LEFT JOIN LG_301_01_STLINE AS KK
    ON STL.LINETYPE = 7
   AND KK.LOGICALREF = STL.PREVLINEREF
   AND KK.INVOICELNNO = STL.PREVLINENO
   AND KK.LINETYPE = 6
OUTER APPLY (
    SELECT SUM(SIB.TOTAL) AS COMP_GROSS_TOTAL
    FROM LG_301_01_STLINE AS SIB
    WHERE KK.LOGICALREF IS NOT NULL
      AND SIB.PREVLINEREF = KK.LOGICALREF
      AND SIB.LINETYPE = 7
) AS KKS
-- Conditional CLIENTREF routing by LINETYPE
LEFT JOIN LG_301_CLCARD AS CLC
    ON CLC.LOGICALREF = CASE
        WHEN STL.LINETYPE IN (0, 4, 11) THEN INV.CLIENTREF
        ELSE STF.CLIENTREF
    END
LEFT JOIN LG_301_ITEMS AS ITM ON ITM.LOGICALREF = STL.STOCKREF
LEFT JOIN LG_301_UNITSETL AS UOM ON UOM.LOGICALREF = STL.UOMREF
LEFT JOIN LG_301_ITMUNITA AS ITMU_KG
    ON ITMU_KG.ITEMREF = STL.STOCKREF AND ITMU_KG.LINENR = 2
LEFT JOIN LG_SLSMAN AS SLS
    ON SLS.LOGICALREF = STL.SALESMANREF AND SLS.FIRMNR IN (301, -1)
LEFT JOIN LG_301_SPECODES AS SPC
    ON SPC.SPECODE COLLATE database_default = STL.SPECODE COLLATE database_default
   AND SPC.CODETYPE = 1 AND SPC.SPECODETYPE = 1
WHERE STL.CANCELLED = 0
  AND COALESCE(INV.CANCELLED, 0) = 0
  AND COALESCE(CLC.SPECODE5, '') <> 'LÇ'
  AND CLC.CODE NOT LIKE '120.GR.%';

3. Unit-of-Measure (UINFO1 = 1 & MT_KG) Tonnage Corruption & Sheet-Metal Group Fragmentation

In steel service centers, pipe/profile mills, and heavy industrial distributors, invoice lines mix KG (coils/sheets), MT (meters of pipe or structural profile), and AD. (individual cut plates, flanges, or consumables). Standard ERP reporting views silently corrupt physical tonnage through four recurring traps:

  • Hardcoded UINFO1 / UINFO2 = 1 Instead of LG_XXX_ITMUNITA: Many reporting views either hardcode UINFO1 = 1 / UINFO2 = 1 or trust unpopulated STLINE.UINFO1/UINFO2 line factors when clerks enter MT orders rapidly. Without joining LG_XXX_ITMUNITA.CONVFACT1 (LINENR = 2) for METRE -> KG linear pipe/profile weights, 1,200 meters of heavy structural pipe is counted as 1,200 kg instead of 28,800 kg.
  • MT_KG Helper Columns Leaking Raw Piece Counts (BIRIM_KODU = 'AD.'): Custom SQL views frequently expose a pre-computed MT_KG column that multiplies meters by linear weight when BIRIM_KODU = 'MT', but falls back to ELSE MIKTAR when BIRIM_KODU = 'AD.'! Any LLM running SUM(MT_KG) unknowingly sums 10,000 bolts or cut parts (AD.) as 10,000 kg (10 tons), or undercounts heavy cut plates by an order of magnitude.
  • Gross TUTAR vs. NET_TUTAR & Excluding Service/Welding Groups (D, KYN): View columns named TUTAR typically hold gross pre-discount line amounts (AMOUNT * PRICE) rather than NET_TUTAR (VATMATRAH after distributed invoice discounts). Furthermore, merchandise steel margin-per-ton queries must enforce SATIR_TURU = 'STOK' and exclude non-steel service and welding stock groups (STOK_GRUP_KODU IN ('D', 'KYN')).
  • Sheet-Metal (Sac) Group Fragmentation: When an executive asks "How many tons of sheet metal (sac) did we ship this month?", an ungrounded LLM writes WHERE STOK_GRUP_KODU = 'SAC' and returns 0 tons—because the plant splits flat-rolled steel across six distinct codes: SS (Hot-Rolled / Sıcak Sac), DS (Cold-Rolled / DKP), HS (Pickled & Oiled / HRP), GS (Galvanized), KS (Prepainted / Coated), and BS (Checkered / Floor Plate).
Forensic Catalog of Logo Tiger SQL View Traps & Governed Ontology Rules
Schema / View PatternNaive Text-to-SQL QuerySilent Production DistortionGoverned Ontology Compilation Rule
LINETYPE 6 & 7 (Karmakoli)SUM(TOTAL) across STLINEDouble-counts parent bundle + child items (~2x revenue) or drops DISTDISCExclude LINETYPE=6; prorate KK.DISTDISC onto LINETYPE=7 components
TRCODE = 14 (Price Diff)SUM(AMOUNT) for shipped tonsCounts reference quantities on pure financial price adjustments as physical tonnageForce AMOUNT=0 when TRCODE=14; negate net total when DECPRDIFF=1
UINFO1 = 1 & MT_KGSUM(MT_KG) for total weightTreats AD. (pieces) as kilograms and breaks METRE -> KG pipe weightsJoin LG_XXX_ITMUNITA (LINENR=2); isolate piece-count items from KG metrics
STOK_GRUP_KODU ("Sac")WHERE STOK_GRUP_KODU = 'SAC'Returns 0 rows; misses 100% of flat-rolled steel shipmentsMap canonical concept SheetMetal -> IN ('SS','DS','HS','GS','KS','BS')
120.GR.* & CH_OZEL_KODU5 = "LÇ"Aggregates all 120.* AR accountsInter-branch transfers inflate external company revenue by 18–35%Classify 120.GR.* as internal transfers; exclude LÇ from board sales KPIs
FATURA_OZEL_KODU = "601"GROUP BY FATURA_OZEL_KODU for rep commissionDrops all export sales from reps and creates a phantom top rep named "601"Decode "601" as TDHP export ledger code; resolve rep via LG_SLSMAN

4. Chart-of-Accounts Contamination (120.GR, 120.AH, MPEŞİN), OZEL_KOD Entropy & Legacy Firebird Links

In Turkish industrial ERPs, critical business semantics live inside Uniform Chart of Accounts (Tekdüzen Hesap Planı) prefixes and overloaded OZEL_KOD (SPECODE) columns rather than normalized lookup tables:

  • 120.GR.XXXXX Inter-Branch Transfers, 120.AH/120.AV Legal Receivables, MPEŞİN & LÇ: Multi-branch plants invoice stock transfers between sibling warehouses under 120.GR.* receivable accounts—inflating external revenue by 18–35% unless excluded. 120.AH.* and 120.AV.* denote legal/doubtful receivables transferred to litigation and must be segregated from active credit-limit aging; MPEŞİN aggregates walk-in counter cash buyers into a single pseudo-customer; and CH_OZEL_KODU5 = 'LÇ' flags special reconciliation accounts excluded from management sales reports.
  • Semantic Overloading of FATURA_OZEL_KODU ("601" Export Trap): On domestic invoices, clerks populate FATURA_OZEL_KODU with the salesperson identifier. On export invoices, accounting overwrites that exact column with "601" (the Turkish Uniform Chart of Accounts code for Export Sales), stripping export turnover from sales reps and fabricating a top salesperson named "601".
  • SATIR_OZEL_KODU Machine-Code Entropy & Pre-2025 Regime Drift in SATIR_OZEL_KODU2: Shop-floor operators enter slitting/shearing line codes as free text ('KS', 'ksKS', 'makas'), requiring case- and synonym-normalized ontology mappings. Meanwhile, SATIR_OZEL_KODU2 uses NULL not as missing data, but to represent standard merchandise sales (versus 'FASON' toll processing)—and because plants introduced this convention at a 2025 cutover, unguarded year-over-year filters misclassify all pre-2025 toll work as stock sales!
  • Ay+90 Month-End Payment Math & Legacy Firebird PDKS Linked Servers: Commercial terms labeled "Ay+90" in LG_XXX_PAYPLANS mean End-of-Invoice-Month + 90 days (DATEADD(day, 90, EOMONTH(INVOICE.DATE_))), not DATE_ + 90 days—a cash-flow variance of up to 30 days. Finally, plant time-and-attendance (PDKS) records frequently sit in legacy on-prem Firebird databases mounted into MSSQL via Linked Servers; letting an AI agent write direct four-part joins drags millions of raw badge punches over ODBC and exhausts tempdb unless wrapped in bounded OPENQUERY ontology resolvers.
Ontology Modeling Rule: Encode Cutover Dates (valid_from) on Business Codes

Whenever an ERP custom field like SATIR_OZEL_KODU2 changes operational meaning starting on a specific fiscal cutover date, bind a valid_from predicate inside the ontology term definition so historical cross-year comparisons never suffer silent regime-cliff bias.

Frequently Asked Technical Questions

If our ERP integrator already created clean SQL views (VW_SALES), why did 63% of initial Text-to-SQL answers still fail?

Because clean column names do not document business exceptions or hidden view shortcuts. A view column named MT_KG does not warn the LLM that piece-count (AD.) lines fall back to raw quantities, nor does FATURA_OZEL_KODU warn that "601" means export accounting rather than a salesperson, nor that "Sac" maps to six distinct group codes (SS, DS, HS, GS, KS, BS).

Why must AMOUNT (MIKTAR) be forced to zero on Logo Tiger TRCODE = 14 invoices?

TRCODE = 14 represents a Price-Difference Invoice (Fiyat Farkı Faturası). Logo stores the reference item quantity in STLINE.AMOUNT so unit price adjustments multiply properly on the printed invoice, even though zero physical stock moved. Summing AMOUNT without zeroing TRCODE = 14 double-counts previously shipped tonnage.

What breaks when joining Logo Tiger records across years using LOGICALREF (KAYIT_ADRESI)?

Logo Tiger shards transactional tables by firm (XXX) and fiscal period (YY), such as LG_301_01_STLINE and LG_301_02_STLINE. Every new fiscal period resets LOGICALREF starting at 1. Joining or deduplicating without the composite key (FIRMNR, PERIODNR, LOGICALREF) merges unrelated invoices from different years.

How should an enterprise ontology query legacy Firebird PDKS attendance databases linked to MSSQL?

Never expose Linked Server four-part table names ([PDKS_FB]...PUNCHES) to open-ended SQL generation, as SQL Server cannot push complex predicates across legacy Firebird ODBC drivers and will pull full tables into tempdb. Encapsulate attendance lookups behind parameterized OPENQUERY templates with mandatory narrow date windows or pre-aggregated shift views.

Glossary Concepts Referenced in This Guide

Open License (CC BY 4.0) · Cite This Page

Free to reference in engineering docs, ADRs, articles, and course syllabi with attribution.

[Logo Tiger STLINE & Sales View SQL Forensics: Karmakoli, TRCODE 14, 120.GR & UINFO1 Traps — Ontoloji.org](https://ontoloji.org/en/guides/logo-tiger-stline-karmakoli-trcode-14-and-uinfo1-sql-traps)

More Guides in This Series

Core Architecture
How AI Uses an Ontology
9 min read
Agent Engineering
Agent Harness vs. Ontology
8 min read
Data Engineering
ERP, CRM & MES Patterns
10 min read
Strategy & Governance
30-Day Ontology Strategy
7 min read
ERP Integration
ERP Ontology Integration Guide
11 min read
ERP Data Engineering
Logo Tiger, Nebim V3 & Turkish Unicode Traps
14 min read
Agent Governance
Adversarial Verification, Permissions & Compaction
13 min read
Verification Engineering
Absence-Aware Gates & Ratio Reconstruction
13 min read
Provenance & Governance
Draft vs. Normative Provenance Hygiene
12 min read
SAP & Protocol Architecture
SAP BTP, Cloud Connector & ORD Ontology
11 min read
ERP Write-Safety
Logo REST, Nebim Integrator & UBL-TR Safety
12 min read
Platform Architecture Comparison
Cortex, Genie, dbt & Cube vs. Ontology
12 min read
Systems Engineering & Forensics
ERP Integrator Anti-Patterns & Forensics
13 min read
Platform Architecture Comparison
Fabric IQ, D365 MCP & SAP Joule vs. Ontology
12 min read
Retrieval & RAG Architecture
PageIndex Vectorless Tree RAG vs. Vector DBs
11 min read
Platform Architecture Comparison
Atlan, Stardog & Neo4j vs. Ontology
12 min read
Statutory & Financial Governance
GİB UBL-TR, VUK/TMS 29 & KVKK Ontology
13 min read
Agent Memory & Ontology Architecture
Cognee & Zep Graphiti vs. Ontology
11 min read
Protocol & Multi-Agent Architecture
MCP vs. OpenAPI & Specialist Agents
12 min read
Protocols & Standards
MCP 2026-07-28: Tasks, Events & Apps
13 min read
Agent Architecture & Governance
Agent Harness Engineering Rubric
12 min read
Agent Architecture & Governance
Multi-Agent Task Boards & Mailboxes
12 min read
Verification & Security
Generate-Evaluate-Repair & Observers
12 min read
Verification & Security
NSA MCP Security & CIMD vs. DCR
13 min read
Agent Architecture & Governance
OpenTelemetry for AI Agents & MCP
11 min read
Agent Architecture & Governance
MCP Gateway vs. Enterprise AI Ontology
12 min read
MCP & Agent Security
MCP Apps Nonces, Elicitation & Refusal Traps
13 min read
Manufacturing, MES & OEE Ontology
TRUMPF OPC UA & Siemens Energy SQL OEE Fix
13 min read
MCP & Agent Architecture
Claude Mobile, Desktop & OpenWebUI MCP Bugs
13 min read
ERP & SQL Ontology
AI on ABAP, TROIA, Delphi & Stored Procedures
13 min read
MCP & Agent Security
Enterprise MCP Gateway & RFC 8693 Security
14 min read
Core Ontology Specification
Operational Ontology: Action Types, Links & Interfaces
15 min read