Showing posts with label Data Types. Show all posts
Showing posts with label Data Types. 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.

Data Types

Definition:

Data Types are diffrent kinds of information that may appear in the C/SIDE Environment.

Different data types having different values and each of them having diffrent way of representation. 

Example:

If we have two data types "12" and "36" and add them, we will get different values according to different data types. ie, If they are numbers then the result would be 48 and on the other hand if we consider these are text then the result would be "1236" only.

Data Types can be mainly divided in to 4 types

  1. Simple Datatypes
  2. Numeric Data Types
  3. String Data Types
  4. Boolean, Date and Time
  • Simple Datatypes: Simple data types are those types of data which have only one value and which cannot be broken up into other values of different types.                                                    
  • Numeric Data ypes: Numeric Data Types are all forms of numbers or amounts.

TYPERANGESIZEEXAMPLEDEFAULT VALUE
IntegerFrom 2,147,483,647 to + 2,147,483,6474 Bytes

12

1000

-100

0

0
DecimalFrom -1X10^63(1 followed by 63 zeros) to + 2,147,483,64712 Bytes

12.50

-2.0

0.008

0
Option

Red, Orange, yelow, Green, Blue, Indigo, Violet Where 0 is Red and 3 is Green

0
Char0-2551 Bytes

'b'

'C'

'3'

'?'


  • String Data Types: 

TYPERANGESIZEEXAMPLE
TextFrom 0 to + 250add one to the length and round up to the nearest four. Thus and 8 char text takes up to 12 bytes (1+8 round up to the nearest 4)

"Hello"

'127.50'

Code

All Letters are forced

to upper case and all leading and 

trailing spaces are removed.

add 2 to the length and round

up to the nearest 4. Thus an 11 character code 

takes up 16 bytes (2+11 round up to the nearesr 4)

'HELLO'

'127.50'

  • Boolean, Date and Time
TYPERANGESIZEEXAMPLE
Boolean

1 Byte in memory only 

TRUE

FALSE

Date

1/1/0000 through 12/31/9999

4 Bytes

0D (The undefined date, less than all other dates)

123197D (Dec 31 1997)

Time

00:00:00through23:59:59:999

4 Bytes

1030000T (10:30am)

0T(The undefined time, less than all other times)

Related Posts with Thumbnails