$npx -y skills add totvs/engpro-advpl-tlpp-skills --skill advpl-to-tlpp-migrationGuide the migration of legacy AdvPL (Advanced Programming Language) code to modern TLPP (TOTVS Language Plus Plus). Covers feature comparison, syntax transformation, include/namespace adoption, typing, Try-Catch, REST migration, long identifiers, JSON inline, named parameters, ac
| 1 | # AdvPL-to-TLPP Migration |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Migrate legacy AdvPL source files (`.prw`, `.prx`) to modern TLPP (`.tlpp`) incrementally and safely. TLPP is an evolution of AdvPL that introduces modern language features while maintaining full backward compatibility with existing AdvPL constructs. This skill provides a structured migration path that can be applied gradually — no forced rewrite is required. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - Modernizing legacy AdvPL code to TLPP |
| 12 | - Converting `.prw` files to `.tlpp` |
| 13 | - Adopting TLPP-exclusive features (typing, try-catch, namespace, etc.) |
| 14 | - Replacing prohibited constructs (e.g., `StaticCall`) in TLPP sources |
| 15 | - Preparing code for TLPP REST migration from WsRESTful |
| 16 | - Onboarding developers transitioning from AdvPL to TLPP |
| 17 | |
| 18 | --- |
| 19 | |
| 20 | ## Feature Comparison: AdvPL vs. TLPP |
| 21 | |
| 22 | For the complete feature-by-feature comparison table (19 features covering scoping, control structures, typing, namespaces, Try-Catch, JSON inline, class modifiers, REST, and StaticCall status), see [advpl-tlpp-feature-comparison.md](references/advpl-tlpp-feature-comparison.md). |
| 23 | |
| 24 | --- |
| 25 | |
| 26 | ## Migration Process |
| 27 | |
| 28 | > **MANDATORY RULE — File Extension:** Any source file that includes `#include "tlpp-core.th"` or uses TLPP-exclusive features **must** use the `.tlpp` extension. If a `.prw` or `.prx` file is being migrated or modified to adopt TLPP constructs, rename it to `.tlpp` as part of the same change. The AdvPL compiler silently ignores TLPP directives in `.prw`/`.prx` files, which leads to hard-to-diagnose failures. **Always change the extension first.** |
| 29 | |
| 30 | The migration involves 15 steps, each addressing a specific AdvPL → TLPP transformation: |
| 31 | |
| 32 | 1. **File Extension and Includes** — `.prw` → `.tlpp`, add `#include "tlpp-core.th"` |
| 33 | 2. **Add Namespace** — Organize code with `Namespace company.module.feature` |
| 34 | 3. **Add Type Annotations** — Variables, parameters, return values (`as Type`) |
| 35 | 4. **Replace ErrorBlock with Try-Catch** — Modern exception handling |
| 36 | 5. **Replace StaticCall** — Use `FWLoadMenuDef`, `FWLoadModel`, namespace calls |
| 37 | 6. **Use Long Identifier Names** — TLPP removes the 10-char limit |
| 38 | 7. **Use Named Parameters** — Improve readability at call sites |
| 39 | 8. **Use JSON Inline** — Replace `JsonObject():New()` chains |
| 40 | 9. **Add Class Access Modifiers** — `Private`, `Protected`, `Public` |
| 41 | 10. **Migrate WsRESTful to TLPP REST** — Annotation-based `@Get`, `@Post`, etc. |
| 42 | 11. **Fix Incorrect Inheritance** — `LongNameClass` (not `LongClassName`) |
| 43 | 12. **Remove ISAM Driver Usage** — Migrate to `FWTemporaryTable` |
| 44 | 13. **Migrate Console APIs to FWLogMsg** — Replace `ConOut`, `OutErr`, `?` |
| 45 | 14. **Remove IIF Usage** — Replace with `If/Else/EndIf` |
| 46 | 15. **Migrate FormCommit Override to FWModelEvent** — Use `FWFormCommit(oModel)` |
| 47 | |
| 48 | For complete before/after diff examples for all 15 steps, see [tlpp-migration-patterns.md](references/tlpp-migration-patterns.md). |
| 49 | |
| 50 | --- |
| 51 | |
| 52 | ## Migration Checklist |
| 53 | |
| 54 | ### Pre-Migration |
| 55 | |
| 56 | - [ ] Source file is under version control with a clean commit |
| 57 | - [ ] Existing tests pass (or tests exist for the code) |
| 58 | - [ ] Dependencies on the file are identified (callers, includes) |
| 59 | - [ ] Team is aware of the migration (naming changes affect callers) |
| 60 | |
| 61 | ### File Transformation |
| 62 | |
| 63 | - [ ] File extension changed from `.prw` to `.tlpp` |
| 64 | - [ ] `#include "tlpp-core.th"` added as the first include |
| 65 | - [ ] `Namespace` declaration added |
| 66 | - [ ] All `StaticCall()` replaced with direct calls or `FWLoad*` functions |
| 67 | - [ ] User Function return types added (`as Type`) |
| 68 | - [ ] Parameter types added (`as Type`) |
| 69 | - [ ] Variable types added (`as Type`) |
| 70 | |
| 71 | ### Modernization (Incremental) |
| 72 | |
| 73 | - [ ] `ErrorBlock` patterns replaced with `Try-Catch` where appropriate |
| 74 | - [ ] Short identifier names expanded to descriptive names |
| 75 | - [ ] `Private` variable scope replaced with `Local` where possible |
| 76 | - [ ] Class access modifiers added (`Private`, `Protected`, `Public`) |
| 77 | - [ ] Named parameters used for functions with 3+ parameters |
| 78 | - [ ] JSON inline syntax used for JSON object construction |
| 79 | - [ ] WsRESTful services migrated to TLPP REST annotations |
| 80 | - [ ] `LongNameClass` used for inheritance (not `LongClassName`) |
| 81 | - [ ] ISAM drivers (`MSCREATE`, `DBCREATE`, `CRIATRAB`) replaced with `FWTemporaryTable` |
| 82 | - [ ] `ConOut()` / `OutErr()` / `?` replaced with `FWLogMsg()` |
| 83 | - [ ] `IIF()` replaced with `If/Else/EndIf` blocks |
| 84 | - [ ] `FormCommit` overrides migrated to `FWMode |