Using enums
Enums are a very useful programming construct. JPortal has some powerful mechanisms for working with enums.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 | DATABASE ExampleDatabase
PACKAGE com.example.db
SERVER ExampleServer
SCHEMA ToDoList_App
TABLE ToDoList
ID SEQUENCE
ListName CHAR(255)
ListType SHORT (Private=1, Public=2)
Description CHAR(255)
LastUpdated TIMESTAMP
PROC EnumExampleReturnAllPublicLists
OUTPUT
ID =
ListName =
ListType =
SQLCODE
SELECT
ID,
ListName,
ListType
FROM
ToDoList
WHERE
ListType = %ListType.Public%
ENDCODE
|
In the above table definition, line 9 defines ListType
as an enum with 2 values:
Key |
Value |
1 |
Private |
2 |
Public |
Using enums in your code
In the generated code this will allow you to use enums instead of magic numbers in your code. For example:
Using enums in SQL
To use the above enums in your SQL code, you can use the syntax
%<ColumnName>.<EnumValue>
.
So for example if you wanted to select all records where ListType is Public (i.e. 2), you could write
WHERE
ListType = %ListType.Public%
which would generate