---
title: Generate VB Enum member list
summary: Read code-table rows and emit a VB enum-member list.
status: draft
owner: SAIF DocGen
last_reviewed: 2026-07-30
library: SAIF.Framework.CodeGen
reference_type: package
operation_id: OP-CODEGEN-003
trigger: Caller invokes CreateEnumStatement
---

# Generate VB Enum member list

This operation reads `code`/`code_descr` reference rows from a caller-supplied table and turns each row into a VB enum-member line with an inline comment. It can optionally prepend a leading `Null` member, derives a legal VB identifier for every row, and disambiguates any identifier that repeats before returning the completed member list.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-CODEGEN-003 |
| **Trigger** | Caller invokes `CreateEnumStatement(table, enumName, includeNull, ...)` |
| **Inputs** | `table`, `enumName` (accepted but unused), `includeNull`, optional `useDescriptionAsCode`, optional `tabIndex` |
| **Outputs** | Generated VB source text containing enum-member lines and inline comments |
| **Primary components** | `CodeTableMap.CreateEnumStatement`, `CodeTableMap.GetResult`, `CodeTableMap.GetEnumValue` |
| **Entry point** | `SAIF.Framework.CodeGen\CodeTableMap.vb` |

## Steps

1. `CreateEnumStatement` calls `GetResult(table)`, which executes [SQL-001](../sql/SQL-001-select-code-table.md) against [CODE_TABLE (caller-supplied)](../database-tables.md#code_table-caller-supplied) — the same unfiltered `code`/`code_descr` lookup used by `CreateCaseStatement`.
   - `ResultSetQuery` obtains a new portal request from `m_dpi.NewPortalRequest()` and marks it as a result-set request.
   - `Execute(sql)` assigns the formatted SQL text to `DataRequest.SQLStatement`.
   - `Execute()` calls `m_dpi.ProcessPortalRequest(...)` and returns the resulting `clsResultSet`.

   > **Origin**: Steps 1.1-1.3 are implemented in `SAIF.Framework.Core`'s data-portal pipeline and execute on behalf of this operation; see [SAIF.Framework.Core interaction model](../../saif-framework-core/architecture.md#interaction-model).
2. The method initializes an empty output buffer.
3. When `includeNull = True`, the method writes a single tab-indented `Null` member as the first line, before any database-driven entries are emitted.
4. The method initializes a `Dictionary(Of String, Boolean)` that tracks which identifiers have already been emitted.
5. For each row returned by the query, `GetEnumValue` derives a candidate member identifier.
   - When `useDescriptionAsCode = True` (the default), it strips every non-alphabetic character from `row("code_descr")` and uses what remains as the identifier ([BR-003](../business-rules.md#br-003-enum-member-identifier-derivation-strips-non-alphabetic-characters-from-the-description)).
   - If the resulting candidate is purely numeric, it is prefixed with the literal `Code` so the emitted member name stays legal VB syntax ([BR-002](../business-rules.md#br-002-generated-enum-member-identifiers-must-be-legal-vb-identifiers)).
6. Before writing the line, the method checks whether the candidate identifier is already present in the dictionary.
   - If it is, the method appends the row's raw `code` value so the emitted member name becomes unique ([BR-001](../business-rules.md#br-001-enum-member-identifiers-must-be-unique-within-a-generated-block)).
   - It then records the final identifier in the dictionary, so subsequent rows are compared against every name emitted so far ([BR-001](../business-rules.md#br-001-enum-member-identifiers-must-be-unique-within-a-generated-block)).
7. The method appends one tab-indented enum-member line in the form `{enumValue} ' {code}: {code_descr}`.
8. Once every row has been processed, the method returns the accumulated buffer as the finished member list.
   - If [SQL-001](../sql/SQL-001-select-code-table.md) returns zero rows from [CODE_TABLE (caller-supplied)](../database-tables.md#code_table-caller-supplied), the result contains only the optional leading `Null` line, if requested.
   - The `enumName` parameter is accepted by the method signature but is never read inside this implementation, so it has no effect on the generated output.
   - No local exception handling surrounds query execution or string assembly, so any failure in either stage propagates directly to the caller.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Caller invokes CreateEnumStatement]) --> Query[Read code-table rows]
	Query --> NullOpt{includeNull?}
	NullOpt -->|Yes| AddNull[Emit Null member]
	NullOpt -->|No| Loop[For each row derive identifier]
	AddNull --> Loop
	Loop --> Dup{Identifier already used?}
	Dup -->|Yes| Disambiguate[Append raw code value]
	Dup -->|No| Emit[Emit enum-member line]
	Disambiguate --> Emit
	Emit --> More{More rows?}
	More -->|Yes| Loop
	More -->|No| EndOk([Return generated enum list])
```

## Failure and edge-case behavior

- Duplicate computed identifiers are disambiguated by appending the row's raw `code` value before the line is emitted, guaranteeing every member name in the generated list is unique ([BR-001](../business-rules.md#br-001-enum-member-identifiers-must-be-unique-within-a-generated-block)).
- Description-derived identifiers have non-alphabetic characters stripped and are then prefixed with `Code` when the stripped result is purely numeric ([BR-003](../business-rules.md#br-003-enum-member-identifier-derivation-strips-non-alphabetic-characters-from-the-description), [BR-002](../business-rules.md#br-002-generated-enum-member-identifiers-must-be-legal-vb-identifiers)).
- `includeNull` only controls whether the optional leading `Null` line is written; the `enumName` argument has no effect on the output because the method never reads it.
- Query failures bubble up unhandled, because neither `GetResult` nor `CreateEnumStatement` wraps or catches exceptions raised while executing [SQL-001](../sql/SQL-001-select-code-table.md).

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

## Sources
- SAIF.Framework.CodeGen\CodeTableMap.vb
- SAIF.Framework.Core\V1\DataAccessLayer\SqlHelper.vb
- SAIF.Framework.Core\V1\Interfaces\iDataPortalInfo.vb
