A DataTable part consists of a collection of data in tabular form that you can make available throughout an application. Unlike other data parts, you declare each DataTable part in its own EGL source file. A DataTable is a generatable part, which means that you must define it in a file that has no other generatable parts, and it must have the same name as the file.
Include a DataTable in a use statement to make it visible to a program, library, or handler. When you use the DataTable as a message table only, you can connect the DataTable to the program through the msgTablePrefix property of the program.
The DataTable part has a required property, contents, that specifies a two-dimensional array of values for the table. See DataTable properties and the example later in this topic.
For each column of data that you specify with the contents property, you must include a variable declaration. These variable declarations are structure fields, similar to those in a structured record (see Record part). Structure fields always have a fixed length (for example, no STRING variables of undefined length are allowed). You can substructure these declarations by assigning a numeric prefix; otherwise, EGL assumes all fields are at the same level. You can specify contents only for the highest level fields (those with the lowest level number) in the structure, not for the substructure fields. For more information, see the examples later in this topic.
strTest = myDataTable.column3[4];
In this example, the STRING variable strTest contains the value from the third column, fourth row of the data table.
DataTable myErrorMessages type MsgTable { shared = yes } msgNum INT; msgText char(30); { contents = [ [ 101, "File not found" ] , [ 102, "Read error" ] , [ 103, "Write error" ] ] } end
Function displayError(index INT in) strTest = formatNumber(myErrorMessages.msgNum[index]) + " " + myErrorMessages.msgText[index]; sysLib.writeStdout(strTest); end
102 Read error
DataTable myDataTable type basicTable { shared = yes } 10 myColumn1 CHAR(10); 15 Column1A CHAR(5); 15 Column1B CHAR(5); 10 myColumn2 CHAR(10); 10 myColumn3 CHAR(10); { contents = [ [ "ABCDEFGHIJ", "row1 col2", "row1 col3" ] , [ "KLMNOPQRST", "row2 col2", "row2 col3" ] , [ "1234567890", "row3 col2", "row3 col3" ] ] } end
writeStdOut(myDataTable.Column1B[1]); // displays FGHIJ
In most environments, you can modify the contents of a DataTable at runtime. Changes made at run time are visible to every program that has access to the DataTable, and the changes remain until the DataTable is unloaded. The ability to make changes and the visibility of those changes to other programs in the run unit is affected by the target system and the shared property. The unloading of the DataTable is affected by the target system and by the resident property. For more information, see DataTable properties.
DataTable myConstants type basicTable 10 myConstant1 INT; 10 myConstant2 CHAR(10); {contents = [ [ 0, ""]]} // single row with initial values endThen you could update the DataTable from a database or file at run time, as in the following example code:
get constantInfo; myConstants.myconstant1[1] = constantInfo.myconstant1; myConstants.myconstant2[1] = constantInfo.myconstant2;The advantage of using this technique over declaring the constants in your program is that you simply need to update the database when the data changes; there is no need to change the constants in each program. Depending on the environment, this use of the DataTable might give you better performance than using a library or database. For example, in CICS®, you might define the DataTable as resident and initialize it during the startup for a CICS region.