LOCAL FUNCTIONS AND VARIABLES

LOCAL FUNCTIONS AND VARIABLES
Local Functions
A local function is a function that can be called in the object in which it is defined. Any function that not be defined by local function called from other objects as well as the objects from which its defined.
Local Variables
A local variable is avariable whose scope is limited to single function. This means that in this function trigger code, a local variable can be used like any other variable. If the name of a local variable is reffered outside of the function in which it is defined, syntax error will result.

FUNCTION PARAMETERS

FUNCTION PARAMETERS IN MICROSOFT DYNAMICS

Function parameter is one or more variables or expressions that are sent to the function through a function call. These parameters provided for function information also can able to modify that information. If there is more than one parameter, the parameters will be sepearated by commas.

There are mainly 2 types of parameter passing occur

  1. Pass By Value
  2. Pass By Reference
  • Pass By Value:- In this type of parameter passing only pass some values only. If we change thse values then it will not affect in the parent trigger or values. That is once pass the value it will not affect any kind of changes in the parent method, its only passing the value.
  • Pass By Reference:- In this kind of parameters its pass like reference of the variable, sometimes called name of the variable. Whenever we change the value of these variables it will affect the parent trigger also. Because in this type the computer knows the exact storage space of that variable or parameter. 

FUNCTIONS IN MICROSOFT DYNAMICS

FUNCTIONS IN MICROSOFT DYNAMICS

Definition

Functions are named portions of a program, some times called as Subprogram or Subroutine.

When a function is called from a set of programming code then current programming code is suspended and continued with a trigger code. And after the completion of that trigger the program control return to the origin. 

A function can be used as expression also

For example:

TotalCost := Qty * CalculatePrice

In this code CalculatePrice is one function that calculate the price and after the calculation it return some value based upon that further programming codes executes.

Built In Functions

In Microsoft Dynamics C/SIDE programming using some built in functions also. These programming codes cannot be viewed by the users and it cannot be modified.

Some of the built in functions are as follows

  • MESSAGE :- Displays a message on the screen.
  • MAXSTRLEN :- Return defined legth of string variable.
  • COPYSTR :- Returns part of a string
  • CLEAR :- Clears the passed in variable
  • ARRAYLEN :- Returns number of elements in an array.

CASE

CASE Loop or Statements

CASE Loop or statements is a conditional statement. 

Like IF loop or statement these also works in the manner that once the statement is true then some statements are executed other wise the else part will be executed. But in the case of CASE we can consolidate muliple levels of IFloops in one CASE. Some programming languages like C its called as SWITCH - CASE loop but in Navision or Microsoft Dynamics NAV we called this as CASE only.

Syntax of CASE 

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

        CASE Expression OF

               Value Set 1 : Statement 1;

               Value Set 2 : Statement 2;

                 ...

               Value Set n : Statement n;

             ELSE Statement n+1;

         END 

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

A sample program for the CASE is as follows

==============================================================

     CASE Color OF 

          Color :: Orange:

                             MESSAGE('COLOR IS ORANGE');

          Color :: Red,Color :: Green:

                             MESSAGE('COLOR IS RED OR GREEN');

            ELSE

                             MESSAGE('COLOR NOT ORANGE,RED OR GREEN');

      END

==============================================================

WITH Loop / Statement

WITH Loop / Statement

WITH Statement or loop is used to make record variables easier. 

Record variable is a complex datatype with one variable we can store multiple values like arrays. Each record having different fields and each of these fields can able to store different data types also. These fields are separated by the '.' or dot sign. If a customer record having field named Name then it can be specified like customer.Name

Syntax Of WITH Loop

Suppose we having three fields names name, address and City then it can be specified in the recod named customer as folows

     customer.Name := Txt[1];

     customer.Address := Txt[2];

     customer.City := Txt[3];

We can sort these kind of representation in the system different way so that we can minimise the number of codings that syntax of WITH Loop is as follows

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

           WITH Record Variable DO Statement

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

 By the help of this syntax we can remodify the abow code as following type of codes

=====================================================

                WITH customer DO BEGIN 

                             Name := Txt[1];

                             Address := Txt[2];

                             City := Txt[3];

                  END; 

=====================================================

Once we cross check the abow codes we found that the Record variable is not found with any of the fields. The computer will automatically konow the identification about each fields assigned to the records.

REPEAT - UNTIL Loop

REPEAT - UNTIL Loop or Statement In Microsoft Dynamics NAV C/AL

Definition

REPEAT - UNTIL Loop is a repetative loop, is used for programmes having one or more statements to be executed until some condition.

Syntax OF REPEAT - UNTIL Loop

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

REPEAT Satements UNTIL Boolean Expression

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

This works in a manner like that it will work the statements until the Boolean Expression is true. The difference Between WHILE-DO loop is that the REPEAT - UNTIL Loop will execute atleast one time and then only it will check the Boolean expression true or false. But in the case of WHILE-DO loop only execute the code when a particular condition is true.

For Example:

=======================================

REPEAT

i :=  i + 1;

Total Sales := Total Sales + Sales[i];

UNTIL Sales[i]=0;

=======================================

The abow example works in a manner like that it will execute the statement once after that check the Boolean expression Sales[i]=0 or not if the condition is true then reapeat the statement otherwise it will exit from the loop and execute the statement immediatly after that.

WHILE .. DO Loop

WHILE .. DO Loop or Statement In Microsoft Dynamics NAV C/AL

Definition

The WHILE .. DO Loop is a repetitive statement or loop, is used in the program where a certain code is to be executed as long as some condition is true.

Syntax Of WHILE .. DO Loop

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

WHILE Boolean Expression DO Statement

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

This is simpler than the IF loop. In the case of  WHILE .. DO Loop the system check continously the boolean expression become true then the statement between BEGIN and END execute otherwise move to next statement.

For Example:

==================================================

WHILE Sales[i+1] <> 0 DO BEGIN

     i := i + 1;

     Total Sales :=  Total Sales + Sales[i];

END;

==================================================

This is work in a manner like that check every time the Sales[i+1] <> 0 and if the condition is true then execute the statement between BEGIN and END other wise execute after the END statement.

Related Posts with Thumbnails