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.
- 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, naiveSUM(TOTAL)double-countsKarmakolimixed bundles (LINETYPE6 & 7), while failing to zeroAMOUNTon Price-Difference Invoices (TRCODE = 14) inflates physical tonnage. - 03Reporting views that hardcode
UINFO1 = 1or exposeMT_KGhelper columns corrupt pipe/profileMETRE -> KGweights and leak raw piece counts (BIRIM_KODU = 'AD.') into steel tonnage. - 04
120.GR.XXXXXinter-branch transfers inflate external turnover by 18–35%,FATURA_OZEL_KODUmutates from salesperson ID to"601"on exports, andLOGICALREFresets 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.
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:
KarmakoliMixed Bundles (LINETYPE = 6Parent &LINETYPE = 7Component Lines): On mixed-bundle sales,LINETYPE = 6stores the commercial bundle header and header-level distributed discount (DISTDISC), whileLINETYPE = 7rows record the physical component items deducted from stock. Summing all rows double-counts revenue (~2x); filtering onlyLINETYPE = 7loses bundle discounts. Component rows must self-join back to the parent (KK) viaPREVLINEREF = KK.LOGICALREFandPREVLINENO = KK.INVOICELNNO(withKKSsumming sibling components ifKK.TOTALis zero) to prorateDISTDISC((STLINE.TOTAL / NULLIF(KK.TOTAL, 0)) * KK.DISTDISC) and reconstruct exactVATMATRAH.- Price-Difference Invoices (
Fiyat Farkı Faturası,TRCODE = 14+DECPRDIFF = 1) & Promotions (LINETYPE = 1): Logo stores a non-zero referenceAMOUNT(MIKTAR) onTRCODE = 14invoices so unit-price difference multiplication works on the invoice form—even though zero physical goods moved. Unless SQL forcesAMOUNT = 0onTRCODE = 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
CLIENTREFRouting,LG_SLSMAN&SPECODESCollation: Joining customer masterLG_XXX_CLCARDrequiresINVOICE.CLIENTREFwhenSTLINE.LINETYPE IN (0, 4, 11)(billed material, service, subcontracting/fixed-asset lines) versusSTFICHE.CLIENTREFotherwise. Cross-firm salespeople inLG_SLSMANcarryFIRMNR = -1(filteringFIRMNR = XXXdrops active reps), andLG_XXX_SPECODESjoins requireCOLLATE database_defaultto avoidTurkish_CI_ASvs.SQL_Latin1_General_CP1_CI_AScrashes. - Cross-Year
LOGICALREF(KAYIT_ADRESI) Resets: Fiscal-period tables (LG_301_01_STLINE,LG_301_02_STLINE,INVOICE,STFICHE) resetLOGICALREFback to1in every new fiscal period (YY) and firm (XXX) shard. Keying warehouse tables or entity caches byLOGICALREF/KAYIT_ADRESIalone collides unrelated cross-year records unless keyed by(FIRMNR, PERIODNR, LOGICALREF).
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 = 1Instead ofLG_XXX_ITMUNITA: Many reporting views either hardcodeUINFO1 = 1/UINFO2 = 1or trust unpopulatedSTLINE.UINFO1/UINFO2line factors when clerks enterMTorders rapidly. Without joiningLG_XXX_ITMUNITA.CONVFACT1(LINENR = 2) forMETRE -> KGlinear pipe/profile weights,1,200 metersof heavy structural pipe is counted as1,200 kginstead of28,800 kg. MT_KGHelper Columns Leaking Raw Piece Counts (BIRIM_KODU = 'AD.'): Custom SQL views frequently expose a pre-computedMT_KGcolumn that multiplies meters by linear weight whenBIRIM_KODU = 'MT', but falls back toELSE MIKTARwhenBIRIM_KODU = 'AD.'! Any LLM runningSUM(MT_KG)unknowingly sums10,000bolts or cut parts (AD.) as10,000 kg(10 tons), or undercounts heavy cut plates by an order of magnitude.- Gross
TUTARvs.NET_TUTAR& Excluding Service/Welding Groups (D,KYN): View columns namedTUTARtypically hold gross pre-discount line amounts (AMOUNT * PRICE) rather thanNET_TUTAR(VATMATRAHafter distributed invoice discounts). Furthermore, merchandise steel margin-per-ton queries must enforceSATIR_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 writesWHERE STOK_GRUP_KODU = 'SAC'and returns0tons—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), andBS(Checkered / Floor Plate).
| Schema / View Pattern | Naive Text-to-SQL Query | Silent Production Distortion | Governed Ontology Compilation Rule |
|---|---|---|---|
| LINETYPE 6 & 7 (Karmakoli) | SUM(TOTAL) across STLINE | Double-counts parent bundle + child items (~2x revenue) or drops DISTDISC | Exclude LINETYPE=6; prorate KK.DISTDISC onto LINETYPE=7 components |
| TRCODE = 14 (Price Diff) | SUM(AMOUNT) for shipped tons | Counts reference quantities on pure financial price adjustments as physical tonnage | Force AMOUNT=0 when TRCODE=14; negate net total when DECPRDIFF=1 |
| UINFO1 = 1 & MT_KG | SUM(MT_KG) for total weight | Treats AD. (pieces) as kilograms and breaks METRE -> KG pipe weights | Join 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 shipments | Map canonical concept SheetMetal -> IN ('SS','DS','HS','GS','KS','BS') |
| 120.GR.* & CH_OZEL_KODU5 = "LÇ" | Aggregates all 120.* AR accounts | Inter-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 commission | Drops 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.XXXXXInter-Branch Transfers,120.AH/120.AVLegal Receivables,MPEŞİN&LÇ: Multi-branch plants invoice stock transfers between sibling warehouses under120.GR.*receivable accounts—inflating external revenue by 18–35% unless excluded.120.AH.*and120.AV.*denote legal/doubtful receivables transferred to litigation and must be segregated from active credit-limit aging;MPEŞİNaggregates walk-in counter cash buyers into a single pseudo-customer; andCH_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 populateFATURA_OZEL_KODUwith 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_KODUMachine-Code Entropy & Pre-2025 Regime Drift inSATIR_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_KODU2usesNULLnot 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+90Month-End Payment Math & LegacyFirebirdPDKS Linked Servers: Commercial terms labeled"Ay+90"inLG_XXX_PAYPLANSmean End-of-Invoice-Month + 90 days (DATEADD(day, 90, EOMONTH(INVOICE.DATE_))), notDATE_ + 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 exhauststempdbunless wrapped in boundedOPENQUERYontology resolvers.
valid_from) on Business CodesWhenever 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
ORDER_LINES and PAYMENTS) in one flat SQL query, multiplying totals silently.STAT = 4, SPEC_CODE = "B2") in operational tables to verified business states and calculation inclusion rules.FOREIGN KEY constraints—common across mature ERP and manufacturing databases.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)