$npx -y skills add totvs/engpro-advpl-tlpp-skills --skill data-dictionary-lookupQuery the TOTVS Protheus ERP data dictionary (SX2 tables, SX3 fields, SIX indexes, SX6 parameters, SX5 generic tables, SX7 triggers, SX1 questions, SX9 relationships, SXB standard lookups, SXG/SXA groups). Use when the user asks 'what fields does SA1 have', 'what is the index of
| 1 | # Protheus Data Dictionary Lookup |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Structured querying of the TOTVS Protheus ERP data dictionary. Allows searching tables, fields, indexes, parameters, generic tables, triggers, parameterization questions, relationships, and standard lookups (SQL queries via `execute-sql` and TDN documentation via search tools). |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Discover which fields a table has and their types/sizes |
| 10 | - Check available indexes for a table |
| 11 | - Query the value and purpose of a parameter (MV_*) |
| 12 | - Search generic table contents (SX5) |
| 13 | - Check triggers associated with a field |
| 14 | - Query parameterization questions (SX1) |
| 15 | - Check relationships between tables (SX9) |
| 16 | - Query standard lookups (SXB) |
| 17 | - Find the sharing mode of a table (Exclusive/Shared) |
| 18 | - **Impact validation in the dictionary**: during refactorings, migrations, or code improvements, consult the dictionary when necessary to confirm whether the changes affect fields, triggers, indexes, parameters, or relationships of the tables involved in the process |
| 19 | |
| 20 | --- |
| 21 | |
| 22 | ## Bundled Reference Files |
| 23 | |
| 24 | This skill uses progressive disclosure. The SKILL.md covers dictionary structure, query flow, and response format. SQL queries and detailed column reference are in the `references/` directory — read on demand as needed: |
| 25 | |
| 26 | | Reference File | When to Read | Content | |
| 27 | | --- | --- | --- | |
| 28 | | [references/sql-queries.md](references/sql-queries.md) | Executing **dictionary queries** — listing fields, indexes, parameters, triggers, questions, relationships, standard lookups, or combining SX* tables | Complete SQL queries for all 9 dictionary tables (SX2, SX3, SIX, SX6, SX5, SX7, SX1, SX9, SXB), combined queries (full view, fields with triggers, mandatory fields), and mandatory `execute-sql` rules (TRIM, d_e_l_e_t_, lowercase) | |
| 29 | | [references/column-reference.md](references/column-reference.md) | Interpreting **results** or needing to understand the **meaning of specific columns** from SX* tables | Detailed tables with all columns from SX2, SX3, SIX, SX6, SX5, SX7, SX1, SX9, and SXB, including type, possible values, and functional description | |
| 30 | |
| 31 | --- |
| 32 | |
| 33 | ## Data Dictionary Structure |
| 34 | |
| 35 | Protheus organizes its metadata in SX* tables: |
| 36 | |
| 37 | | Table | Description | Primary Key | |
| 38 | |-------|-------------|-------------| |
| 39 | | **SX1** | Parameterization questions (reports/queries) | `X1_GRUPO` + `X1_ORDEM` | |
| 40 | | **SX2** | System tables registry | `X2_CHAVE` (table alias) | |
| 41 | | **SX3** | Table fields | `X3_ARQUIVO` + `X3_CAMPO` | |
| 42 | | **SX5** | Generic tables (lookup values) | `X5_TABELA` + `X5_CHAVE` | |
| 43 | | **SX6** | System parameters (MV_*) | `X6_VAR` | |
| 44 | | **SX7** | Field triggers | `X7_CAMPO` + `X7_SEQUENC` | |
| 45 | | **SX9** | Table relationships | `X9_DOM` + `X9_CDOM` | |
| 46 | | **SXA** | Folders and groupers | - | |
| 47 | | **SXB** | Standard lookups (F3) | `XB_ALIAS` + `XB_TIPO` | |
| 48 | | **SXG** | Field groups | - | |
| 49 | | **SIX** | Table indexes | `INDICE` + `ORDEM` | |
| 50 | |
| 51 | --- |
| 52 | |
| 53 | ## Mandatory Rules for execute-sql Queries |
| 54 | |
| 55 | 1. **Always** include `d_e_l_e_t_ = ' '` (soft-delete filter) |
| 56 | 2. Columns are **lowercase** — never use `X3_CAMPO`, always `x3_campo` |
| 57 | 3. Use `TRIM()` in `character` field comparisons (trailing spaces) |
| 58 | 4. Use **base** table without suffix: `sx3`, `sx2`, `six` — **never** `sx3t10`, `sx2t10` |
| 59 | |
| 60 | --- |
| 61 | |
| 62 | ## Query Flow by Scenario |
| 63 | |
| 64 | ### Full table overview |
| 65 | |
| 66 | Execute **3 queries in parallel** (see queries in [references/sql-queries.md](references/sql-queries.md)): |
| 67 | |
| 68 | 1. **Metadata** → SX2 filtering by `x2_chave` |
| 69 | 2. **Fields** → SX3 filtering by `x3_arquivo` |
| 70 | 3. **Indexes** → SIX filtering by `indice` |
| 71 | |
| 72 | ### Parameter lookup |
| 73 | |
| 74 | 1. Search by exact name (`TRIM(x6_var) LIKE 'MV_NAME%'`) or by description (`UPPER(x6_descric) LIKE '%TERM%'`) |
| 75 | 2. If additional context is needed, search TDN documentation via `product-docs-search` |
| 76 | |
| 77 | ### Field triggers |
| 78 | |
| 79 | 1. Query SX7 filtering by `x7_campo` |
| 80 | 2. Combine with SX3 to get field titles for involved fields |
| 81 | |
| 82 | --- |
| 83 | |
| 84 | ## Response Format |
| 85 | |
| 86 | When presenting results to the user, always: |
| 87 | |
| 88 | 1. **Title**: Table name and description (from SX2) |
| 89 | 2. **Sharing mode**: E (Exclusive) or C (Shared) — indicate the meaning |
| 90 | 3. **Formatted table**: Fields in markdown table with relevant columns |
| 91 | 4. **Indexes**: List with composition and description |