Class ZCL_LLM_TOOL_PARSER
AI Generated documentation.
Overview
The class ZCL_LLM_TOOL_PARSER generates JSON schemas from ABAP data structures, enabling structured data validation and tooling integration. It focuses on mapping ABAP types (elementary types, structures, tables) to JSON schema constructs while incorporating metadata like field descriptions and enum values.
Public Methods:
zif_llm_tool_parser~parse:
Main entry point. Converts an ABAP data structure into a JSON schema string. Handles nested structures, tables, type validation, and metadata integration.
Dependencies
- Exceptions:
zcx_llm_validationfor error reporting. - Type Descriptors: Relies on
cl_abap_typedescr,cl_abap_structdescr,cl_abap_tabledescr, andcl_abap_elemdescrfor ABAP type introspection.
Details
Schema Generation Flow
flowchart TD
A[parse] --> B[Initialize schema]
B --> C{Data type?}
C -->|Structure| D[Process nested components]
C -->|Table| E[Generate array schema]
C -->|Elementary| F[Map to JSON type]
D --> G[Recursive processing]
E --> H[Process line type]
F --> I[Handle enums/descriptions]
G --> C
H --> C
I --> J[Validate constraints]
J --> K[Append to schema]
K --> L{More fields?}
L -->|Yes| C
L -->|No| M[Finalize schema]
Key Implementation Aspects
- Type Mapping:
- ABAP
INT/INT8→ JSONinteger - ABAP
DECFLOAT→ JSONnumber - ABAP
STRING→ JSONstring -
ABAP
CHAR1with boolean context → JSONboolean(validated via type pool checks). -
Metadata Integration:
- Field descriptions from
descriptionsare injected into the schema. -
Enum values are converted to JSON
enumarrays. -
Nested Structures:
- Nested ABAP structures become JSON
objecttypes withproperties. -
Paths (e.g.,
field-subfield) are tracked for metadata assignment. -
Table Handling:
- ABAP tables are mapped to JSON
arraytypes. -
Supports tables of structures (nested objects) and multi-level nesting.
-
Validation:
- Rejects unsupported types (e.g., type
D). - Ensures
CHAR1fields not flagged as booleans throw errors. -
Enforces required fields in generated schemas.
-
Extension Hooks:
- Empty
pre_*/post_*methods (e.g.,pre_object,post_array) allow subclassing for custom logic.
Example Interaction
When processing a table field:
process_tablegenerates anarrayskeleton.process_typeresolves the line type (e.g., a structure).process_structurerecursively adds properties for each component.- Metadata (descriptions, enums) is injected during field processing.
This ensures complex ABAP data models are accurately represented as JSON schemas for downstream tooling.