Chapter 3: Introduction To C/Al Programming: Training Objectives

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Chapter 3: Introduction to C/AL Programming

CHAPTER 3: INTRODUCTION TO C/AL


PROGRAMMING
Training Objectives
In this chapter, you learn about:

• The C/AL Programming Unit


• C/AL
• Accessing C/AL

Page 145
Microsoft Navision Development I − C/SIDE Introduction

C/AL Programming
This section discusses Microsoft® Business Solutions−Navision® programming
language and our development environment. You become familiar with creating
variables using the Pascal-based language and Microsoft Navision's built in
functions to run simple code. This provides a good base in preparation for
attending the Solution Developer class. The following topics are presented in this
section:

• Chapter 4: Intrinsic Data Types Training


• Chapter 5: Identifiers and Variables
• Chapter 6: Assignment Statement
• Chapter 7: Simple Expressions, Terms, and Operators
• Chapter 8: Numeric Expressions
• Chapter 9: Logical and Relational Expressions
• Chapter 10: The IF and EXIT Statements
• Chapter 11: Compound Statements and Comments
• Chapter 12: Arrays
• Chapter 13: Repetitive Statements
• Chapter 14: Other Statements
• Chapter 15: Functions
• Chapter 16: Using Intrinsic C/AL Functions
• Chapter 17: Creating Your Own Functions

C/AL
Definition
C/AL (Client Application Language) is the programming language used in the
Client / Server Integrated Development Environment (C/SIDE) included with
Microsoft Navision.

What is it used for?


There are many purposes for which you can use a computer programming
language. However, many of these uses are already handled for you by using the
standard C/SIDE objects. For example:

• Data presentation is handled through the form objects and report


objects.

Page 146
Chapter 3: Introduction to C/AL Programming

• Data acquisition is mainly handled through form and dataport


objects.
• Data storage and organization is handled by the table objects in
conjunction with the built-in Database Management System
(DBMS).

In C/SIDE, the main purpose of the programming language is data manipulation.


Through C/AL, you can create business rules to insure that the data stored in the
tables are meaningful and consistent with the way your customer does business.
You can add new data or transfer data from one table to another (for example, a
journal to a ledger). If data from multiple tables need to be combined onto one
report or displayed on one form, you probably need to program this.

Another purpose of C/AL is to control the execution of the various C/SIDE


objects. With C/AL you are able to coordinate them in a way that meets the
business needs of your customer.

Where is it Used?
C/AL programming can be found in any Microsoft Navision application object.
In fact the codeunit application object is used only for programming. If you go
into the Object Designer, press the Codeunit button, select a codeunit and press
the Design button, you immediately see the C/AL editor and programming
language statements (also known as "C/AL statements", or just "code").

Other objects can have C/AL statements as well, although they do not always
have them. This code is found in "triggers" within the object. Please start
Microsoft Navision and follow along as we explore.

Page 147
Microsoft Navision Development I − C/SIDE Introduction

Accessing C/AL
Start the Object Designer
To start the Object Designer, select the Tools option from the Menu Bar and then
select Object Designer from the list that drops down.

View Codeunit Objects


To view codeunit Objects, press the Codeunit Option button on the Object
Designer form.

Codeunit
Option Button

Design Command Button Scroll


Bar

Page 148
Chapter 3: Introduction to C/AL Programming

Select an Object
Using the picture above as a guide, scroll through the codeunits to find codeunit
number 358, "DateFilter-Calc", then click on it. Or, if you prefer, use the up and
down arrows on your keyboard to move to codeunit 358.
Look at the C/AL Code
Using the below picture as a guide, press Design once codeunit 358 −
"DateFilter-Calc" has been selected. The C/AL Editor window appeared, looking
something like this:

Each shaded bar is called a "trigger." The C/AL code that you may see listed
below the shaded bar is the "trigger code" for that trigger. If there is no C/AL
code between one trigger and the next trigger, then that trigger is said to be
empty. For example, there is no trigger code between the "OnRun" trigger and
the "CreateFiscalYearFilter" trigger, therefore the "OnRun" trigger is empty.

There are three kinds of triggers. The first is the "Documentation Trigger". This
is not really a trigger and no code in this trigger is run. Instead, you can use the
Documentation trigger to write any sort of documentation you want for this
object. Many people use this space to document their modifications to standard
objects. Every object has a Documentation trigger.

The second kind of trigger is an "Event Trigger". The name of these triggers
always starts with "On." The C/AL code in an event trigger is executed when the
named event occurs. For example, the code in the "OnRun" event trigger is
executed whenever this codeunit object is run. In this case, since there is no
trigger code, nothing would happen. Each object has its own set of predefined
event triggers that can be programmed.

Page 149
Microsoft Navision Development I − C/SIDE Introduction

The third kind of trigger shown here is a "Function Trigger". These triggers are
created whenever you create a "function" in an object. The C/AL code in this
function trigger is executed whenever the function is "called." You learn more
about creating and calling functions in another section. You learn more about
event triggers in your Solution Developer II class.

Closing an Object
After looking at the "CreateFiscalYearFilter" codeunit, close the C/AL Editor
window by clicking the Close Box or by pressing the ESC key. If you have not
changed anything, the object is closed and you can continue. If you have changed
something, the following box pops up:

For now, press the No button (or press the ALT +N key) to discard any changes
you may have made in order to exit the C/AL Editor and close the object.
Look at C/AL Code in a Table Object
Press the Table button in the Object Designer window. Scroll through the Object
Designer window and select Table 18 (the Item table). Press the Design button to
open the Table Designer window. Note that this is not the C/AL Editor. Instead,
it is a list of the fields that make up the table definition. You learn more about
these later.

To get to the C/AL Code, you must open the C/AL Editor. To do this, review the
Tool Bar:

C/AL Code Editor

Press the C/AL button. As an alternative, you can press the F9 key. Once you are
in the C/AL Editor, note that there are numerous triggers in this Table Object.
Most of them are empty, but several of them contain C/AL code.

Most of these are in triggers labeled with a field name followed by "OnValidate."
These are event triggers and the code is triggered by the "event" of the user
completing the entry of that field. You learn more about this and the other
triggers discussed here in your Solution Developer class. For now, just take a
look around and then close the C/AL Editor window. Once it is closed, close the
Table Designer, again without saving any changes you may have accidentally
made.

Page 150
Chapter 3: Introduction to C/AL Programming

Test Your Knowledge


Terminology

1. What is the programming language of C/SIDE called?

2. List three or more uses of programming code.

3. Where can programming language statements be found?

4. What do you use to modify code in an object?

5. List the three basic types of triggers.

6. What is the key you press to view or modify code in an object (other
than a codeunit object)?

Practical
Use the Object Designer to look at the code in Form Object 39.

Use the Object Designer to look at the code in Report Object 324. Note that the
code is different depending upon which line (also called a "DataItem") is selected
in the Report Designer. See what happens when you select the line following the
last line in the Report Designer before starting the code window.

Page 151
Microsoft Navision Development I − C/SIDE Introduction

Quick Interaction: Lessons Learned


Take a moment to write down three Key Points you have learned from this
chapter:

1.

2.

3.

Page 152

You might also like