Showing posts with label Variables. Show all posts
Showing posts with label Variables. Show all posts

Self Practise Topic 2

Self Practise Topic 2

Varibles & Datatypes Area

  1. 1)Create an Integer Item named mynum and store the value 100 and diplay the data in a Message Box when the page run.
  2. 2) Create a program to add two decimal numbers and display the result in a Message box when the object run.

Answers:

2.1)Here i am not specifying how to define a variable, i think you already understand how to define that from the previous post. Only diff is that you have to define the variable in the Datatype column as integer. 

The program code for display that was

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

mynum := 5;

MESSAGE('The Value Of %1 Is %2', 'mynum', mynum);

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

2.2) For doing this you have todefine 2 variables as Decimal numbers.

Let us consider Num1 and Num2 , the result storing and display from the Result variable

the programming codes are as follows

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

Num1 := 2;

Num2 := 7;

Result := Num1 + Num2;

MESSAGE('The Value Of %1 Is %2', 'Result', Result);

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

The result will be 9

Sample Program to display a Stored Data

Sample Program to display a Stored Data

This session describes how to define a variable as particular Data type and display their contents.

First up all we will see the assigning a text to a 'text' variable and display there contents in a message box.

  • For doing this you have to first define the variable as text variable for that goto the Tools -> Object Designer 
  • Open the object you want to do coding. (for how to open a C/AL Editor see the C/AL Editor page) 
  • After open the C/AL editor goto the View -> C/AL Globals
  • Go to the Variables tab and enter the Name as your text name let us say "sampletext"
  • Go to the Datatype column, here you can specify the datatype of the variable 
  • Got to the Length column type 30. ie, is the space where specifies the length of the text.

Variables defining area looks like follows


After defining this press Esc and goto the normal C/AL Editor window and type the following text in the OnRun()

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

sampletext := 'My Sample Text';
MESSAGE('The Value of %1 Is %2', 'sample text',sampletext);

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

Then you will get a output like the following when you run the program.

Variables

Definition

A Variable is a reference to the data value that can vary while user is running the application.

Variable always check actual memory location in which data is stored. Every varible has a datatype which describes the type of data that can be stored and each of them having value, this is stored actually in the memory address.

Mainly 3 types of variables are there

  1. Global Variables
  2. Local Variables
  3. System Defined Variables

Global Variables:-If a variable can be accesse anywhere in an object, its said to have 'Global' scope.

Local Variables:-If the accessibility is limitted to a single trigger in an object, that type of variable is called 'Local' variable.

System Defined Variables:- A variable that is maintained automatically by the system. Examples- Rec in Table object, CurrReport in Report object

Related Posts with Thumbnails