Using an array dictionary in Console UI
Informix® 4GL used a screen array to display columns of data within the console window. EGL provides the equivalent capability that you can use to specify an ArrayDictionary part with your openUI statement.
For example, suppose you were designing an application for a point-of-sale
terminal at a department store. The columns on the display might show
quantity, description, price, and extension for each item scanned:
QTY DESC PRICE EXT
1 DOG BOWL - STAINLESS 7.95 7.95
2 FRENCHIES MUSTARD 12OZ 2.95 5.90Each row
on the display is a series of name-value pairs, such as QTY=1, DESC="DOG
BOWL - STAINLESS". In EGL, a Dictionary is a part that holds such
name-value pairs, and an array of such dictionaries is an ArrayDictionary.From a code perspective, the table is defined as a collection of Console Field arrays, one per column. For example, the description column is an array of n string-type fields, the price is an array of n money-type fields, and so on.
The following example illustrates a simple implementation for this
terminal. The sample program multiplies out the extension for each
product and displays a running total when the user presses Ctrl+X.
package com.companyb.retail;
// Each line from the array binds to one of these
Record ItemRecord type BasicRecord
itemQty INT;
itemDesc STRING;
itemPrice DECIMAL(9,2);
itemExt DECIMAL(9,2);
end
// Form to appear on the point of sale terminal
Record RegisterConsole type ConsoleForm {
formSize = [10,78],
showBrackets = yes }
// headers for the columns
*ConsoleField {position = [1,2], value = "QTY" };
*ConsoleField {position = [1,8], value = "DESCRIPTION" };
*ConsoleField {position = [1,36], value = "PRICE" };
*ConsoleField {position = [1,48], value = "EXT" };
QTY ConsoleField[4] {
name="QTY",
datatype = "INT",
fieldlen = 3,
align = right,
position = [2, 2]
};
DESC ConsoleField[4] {
name="DESC",
datatype = "STRING",
fieldlen = 25,
align = left,
position = [2, 8]
};
PRICE ConsoleField[4] {
name="PRICE",
datatype = "NUMBER",
fieldlen = 9,
align = right,
position = [2, 36]
};
EXT ConsoleField[4] {
name="EXT",
datatype = "NUMBER",
fieldlen = 9,
align = right,
position = [2, 48]
};
registerArray ArrayDictionary {
col1 = QTY,
col2 = DESC,
col3 = PRICE,
col4 = EXT
};
end
program pos_terminal
function main ()
i INT; // index for record array
total DECIMAL(9,2) = 0; // running total
myRegister RegisterConsole {
name = "myRegister"};
myItems ItemRecord[20];
displayFormByName( "myRegister"); // display initial screen
openUI myRegister.registerArray
bind myItems // user entry saved here
onEvent(AFTER_FIELD:"PRICE")
i = currentArrayDataLine();
// figure extension amount
myItems[i].itemExt =
myItems[i].itemPrice * myItems[i].itemQty;
onEvent(AFTER_FIELD:"EXT")
i = currentArrayDataLine();
// keep running total
total = total + myItems[i].itemExt;
onEvent(ON_KEY:"CTRL_X")
// display total
displayAtLine( "Total: " + total, 9);
end
end
endThe layout in the console form determines the number of lines that
are displayed on the initial console screen. Because the myItems array
contains more elements (20) than the display does (4), the array portion
of the screen scrolls up or down to show requested records.