6 24 2 Data Classes as Variables

Visual LANSA

6.24.2 Data Classes as Variables

You can define data class components based on any field enrolled in the repository. Here are some examples of how you would define your own data class components:

 

DEFINE_COM class(#GIVENAME) name(#USER_GIVENAME) 
DEFINE_COM class(#EMPNO) name(#LAST_EMPNO) 
DEFINE_COM class(#SALARY) name(#SALARY) 
DEFINE_COM class(#SALARY) name(#OLD_SALARY) 
DEFINE_COM class(#SALARY) name(#NEW_SALARY) 

 

And here is how you would use commands to manipulate the components:

 

SET com(#SALARY) value(34000.56)
SET com(#OLD_SALARY) value(12567.45)
SET com(#NEW_SALARY) value(#OLD_SALARY.Value)
IF cond('#SALARY.Value <= #OLD_SALARY.Value')

 

In the above #SALARY, #OLD_SALARY and #NEW_SALARY are all components of the class #SALARY. The class defines what they are, how long they are, what number of decimals they have, etc.

The important thing to note is that #SALARY in the LANSA repository defines a class of an object. It does not define a component instance. The instances are defined in the DEFINE_COM statements and there may be many instances with many different names . By default a component has the same name as the class to make coding easier.

This concept is relatively easy to understand when dealing with your own things such as #EMPNO,  #SALARY, #GIVENAME because they are such simple things.

However, your repository contains many other classes shipped with LANSA. These components are sometimes referred to as 'primitives' and their names start with #PRIM_.  For example #PRIM_ALPH is a primitive alphanumeric data class and #PRIM_NMBR is a primitive numeric data class. The primitive components can be used like your own classes (or fields) to define components within your code.

For example to define a string variable in your code, you could define a #MYSTRING component based on the primitive alphanumeric variable:

 

DEFINE_COM class(#PRIM_ALPH) name(#MYSTRING)

 

And then use this component in your code:

 

SET com(#MYSTRING) value(#EMPNO)

 

Similarly, to define a numeric variable in your code, you could define a #MYNUMBER component based on the primitive numeric data class:

 

DEFINE_COM class(#PRIM_NMBR) name(#MYNUMBER) 

 

The primitive data classes have also some special uses such as to create 6.26.2 Picklists in 6.26 Property Sheets.

6.25 Using Common Dialogs

Ý 6.24 Data Classes