You are on page 1of 37

Navision Document

 Navision Attain is a two-tier application. It consists of a Database Management


System (DBMS) that resides on the server and a Graphical User Interface (GUI)
that resides on each client.
 Navision Attain has two database options: the standard Navision database and
Microsoft’s SQL Server database.
 Communication between the client and the server is done in one of the three
ways.
o In the SQL Server Option, the client communicates with SQL Server
through an ODBC connection.
o In the Navision Server option, the client can communicate with the server
through the TCP/IP or NetBIOS protocols.
 Navision Application Server (NAS) is a middle-tier server that supports an n-tier
architecture, which executes business logic without user intervention.
 Navision Application Server acts as a client towards a database server and can
act as a server for other services.
 NAS can communicate with both Navision server and SQL Server. It only
supports the windows authentication and automatically reconnects to the
database server

Client:

 The client can connect directly to a standard database file without going through
the server.
 The client is also responsible for executing all the business logic.
 The client reads objects from the database and is also responsible for running the
objects and controlling their behavior.

Server:

 Controls the number of users that can connect to the database at one time.
 Controls access to the data through locking.
 Keeps track of all the read and write transactions performed by every user.
 Returns data to each client, as requests are made.
 Performs all key-based filtering and calculates SumIndexFields.
 Caches data that can be requested again.

1
Satya
© private Solutions.
Note: Microsoft SQL Server also does all of these things. One thing that the standard
server does that SQL Server does not, is keep track of different versions of the same
record.

2
Satya
© private Solutions.
Basic objects:

There are five basic objects in C/SIDE.

1. Table object
a. It is used to storing and retrieving data
b. Understanding tables is the key to using all of the other objects.
2. Form object
a. A form is used to display data to the user in a familiar and useful way.
b. Most forms allow the user to add records to a table, view and modify
records as well.
3. Report object
a. It is used for printout details using filters and sorting based on that he or
she choose.
4. Dataport object
a. Dataports allow you to export or import table data.
5. Codeunit object
a. It allows you, the developer, to organize and group the code that you write.
(This only object doesn’t anything with tables.)

C/SIDE FUNDAMENTALS

C/SIDE (Client/Server Integrated Development Environment)

Each type of application object is created using a specific tool called a designer.

C/SIDE User Interface:

The most important parts of the C/SIDE user interface.

Title bar: Get information about the name and path of the current database.

Menu bar: Access functions on drop-down menus.

Tool bar: Access the most commonly used functions quickly.

Work area: Work with the application design tools.

Status bar: See basic status information about your system (such as the current date
and your user ID)

3
Satya
© private Solutions.
General C/SIDE Concepts

All the five objects are used in the some general concepts those are…..

Properties: Properties are used to control the appearance of data, specify default
values, specify colors and define relationships.

C/AL: C/AL is the language used for writing functions in C/SIDE.

Triggers: When specific things happen to the application objects, the system
automatically activates a trigger. Inside a trigger, you can add your own C/AL code if
you want to modify the default behavior of the application object or extend its
functionality.

Keys: A key defines the order in which data are stored in your tables. For speed up the
searching in defined ways. (Like… primary key)

Fields: A field is the smallest unit of information in your database. A field typically
stores information such as a name or a number.

Controls: Controls are objects on a form or report that display data, perform actions or
decorate the form.

Request Form: A request form is a form that is used in a report. For user specify
filters and options for the report.

Data items: these are like datasource in ax. Data items are mostly used in reports (I
update this later.)

Sections: A section is a substructure of a data item. A section is where you place


controls to display information. You will typically use sections defining the body,
header, and footer in your report.

4
Satya
© private Solutions.
Tables
A C/SIDE table may be visualized as a two-dimensional matrix consisting of columns
and rows.

The following figure illustrates that a table description contains properties, triggers,
fields and keys and shows how these are related:

Table Description

 Table properties
 Triggers
 Fields
o Properties
o Triggers
 Keys
o Properties

Table properties

Id: Table number must be unique.

Name: Table name.

Caption: Caption for the table.

CaptionML: Sets the string that is used to identify a control or other object in the user
interface. (Here ML means Multi language.)

Description: Optional

Data Per Company: save data as company base.

Permissions: read; write, etc.., permissions.

Lookup Form ID: Sets the ID of the form you want to use as a lookup.

Drill down Form ID: Sets the ID of the form to use as a drill-down.

Data Caption Fields:

Paste Is Valid: Sets whether inserting records into this table using the paste command
is enabled.

5
Satya
© private Solutions.
Linked Object: Use this property to link to SQL Server objects. Property Yes
LinkInTransaction become available.

Field properties

Some properties are same as table properties, I write only unknown properties.

Code and Text:


Field Class:

Normal: Just normal Field.

Flow Field: It is just like displaying the values in the table. Flow Field always
non-editable. When Field Class set to Flow Field then calcFormula is activated.

Flow Filter: To filter the data in the parent table, and get only required data.

Alt Search Field:

AutoFormat Type:

AutoFormat Expr:

Caption Class:

Editiable: edit or not

Not Blank: like mandatory

Numeric: only accepts numbers.

Char Allowed: Range of characters user can enter into the field. Ex, adxz. It allows
only following character’s a,b,c,d,x,y,z

Date Formula: Yes or No.

Value Allowed: Only accepts specified values. Ex 1;2;3 only allow 1, 2 or 3.

SQL Data Type: Here uses SQL data types Varchar, Integer, variant, BigInteger.

Table Relation: If you need any relation b/w this field and another table field.

Validate Table Relation:

Test Table Relation:

6
Satya
© private Solutions.
Extended Datatype: some additional datatypes like phone no, email, etc..,

Boolean

CalcFormula: No use for the Boolean datatype because calcFormula only for decimals.

Blank Numbers:

DontBlank (default) Not clear any numbers


BlankNeg Clear negative numbers
BlankNegAndZero Clear negative numbers and zero
BlankZero Clear numbers equal to zero
BlankZeroAndPos Clear positive numbers and zero
BlankPos Clear positive numbers
Blank Zero:

Sign Displacement:

Not Blank:

Integ er

Auto Increment: if set to Yes, then it increment the value for next record.

Decimal

Decimal Places: allows specified number only, after decimal.

Test Table Relation:

Option

Below properties are only for “option” datatype’s.

Option String: Here we specify the option separated by comma.

Ex _,a,b,c Note: ‘_’ means space. (Appears like BaseEnums)

Date
Closing Dates:

BLOB

BLOB fields are used primarily to store pictures.

Sub Type:
7
Satya
© private Solutions.
Owner:

Keys

 A key is a sequence of one or more field IDs from the table. Up to 40 keys can be
associated to a table.
 The first key in the list is the primary key.
 The primary key is composed of up to 20 fields in a record.

Primary key

 Open the table design


 Then open key designer window(Alt+v  k)
 Add fields up to 20 as mentioned above, separating by coma.
 The primary key determines the logical order in which records are stored
regardless of their physical placement on disk.
 DBMS checks that the information in primary key fields before inserting the new
record in the table.

Secondary key

 We have already mentioned that up to 40 keys can be associated to a table and


that the first is the primary key. All other keys are secondary keys and optional.
 A secondary key can be changed into an inactive key. This means that the DBMS
does not use time during updates to maintain its index.
 Furthermore, an inactive key doesn’t occupy database space.
 To use secondary key (shift+F8)
 More information “Navision Attain objects Page No.36”

Table relations

 When you create a table relation, you are specifying which field to lookup in
another table.
 If the optional field ID is left blank, it is the first field in the primary key that the
relation is made to.
 To make a relation to the second or third field in a primary key, you must specify
the field ID.
Note: The field ID specified in the Table Relation property must be in the
primary key of the table specified by the table ID in the property.

8
Satya
© private Solutions.
Simple Table with Table Relations

 Open the field properties  Table Relation F6


 Then four fields appear those are condition, table, field, filter.
o Conditions : Current table conditions.
o Table : Specified Related table name
o Field : Required field for lookup.
Note: Field must be in the primary key in parent table.
o Filter : Here we specify related table condition.

Renaming Records

 Changing the primary key values of a record in a table changes the name of the
record. This is called this renaming a record.

Filtered Table Relations

 Specifying the filter field in the TableRelation property.

Conditional Table Relations

 Specifying the condition field in the TableRelation property.

Special Table Fields

SumIndexFields

 A SumIndexFields is a decimal field that can be attached to a key definition.


 SumIndexFields permit fast calculation of sums of numeric columns in tables,
even in tables with thousands of records.
 This occurs because SumIndexFields are maintained when the database record is
updated.
 Each key can have at most 20 SumIndexFields.

FlowFields

 FlowFields are not a permanent part of the table data. It is a virtual field.
 The information in the FlowFields exists only at run time.
 FlowFields are automatically initialized to 0 (zero). To update FlowFields, you
must use the C/AL function <Record>.CALCFIELDS.

9
Satya
© private Solutions.
Types of tables

Master table

 A Master table contains information about the primary focus subject of its
functional area.
 The name of this table is the name of one of the records in the table.
 Primary key: The Primary Key of a Master table is a Code field of length 20,
named "No." or occasionally "Code".
 Standard Fields: The description field of this table is a Text field of length 30,
named "Name" or "Description".

Associated forms

There are three or more forms that are used with a Master table.

 Card form
 List form
 Statistical form

Associated card form:


 First is a Card Form that is used to edit the records in the Master table.
 The name of this form will be the name of the table followed by the word "Card".
Thus the Card form for the Customer table will be named Customer Card.
 This form is link to the other forms.
o List form  F5
o Statistic form  F9
o Ledger tables  ctrl+F5

Associated list form:


 The second form used with a Master table is a List Form. This is used view the all
records in the master form.
 Unlike card form, list form cannot be editing the master table.
 This form is link to the other forms.
o Card form  shift + F5
o Statistic form  F9
o Ledger tables  ctrl+F5
 This form is set as the LookupFormID property and the DrillDownFormID
property of the table, since it is used not only for viewing but also for Lookups
and Drill downs into this table.

Associated statistic form

10
Satya
© private Solutions.
 The third form used with a Master table is a Statistics Form, which is used to view
calculated information about the record in the Master table.
 The name of this form will be the name of the table followed by the word
"Statistics".
 Thus the Statistics form for the Customer table will be named Customer
Statistics.

Supplem ental Table

 A Supplemental Table is a table in which information is stored about a


supplemental subject used in one or more functional areas.
 Ex Currency, language,
 Primary key: The Primary Key of a Supplemental table is a Code field of length
10, named "Code".
 Standard Fields: The description field of this table is a Text field of length 30
or 50, named "Description" or “Name”.

Associated form
 The name of this form is the plural of the name of the Supplemental table. Thus,
the form that is used to edit the Currency table is named "Currencies".
 This form is set as the LookupFormID property of the table since it is used not
only for edit but also for Lookups into this table.

Note: For remaining type of tables refer “Navision attain object” pdf Page No.75.

11
Satya
© private Solutions.
Forms
Forms are used for entering information into database tables and for retrieving
and displaying information from database tables.

Form Description
 Form Properties
 Triggers
 Controls
o Properties
o Triggers

Controls
All information on a form is presented in controls. Controls are objects that can
display data from a database table field.

 Bound controls: Typically, a form is related to a database table and will be used
to enter information into the table and display information from the table. The
form is said to be bound to the table.
 Unbound controls: An unbound form is not related to a table.

Triggers
Certain predefined events that happen to a form or a control cause the system to
execute a user-definable C/AL function-- -the event triggers the function. The event and
the function are together called a trigger.

Two types of triggers those are

 OnOpenForm: It containing statement that will be executed when the form is


opened.
 OnModifyRecord: It containing statements that will be executed before the
system accepts changes the user makes to a record.

Using the Form Wizard

The form wizard can create two different types of forms – Card forms and Tabular
forms.

Card Forms

A card form is a form that displays one record at a time to the user.

12
Satya
© private Solutions.
Tabular Forms
A tabular form is a form that displays many records at a time to the user.

Using FieldMenu

The Field Menu can be used to add fields to any bound form, whether you used the
wizard to create the form or not.

Click the gray box beside the Balance field to select the field (it should be highlighted in
blue).

Creating Menu B uttons


Menu buttons are containers for menu items.

Creating Menu Items

Click View, Menu Items to open the Menu Designer(shortcut Alt+V,M).

13
Satya
© private Solutions.
In the Menu Designer you have above options.

 Caption: Any name for the Menu Item.


 ShortCutKey: Any ShortCutKey for the MenuItem.
 Action: It is for what action if perform, if MenuItem pressed. This have following
options
o Yes:
o No:
o Close:
o Stop:
o FormHelp:
o RunObject: If we use RunObject, it opens the RunObject field specified
form.(Form name must be prefix with “Form”)
o RunSystem:
o LookupTable: It opens the LookupFormID specified form.
 RunObject: Here we specify form name. (Form name must be prefix with
“Form”)

Note: A PushAction of <0> will cause the button to do nothing (except fire its
OnPush trigger).

Creating Subforms

To display two different source tables information in a single form, we use the
Subforms.

Some important points are

 Header form No. and Line form Document No. is always equal.
 In the Subforms Line No. automatically incremented for that, we must set
AutoSplitKey property to Yes.
 In the Subforms Document No. and Line No. must be in visible.

14
Satya
© private Solutions.
Types of Forms

Card form

 A Card form lets the user view and edits one record at a time in a table.
 Card form always has tabs. Even if there are few fields, there is at least one
General tab, which is always first.
 The table's Primary Key field is always the first field in the General tab. In tables
that use Card forms, there is only one field in the Primary Key.

Statistics Form

 A Statistics form is a one-record form that lets the user view but not edit
information.
 It usually contains FlowFields, which lets the user drill down to get to more
information.
 Statistics Forms can also contain tabs, in order to help organize the information.
 The table's Primary Key is displayed only in the form's title bar.
 Ex. Customer Statistics

Tabular form

 A Tabular form is a multi-record form that lets the user view multiple records
from a table and edit them.
 Tabular forms are named with the plural of the name of the table with which they
are associated.
 Ex. General Posting Setup.

List form

 A List form is a multi-record form that lets the user view multiple records from a
table at once, but not edits them.
 Also, the Primary Key, always an integer named "Entry No.", is displayed in the
right-most column rather than the left-most column.
 Ex. Customer Ledger Entries

Worksheet Form

 A Worksheet form is a specialized version of the Tabular Form, a multi-record


form that lets the user view multiple records from a table and edit them.
 This is done using the AutoSplitKey property of the form, combined with an
integer as the last field in the table's Primary Key.

15
Satya
© private Solutions.
 The Primary Key fields of the associated table do not display on the Worksheet
Form.
 The name of the worksheet form will end with the word "Journal".

Header/Line Form

 In many cases, a Header/Line form will represent a Document.


 Header/Line forms are, in fact, two separate forms associated with two different
tables.
o The main form is a Card Form associated with a table.
o The main form has a sub-form control.
o A Worksheet Form is displayed within the sub-form control that is
associated with a different table.
 Ex. Sales Invoice

Setup Form

 A Setup form is a one-record form that lets the user view and edits the one and
only one record in a setup table.
 The user is not allowed to insert or delete this record using this form.
 Since there is only one record, the Primary Key does not display anywhere on this
form.
 Ex. General Ledger Setup

Menu Form (modules)

 A Menu form is a non-bound form that lets the user access many of the other
form types for a functional area from the main menu.
 The form usually consists of command buttons or menu buttons. However, the
appearance of the buttons is usually not what you would expect.
 The buttons properties change so that they look basically like labels with small
circles or triangles in front of the caption.
 Ex. General Ledger Menu.

Other Multi-Record Forms

 There are other forms that let users view and/or edit multiple records at the same
time. These include TrendScape forms and Matrix forms.
 Ex. Items by Location Form.

16
Satya
© private Solutions.
Reports
Reports are used to print information from a database in a structured way.

 Reports can be non-printing. While this may sound like a contradiction in terms,
it is not.
 A report can be used to automate many recurring tasks such as updating all
prices in an item list.
 This could be performed entirely from C/AL code in a codeunit, but using a
report makes it a lot easier because you can use the powerful data modeling
available for report design.

Report structure

Report Description
 Properties
 Triggers
 Data Items
 Properties
 Triggers
 Sections
o Properties
o Triggers
o Controls
 Properties
 Request Form
 Properties
 Triggers
 Controls
o Properties
o Triggers

Data Items

 A data item corresponds to a table, to present data in the reports.


 When a report uses more than one table, you set relations between the data items
in order to retrieve and organize data in the way that you want.

17
Satya
© private Solutions.
Sections

 A section can be thought of as a block of information to print on the paper.


 The complete report consists of a number of sections.

Request Form

 A request form is a form that is run before the actual report begins execution.
 It is used to gather requests and options from the user of the report.
 Example. Sort order or level of detail.

Report properties:
UseReqForm: If Yes show report O.W., It just take a screen shot.

The Report Designers

The Report Designer contains two additional designers – the Section Designer,
used for designing the layout of reports, and the Request Options Form Designer,
used for designing request options forms.

The Section Desig ner

 Each data item can have one or more sections. To view the section Designer,
select the View menu and then Sections.
Note: If the report has its Processing Only property set to Yes you cannot create
any sections.
 To create sections press F3.
 To delete sections, select and press F4.

Body: This section is printed once for every record that is processed by the Data
item.

Footer: This section is printed last for a Data item. By default it is only printed once
each time the Data item is processed, but you can choose to print it on every page. It
display bottom every page.

18
Satya
© private Solutions.
GroupFooter: This section is printed right after the last record in a group that is
processed. This section will ONLY print if the GroupTotalFields property for the
Data item is set and the Data item is appropriately sorted.

GroupHeader: This section is printed right before the first record in a group that
is processed. This section will ONLY print if the GroupTotalFields property for the
Data item is set and the Data item is appropriately sorted.

Note: If you specify Table view then only we get GroupFooter value.

Header: This section is printed first for a Data item. It is also have print it on every
page option.

TransFooter: This section is printed at the bottom of a page for a data item that
will be continued on the next page.

TransHeader: This section is printed at the top of a page for a data item that
continues from the previous page.

The Request Options Form Desig ner

 The request form is the form that is displayed to the user when they run the
report.
 Remember that the Options tab will be the last tab on the Request Form.
 When you add controls to this form, the Options tab will be displayed. The
Options tab will not be visible to the user until you add some controls.
 Request form used to generate report, according to user requirement.

Sections Work

Indentation or Linking

 If you give indentation b/w DataItems then we must use to properties.


o DataItemLink: Relation b/w parent and child.
o DataItemTableView: To sort data according to our need.
o TotalFields: sum the amount total fields against to specified field.
o Group TotalFields: Group the fields against to specified field.

Some Useful Properties

NewPagePerRecord: it uses new page for every parent table record.

19
Satya
© private Solutions.
PrintOnlyIfDetail: it prints data only, if any related records in child table against to
parent table.

ReqFilterFields: it appears while run the report. Before preview.

ReqFilterHeading: It is for specify for the tab name. While run the report. Before
preview.

Grouping With in a Report

 In a report you will generally need to print subtotals or to separate groups of


records based on fields within the records themselves.
 To use grouping we add section called footer, and specify the DataItemLink and
DataItemTableView properties.

Totaling In a Report

 This usually requires summing one or more fields that are being displayed or
read by the report and then displaying the Sum. We call this process “Totaling”
the report.
 To use grouping we add section called footer, and specify the TotalFields and
Group TotalFields properties.

Types of Reports

List report

 A List report contains a single DataItem that is the table that is being listed.
 The table is either a Master table or a Supplemental table.
 The name is usually the name of the table followed by the word "List", or
sometimes followed by the word "Listing".
 Ex. Customer Listing, Item List.

Test report

 A Test report is a report printed from a Journal table.


 Its purpose is to test each of the Journal Lines before Posting.
 Once an error is found during posting, processing stops and the error must be
fixed before Posting can be attempted again.

20
Satya
© private Solutions.
 Thus, in a journal with multiple errors, a test report is a good way of finding these
errors.
 The name is usually the name of the corresponding Journal form followed by the
word "Test".
 Ex. General Journal – Test, Resource Journal – Test, Payroll Journal Test
Report.

Posting Reports

 A Posting report can be printed as part of the "post and print" option on a
Journal.
 It is actually a report that is printed from the Register, and has the same name as
that Register.
 Ex. G/L Register, Item Register, Payroll Register.

Transaction Reports

 A Transaction report has two DataItems. Master table and Ledger table.
 This report is used to view all transactions for a particular Master record.
 Ex. Trial Balance Detail/Summary, Vendor Account Detail, Employee
Transaction Detail.

Other "Normal" Reports

 Reports are customized for a particular client.


 Many times, there will be some sort of group heading or total to split the lines
among various categories and subtotal the lines by the categories.
 Ex. Item Status by Salesperson, Vendor 1099 Information, Item Sales by
Customer.

Docum ent Reports

 Document reports are different from most other reports, in that, many of the
fields are not displayed in columns.
 An example of this kind of report is an Invoice. Where header and lines are
displayed.
 Header
o Header information is printed as though filling out an invoice document.
o It is repeated at the top of each page.
 Lines
o The lines for the invoice print out more like a normal report in rows and
columns.

21
Satya
© private Solutions.
o The lines correspond to the header on the same page, and lines from other
invoices do not display on the same page.
 Ex. Sales Invoice, Customer Statement, Purchase Order.

22
Satya
© private Solutions.
Basic Codeunits
A codeunit is a container for C/AL code that you want to use in many application
objects. If some you want the same function in different applications, Instead of
declaring the same functions over and over again, it would be useful if you only had to
define them once. This is where the codeunit becomes useful.

Functions, Global variables are same, as we know.

Temporary tables: A temporary table is a table that is not stored in the database.
Temporary tables are mainly used as structured variables that hold data temporarily
while you work on it.

Accessing codeunit in Objects:

 Define codeunit in table variables. (Table design, alt+v, b).


 <codeunit name>.<function name>.

Codeunit Assignment:

Single instance codeunit:

Clear and ClearAll:

Codeunit limitations:

Data types

Datatype Range Storage Default


value/example
Integer -2,147,483,647 to +2,147,483,647 4 bytes Zero
Decimal -1x1063 to +1x10-63. 12 bytes Decimal zero
Option Any no. of strings -------- Yes, no.(ex)
Char 0-255 (integer values) 1 byte ‘c’(ex)
Text 0-250 characters (1+no.of chars) ‘Hello’(ex)
nearest 4
Code (2+no.of chars) ‘Hello’(ex)
nearest 4
Boolean 1byte but when True or False
stores takes 4
bytes
Date 1/1/0000 to 12/31/9999 4 bytes 063012d(30/06/2012)
Time 00:00:00 to 23:59:59.999 4 bytes 103000T (10:30am)

23
Satya
© private Solutions.
Display variable
MESSAGE('The value of %1 is %2','LoopNo',LoopNo);

ERROR('Error box %1',n);

Assigning A Value To A Variable

<variable> := <expression> or <value>;

The Statement Separator


[<statement> {; <statement>}]

 Here semi colon statement separator (separating the statements).


 Note that whenever a semicolon is used, a statement must follow.
 Null Statement is automatically inserted after the last semicolon and before the
end of the trigger.

Note: It is not a "statement terminator", but instead signals the arrival of a new
statement.

Run-Time Errors
LoopNo := 27.5;

Overflow under type conversion of Decimal to Integer. Value:=27.5

YesOrNo := 1;

Type conversion is not possible because 1 0f the operators contains an invalid type.
Boolean := Integer

Function Calls In Expressions

MAXSTRLEN Function
Maxstrlen(description);

Display the length of description.

Output: 50.

COPYSTR Function
24
Satya
© private Solutions.
Copystr(<string>,<starting position>,<No. of char copy>);

Ex. Copystr(‘this is satya’,9,5);

Output: satya

Types Of Arithmetic Operators

Plus (+) and minus (-) Operator

Plus(+) / Char Option Integer Decimal Date Time


Minus(-)
Char Char Integer Integer Decimal N/A N/A
Option Integer Integer Integer Decimal N/A N/A
Integer Integer Integer Integer Decimal N/A N/A
Decimal Decimal Decimal Decimal Decimal N/A N/A
Date Date Date Date N/A N/A(+) N/A
Integer(-)
Time Time Time Time N/A N/A N/A(+)
Integer(-)

Multiplication Operator (*)

Multiplication(*) Char Option Integer Decimal

Char Char Integer Integer Decimal

Option Integer Integer Integer Decimal

Integer Integer Integer Integer Decimal

Decimal Decimal Decimal Decimal Decimal

Divide Operator (/)

 The result type of this division is always decimal.

Integ er Divide Operator (DIV)

 The result type of this division is always integer.


 Any decimals that would have resulted from an ordinary division are dropped,
not rounded.
25
Satya
© private Solutions.
Modulus Operator (MOD)

 It performs the modulus operation.


 Ex. 6 Modulus 10 is 6, 10 Modulus 10 is 0, 107 Modulus 10 is 7

Operator Precedence Effects


There are three levels of operator precedence used for arithmetic operators.

 Unary operator  +,-


 Multiplicative operator  *,/,DIV,MOD
 Additive operator  +,-
 Note: Sub expressions are always evaluated first. Means with in parentheses.

In the below examples operator precedence are according to underline wise.

 5 * 2 + 5 - 2 DIV -2; output: 16


 5 * (2 + 5) - 2 DIV -2; output: 36

Set Constant

A set constant consists of an open square bracket(‘[’ and ‘]’)

Ex. [2,4,6,8,10]

IN Operator

IN operator checks to see if the value of the term preceding it is included in that set.

Ex. 5 IN [2,4,6,8,10] is FALSE, 5 IN [2,4..6,8,10] is TRUE

Logical Expressions

NOT

NOT True False


Result False True

OR

OR True False

True True True

26
Satya
© private Solutions.
False True False

AND

AND True False

True True False

False False False

XOR

AND True False

True False True

False True False

Logical Operator Precedence

 Sub expression or Terms  ( ) [ ] . ::


 Unary + - NOT
 Multiplicative  * / DIV MOD AND
 Additive  + - OR XOR
 Relational  < <= = >= ><> IN

Compound or Conditional Statements

This statement enhances the capabilities of the conditional statement. Remember


that the conditional statement can only run one statement if the condition is found True.

If Statement
Syntax: IF <Boolean expression> THEN <statement>

Ex. IF Amount < 0 THEN Amount := -Amount;

IF-THEN-ELSE Statem ent

27
Satya
© private Solutions.
Syntax: IF <Boolean expression> THEN [BEGIN]
<Statement 1> {; <statement 2>}
[END] ELSE [BEGIN]
<Statement 1> {; <statement 2>}
[END];

Ex. IF Quantity <> 0 THEN [BEGIN]



UnitPrice := TotalPrice / Quantity

[END] ELSE [BEGIN]

UnitPrice := 0;

[END];

Exit Statement
The EXIT statement is used to stop the execution of a trigger.

Syntax: <Boolean Expression>or<statement>


EXIT;

Ex. IF Quantity = 0 THEN


EXIT;
UnitPrice := TotalPrice / Quantity;

Nested IF Statem ent


Syntax: IF <Boolean expression> THEN [BEGIN]
<Statement 1> {; <statement 2>}
IF <Boolean expression> THEN [BEGIN]
<Statement 1> {; <statement 2>}
[END];
[END];

Ex. IF Amount <> 0 THEN


IF Amount > 0 THEN
Sales := Sales + Amount
ELSE IF Reason = Reason::Return THEN
IF ReasonForReturn = ReasonForReturn::Defective THEN
Refund := Refund + Amount
ELSE
Credits := Credits + Amount
28
Satya
© private Solutions.
ELSE
Sales := Sales - Amount;

Block of Comm ents

{The second syntax is a block of comments. If a start brace ( { ) is inserted in the code,
the compiler will ignore it and everything following it until the matching end brace ( } )
is found.}

Arrays

An array is still a variable. The only difference between calling a simple variable and a
complex one is adding the element index.

 Declaring array variable: Normal variable Properties, in the Dimensions specify


the index expression value. Like 4 or 5 or 8 etc..,
 To declare 2 Dimensions array define using semi colon. Like 2;2 or 3;3.

Syntax: <identifier>[<index expression>{,<index expression>}]

Ex. SaleAmount[5] := 0;

If you want to clear or reset the array use the CLEAR Function.

Syntax: CLEAR(<variable>)

Ex. CLEAR(SaleAmount);

ARRAYLEN Function
It gives the length of the array.

Syntax: ARRAYLEN(<array variable>)

Ex. ARRAYLEN(SaleAmount);

Repetitive or Control Statements

A repetitive statement is a statement that allows you to execute one or more other
statements multiple times. A repetitive statement is often called a "loop", because when
the execution reaches the end of the repetitive statement, it loops back to the beginning
of the repetitive statement.

FOR…TO Statement
29
Satya
© private Solutions.
Syntax: FOR <control variable> := <start value> TO <end value> DO [BEGIN]
<statement1>{;<statement2>}
[END];

Ex. FOR idx := 4 TO 8 DO BEGIN


Total := Total + 2.5;
END;
Note: In the above statement idx value is automatically incremented by 1.

FOR…DOWNTO Statem ent


Syntax: FOR <control variable> := <start value> DOWNTO <end value> DO
[BEGIN]
<statement1>{;<statement2>}
[END];

Ex. FOR i := 5 DOWNTO 2 DO


MESSAGE('%1',i);
Note: In the above statement idx value is automatically decremented by 1.
WHILE…DO Statement
Syntax: WHILE <Boolean expression> DO [BEGIN]
<statement1>{;<statement2>}
[END];

Ex. WHILE i < 5 DO BEGIN


i := i+1;
MESSAGE('%1',i);
END;

REPEAT…UNTIL Statem ent

Syntax: REPEAT <statement> { ; <statement> } UNTIL <Boolean expression>

Ex. REPEAT
i := i + 1;
MESSAGE('%1',i);
UNTIL i = 5;
There are several differences between the REPEAT and WHILE statements:

 First, there can be more than one statement between the REPEAT and the
UNTIL, even if no BEGIN and END is used.

30
Satya
© private Solutions.
 Secondly, the Boolean expression is not evaluated until the end, after the
statements have already been executed once.
 And third, when the Boolean expression is evaluated, it loops back to the
beginning if the expression evaluates to False and terminates the loop if the
expression evaluates to True.

WITH Statem ent

WITH is used for just simplify the code.

For example you want to get the customer details then you get those details like..,
Customer.Name := Txt[1];
Customer.Address := Txt[2];
Customer.City := Txt[3];
Customer.Contact := Txt[4];
Customer."Phone No." := Txt[5];
Here every time we use “customer.” record variable name. So to reduce this we use
WITH statement.

Syntax: WITH <record variable> DO <statement>

Ex. WITH Customer DO BEGIN


Name := Txt[1];
Address := Txt[2];
City := Txt[3];
Contact := Txt[4];
"Phone No." := Txt[5];
END;

Case Statem ent


Syntax: CASE <expression> OF
<value set 1> : <statement 1>;
<value set 2> : <statement 2>;
...
<value set n> : <statement n>;
[ELSE <statement n+1>]
END;
Ex. Int1 := 2;
CASE Int1 OF
1:MESSAGE('This is 1');
2:MESSAGE('This is 2');

31
Satya
© private Solutions.
3:MESSAGE('This is 3');
END;
Output: This is 2

Function

Use of Random and Randomize

 If we use random function, it gives random number b/w 1 and given maximum
number in random function.
 Random function always gives same value as output for every execution.
 If we use randomize function without parameters, before random function.
 Then it gives different random number for every execution.
 Ex. RANDOMIZE();
i := RANDOM(125);
MESSAGE('%1',i);

32
Satya
© private Solutions.
Advanced
Complex Data Type

Complex data types are those that have more than just a value and operators.

 Complex data types, however, have properties or methods along with a value (or
values).
 For instance, a form data type has a value (the form object), but it also has
methods like the RUN method that displays the form to the user.
 It also has properties like LOOKUPMODE.
 Complex datatypes are BLOB, CodeUnit, Dataport, Dialog, etc..,

Using the Objects You Know

All of these data types have one method in common, the RUN method.

Using the code unit variable


 Create a variable of type codeunit.
 In the Subtype field, put the name or ID of the codeunit you want to access.
 You can call the RUN method of the codeunit or a function within the codeunit.
 You must pass in the ID of the codeunit that you wish to run.
 You can pass a record variable into the RUN method if the OnRun trigger will
accept one.
 Ex. CodeunitVariable.RUN; //No record variable
CodeunitVariable.RUN(Rec); //With record variable
X := CodeunitVariable.AddTen(9001); //Calling a function

Using the CODEUNIT.RUN Function

By using the CODEUNIT.RUN function to create and run a codeunit, you dynamically
create an instance of a codeunit based on the ID.

Accessing CodeUnit

 Example
CODEUNIT.RUN(393); //No record variable
CODEUNIT.RUN(393, Rec); //With record variable

33
Satya
© private Solutions.
Accessing Forms

Forms can be run in much the same way as Codeunits, with a form variable or
using the FORM.RUN function. However, you can also run them modally using the
RUNMODAL method instead of RUN.

Examples (running a form non-modally)


CustomerCardVariable.RUN;
FORM.RUN(FORM::“Customer Card”, CustRec);

Examples (running a form modally)


By running a form modally, you can check what button the user pushed to close the
form. In this example, the customer list form is run modally and if the user pushed the
OK button, a variable is changed.

IF FORM.RUNMODAL(22,CustRec) = Action::LookupOK THEN


CustNo := CustRec.”No.”;

Accessing Reports and Dataports

As with forms, reports and dataports can be run with a variable, without a variable,
modally or non-modally.

Examples
ReportVariable.RUN;
REPORT.RUN(Report ID);
ReportVariable.RUNMODAL;

DataportVariable.RUN;
DATAPORT.RUN(Dataport ID);
DataportVariable.RUNMODAL;

Retrieving a Record

GET

 This method uses the primary key values to find the matching record in the
database. Once the record is found, it fetch data from the database.
 The GET method ignores the record set and goes directly to the table to retrieve
the record.
 Ex. Customer.GET('50000'); //No. is the primary key field
Customer.GET(CustNo); //Using a variable
Customer.GET(Rec.”No.”); //Using a field from another Record Variable

FIND
34
Satya
© private Solutions.
 It is used to go to a specific record in a record set.
 Usually this function is just used to go to the first or the last record within a
record set, but you can use it for searching as well.
 GET only retrieve the data for current filter.
 Additionally, FIND can be instructed to look for records where the key value is
equal to, larger than or smaller than the search string.
o Find(‘+’) goes to the bottom of the table and sets the record variable to the
last record.
o Find(‘-’) goes to the top of the table and sets the record variable to the first
record.
o Find(‘=><’)

NEXT

Once you have retrieved a record from the database, you may want to retrieve the very
next record or a previous record. Then NEXT method will be useful.

 <recordVariable>.next  goes to next record.


 <recordVariable>.next(2)  goes after the 2nd record, from the current record.
 <recordVariable>.next(-2)  goes before the 2nd record, from the current
record.

Modifying the Database Record

INSERT
If you want to insert a record to the table through the code then we use insert
function. If you want to run the OnInsert trigger of the table during the insert, you must
pass TRUE into the function.

Syntax: <recordVariable>.<TableVariable> := <value>;


<recordVariable>.insert[(true)];

Example: EmpList."No." := 'SN';


EmpList."First Name" := 'Satya';
EmpList.INSERT;//EmpList.INSERT(TRUE);
Note: Passing FALSE and without passing parameter also gives same output.

MODIFY

If you want to update the record then we use this function.

Syntax: <recordVariable>.<TableVariable> := <value>;


<recordVariable>.modify[(true)];
35
Satya
© private Solutions.
Example: EmpList.GET('AL');
EmpList."Last Name" := 'Lakshmi';
EmpList.MODIFY;
DELETE
If you want to delete the record then we use this function.

Syntax: <recordVariable>.<TableVariable> := <value>;


<recordVariable>.delete[(true)];

Example: EmpList.GET('AL');//EmpList."No." := 'AL';


EmpList.DELETE;
RENAME
The RENAME method can be used to change the primary key fields of a record in
the database. Like the GET method, you must pass the new primary key values as
parameters to this function. the change is propagated to all related tables. The
OnRename trigger is always called.

Syntax: <recordVariable>.<TableVariable> := <value>;


<recordVariable>.rename;

Example: EmpList.GET('RR');
EmpList.”FIRST NAME” := ‘Rakesh’;
EmpList.RENAME;

Defining a Record Set

A set of records can be referred to by the term Record Set. A Record Set is defined
by the Key and Filters that the record variable has been assigned. This is sometimes
called a “View”. For this use the method functions SETCURRENTKEY, SETRANGE
or SETFILTER.

SETCURRENTKEY
The SETCURRENTKEY method assigns a new key to a record variable.

 All record variables use the primary key by default.


 If you would like to sort the records in a different way, you must use this method
function.
 What you pass into this function is a list of fields. The function then searches the
table’s keys to find a matching key.

36
Satya
© private Solutions.
 A run-time error occurs if the function cannot find a Key that contains all the
fields specified in the order specified.

Syntax: <recordVariable>.SETCURRENTKEY(<variable name>);


Example: Customer.SETCURRENTKEY("Search Name");
Customer.SETCURRENTKEY("No."); //resets to the primary key.
SETRANGE
The SETRANGE method provides a quick way to set a simple filter on a field. If
you call this function with a field that already has a filter, the system removes that filter
before it sets the new one.

Syntax: <recordVariable>.SETRANGE(<variable name>,From value, To value);

Example: Customer.SETRANGE("No.",'10000','90000');

SETFILTER

 The SETFILTER method provides a way to set a complex filter on a field.


 If you call this function with a field that already has a filter, the system removes
that filter before it sets the new one.
 You can construct filters using these operators: (), .., &, |, <, <=, >, <>, *.

Example: Customer.SETFILTER("No.", '10000|20000|30000');

Temporary tables

Temporary tables allow you to minimize the impact on the server in two main areas

 Reducing the calls to the server and in allowing you to create records that may
not yet exist on the server.
o Depending on the requirement report may need to read from the table
many different times
o By reading the data once from the server and storing the data in a
temporary table we are able to minimize the impact on the server as well
as the amount of network traffic.
 working with dimensions there may be times when you want to create data
o The processing is taking place on the client the impact on the server is
minimized.

37
Satya
© private Solutions.

You might also like