Expressions

Expressions In Microsoft Dynamics C/AL

Definition

An Expression is a formula telling the computer how to generate the desired value.Like a variable and a constant, an expression has a type and value. A expression must be evaluated at run-time in order to determine its value. Although a constant's value is known at all times, a variable value is determined at run time, the  system must look it up in memory.

Examples

Quantity * DirectUnitCost

Expressions Function Calls

Expression function call are the type of function calls that calls from the expression itself.

If you try to assign too many characters to a string variable, you will get a runtime error. How this overcomed, since the error doesnot occur until the program is running? One of the method to overcome this is to design your program such that this error could never happen. In some cases using another method. 

MAXSTRLEN Function

MAXSTRLEN function will tell you at runtime the maximum legth of a string that can fit in a variable. It has one parameter, which is the variable in question. The return value is of type integer.

Let us consider the following programing code

-------------------------------------------------------------------------------------

Description := COPYSTR('The message is: ' + CodeB,1, MAXSTRLEN(Description));

-------------------------------------------------------------------------------------

Where Description is a type text variable of length 30 and CodeB is the type of datatype 'Code' with size 50.

Once we use this type of coding style then the error will not through the system because only the Maximum string lengh only copying and displaying.

Related Posts with Thumbnails