| home -> documentation -> EXPVAL tag |
Description
The EXPVAL tag is used for dynamic calculation inside the DBSP pages. With this tag, is possible to calculate a certain value and apply a specific format to the obtained result before inserting it in the page.
Syntax
| <#EXPVAL EXPRESSION="anexpression" [FORMAT="THEFORMAT"]/>
|
| EXPRESSION |
You can specify in anexpression an arithmetic
expression. The DBSP engine will evaluate the expression first and the result
will be replaced instead of the Tag. For more information see the EXPRESSIONS property description. |
| FORMAT |
This is an optional property that can aid you to present the obtained value in different formats. For more information see the FORMAT property description. |
References
EXPRESSION
FORMAT
Applications
The EXPVAL tag is very useful to perform in place calculations and avoid the use of unnecessary variables. See the examples below for a better concept understanding.
Examples
Example 1. Simple calculations using expressions.
This example shows how to calculate values using expressions and the EXPVAL tag.
Source code
File: Examples/ExpVal.dbsp
<!--ExpVal.dbsp--> ExpVal example. The result of the operation : TRUNC(5.7) IS <#EXPVAL EXPRESSION="TRUNC(5.7)"/> The result of the operation : RANDOM(7) IS <#EXPVAL EXPRESSION="RANDOM(7)"/> The result of the operation : (4+3)*0.06 IS <#EXPVAL EXPRESSION="(4+3)*0.06"/> With FORMAT property. The result of the operation : TRUNC(5.7) IS <#EXPVAL EXPRESSION="TRUNC(5.7)" FORMAT="NUMBER:8:2"/> The result of the operation : RANDOM(7) IS <#EXPVAL EXPRESSION="RANDOM(7)" FORMAT="MONEY:4:3"/> The result of the operation : (4+3)*0.06 IS <#EXPVAL EXPRESSION="(4+3)*0.06" FORMAT="PERCENT:5:1"/>
|
Test example
Example 2. Runtime calculations.
This example shows how to calculate values on the fly using the EXPVAL tag.
Source code
File: examples/Ex6_6_1.dbsp
Calculating values on the fly Calculating values on the fly This example shows how to calculate values at run time. The PPP column and the totals are calculated on the fly. Country | Population | GNI * | PPP * | <#SETCOOKIE NAME="TOTALPOPULATION" VALUE="0"/> <#SETCOOKIE NAME="TOTALGNI" VALUE="0"/> <#SETCOOKIE NAME="TOTALPPP" VALUE="0"/> <#SETCOOKIE NAME="COUNTRYCOUNT" VALUE="0"/> <#DATASET ALIAS="OPEX" QUERYID=16> <#COUNTRY/> | <#POPULATION FORMAT="NUMBER:10:0"/> | <#GNI FORMAT="MONEY:10:2"/> | <#EXPVAL EXPRESSION="(GNI/POPULATION)*1000" FORMAT="MONEY:12:2"/> | <#SETCOOKIE NAME="TOTALPOPULATION" EXPRESSION="TOTALPOPULATION+POPULATION"/> <#SETCOOKIE NAME="TOTALGNI" EXPRESSION="TOTALGNI+GNI"/> <#SETCOOKIE NAME="TOTALPPP" EXPRESSION="TOTALPPP+(GNI/POPULATION)*1000"/> <#SETCOOKIE NAME="COUNTRYCOUNT" EXPRESSION="COUNTRYCOUNT+1"/> <#/DATASET> Totals | <#TOTALPOPULATION FORMAT="NUMBER:10:0"/> | <#TOTALGNI FORMAT="MONEY:10:2"/> | <#TOTALPPP FORMAT="MONEY:10:2"/> | Average | <#EXPVAL EXPRESSION="TOTALPOPULATION/COUNTRYCOUNT" FORMAT="NUMBER:10:0"/> | <#EXPVAL EXPRESSION="TOTALGNI/COUNTRYCOUNT" FORMAT="MONEY:10:2"/> | <#EXPVAL EXPRESSION="TOTALPPP/COUNTRYCOUNT" FORMAT="MONEY:10:2"/> | GNI - Gross National Income (in thousands of dollars) PPP - Purchase Power
|
SQL Sentence: ID=16
|
SELECT COUNTRY, POPULATION, GNI
FROM COUNTRYSTATS
ORDER BY COUNTRY
|
Test example
|