Literal Scope Variables

Literal scope variables can be assigned and referenced directly within the PSL source code at compile time. The compiler inserts the values into the generated code as literal values.

Literal variables can be set to any expression that is resolvable at compile time, including a subset of PSL methods. This scope provides the ability to optimize generated code by incorporating database values directly in the code at compile time, and improving readability and maintenance by assigning often-used strings into literal scope variables. The CUVAR variable is a global scope literal variable that is automatically instantiated by PSL at compile time, and can be referenced anywhere in the source code.

Literal variables are scoped within the subroutine and cannot be Public.

For additional information, refer to the Methods Supported for Literal Scope Variables section.

Example 1

The following PSL code:

type literal String X = "All this"

type String y = X_" is that"

quit

 

will generate the following M code:

N y S y = "All this"_" is that"

 

Example 2

A programmer could enter the following line of code:

set x=CUVAR.%MCP

The code generator will extract the value of %MCP from the CUVAR table and generate the following code, assuming that CUVAR.%MCP is 1:

set x = 1

 

Example 3

The combination of literal scope variables, the #XECUTE command, and the #WHILE compiler command can be combined to provide powerful code generation. Use them to build program logic with parameter tables that include code expressions, functions, or methods as a column value. This links a table into a program, enabling you to generate program conditions based on table values.

This PSL source code

acrCalc(iacm,balint,irn,cmp,posacr,dip) // Return one day accrual interest

type literal ResultSet RS = Db.select("CODE,EXPR","UTBLIACM")

#while RS.next()

xecute "if iacm="""_RS.getCol(1)_""" quit "_RS.getCol(2)

#end

quit 0

 

will generate the following M code:

I iacm="10" Q (balint+cmp)*irn/36000

I iacm="11" Q (balint+cmp)*irn/36500

I iacm="13" Q (balint+cmp)*irn/36500

I iacm="20" Q (balint+posacr)*($$EXP^%ZFUNC(irn/36000)-1)

I iacm="21" Q (balint+posacr)*($$EXP^%ZFUNC(irn/36500)-1)

.

.

.

When Standard is Enforced: Profile v7.0