# Relational Standard Table with Calculated Column Example

The following coding example reads data items from an information map that uses relational data. The result displays a simple relational table with one calculated column.

/**

*

* A simple method creates a result of a relational table with a calculated column.

* @param list of data items in an information map.

* @param input data selection

* @return modified data selection containing the result

*

* @throws Exception

*/

private com.sas.iquery.metadata.business.DataSelection SimpleRelationTableDisplay(java.util.List dsDataItems, com.sas.iquery.metadata.business.DataSelection query) throws Exception

{

> for(int i = 0; i < dsDataItems.size(); i++)

> { com.sas.iquery.metadata.business.DataItem tdi = (com.sas.iquery.metadata.business.DataItem)dsDataItems.get(i);

> > // Assign Column to all dataitems and add to dataselection.

> > query.addResultItem(tdi, com.sas.iquery.metadata.business.Role.COLUMN);

> }

> // Define calculated column.

> com.sas.iquery.metadata.business.DataItem di = query.newDataItem();

> com.sas.iquery.metadata.expr.ResourceScope scope = com.sas.iquery.metadata.expr.ResourceScope.BUSINESS_AND_PHYSICAL_SCOPE;

> int type = com.sas.iquery.metadata.expr.ExpressionTypes.EXP_TYPE_NUMERIC;

> com.sas.iquery.metadata.expr.ExpressionInterface expr1 = null;

> expr1 = com.sas.iquery.metadata.expr.StringExpressionUtil.getInstance().newExpression(query,"Age+10", type, scope);

> di.setExpression(expr1);

> di.setLabel("Age Plus 10 years");

> query.addBusinessItem(di);

> // Add the data item as result item for the query.

> query.addResultItem(di);

> return query;

}