Working with Tables
Tables are used to store data to be used in Jobs. For example, you could map customer ID numbers to end-user friendly customer names in a Table and configure a Job Definition to present customer names instead of customer IDs to Operators.
Many complex Jobs consist of Jobs that work with the same Parameter values. For example:
- The name of an external system.
- The processing day (or business day), which may not be the same as today.
- The name of an SAP instance or client to use for a particular task.
These values tend to be used by a large number of Job Definitions, and do not change often. They might change:
- On a daily basis (for the business day).
- Between the Dev, Test, and Prod environments (for external system names).
In some cases, there may be a predefined set of values from which the user can choose:
- A list of countries, provinces or cities.
- A list of departments or cost codes.
In these cases it is also useful to be able to validate the value a user has entered to ensure it is correct, and to prompt them with a list of valid values. This means that validation can occur when a Jobis run, rather than when it executes.
Creating Tables
There are two steps in creating Tables:
-
Navigate to Configure > Automate > Scripting tools > Table Definitions and create a Table Definition that defines what columns the table will have and what kind of data can be included in each column.
-
Navigate to Configure > Automate > Scripting tools > Tables, create a Table, and populate the Table with values.
Using Tables for Parameter Values
To use a Table for Parameter values:
- Navigate to Configure > Automate > Job Definitions.
- Choose Edit from the context menu of the Job Definition.
- Choose the Parameters tab and select the Parameter you want to use.
- In the Simple Constraint Type field choose Table.
- Choose the name of the Table from the Simple Constraint Data dropdown list.
- Click Save & Close.
Accessing Tables from REL
You can access tables using the REL table functions.
Deleting Table Definitions and Tables
You can delete Table Definitions and Tables only if no other objects have relationships to them. For example, if there are Job Definitions that use a Table, the Table cannot be deleted until all Job Definitions that use it have been modified. You can see Job Definitions that relate to a Table under Related Objects in the Detail View.
RedwoodScript Example
The following RedwoodScript code checks the System_Variables table for a system variable with key RW_DEMO
, if it does not exist it will create it and assign a value to it, finally, it will print all entries in the table.
{
Partition p = jcsSession.getPartitionByName("GLOBAL");
Table t = jcsSession.getTableByName(p, "System_Variables");
if (t.getTableValueBySearchKeySearchColumnName("RW_DEMO", "SystemValue") == null)
{
TableValue ctv = t.createTableValue();
ctv.setKey("RW_DEMO");
ctv.setColumnName("SystemValue");
ctv.setColumnValue("SomeValue");
jcsSession.persist();
}
t.getTableValues().forEach(item -> jcsOut.println(item.getKey() + " : " + item.getColumnName()+" > " + item.getColumnValue()));
}