Top Banner
Chapter 8: Dimensions 8-1 CHAPTER 8: DIMENSIONS Objectives The objectives are: Describe Global, Shortcut and Budget dimension types and their functions. List the basic rules of Dimension Setup. List functions that help populate the dimension tables. Implement dimensions on the master record level. Describe the flow of dimension values for posted documents. Describe how shortcut dimension fields are used. Introduction Dimensions are used to control how analysis occurs. A two-dimensional analysis can be analysis of sales for a geographic area. However, by using more than two dimensions when creating an entry, a more complex analysis can be performed. For example an analysis of sales for each sales campaign for each customer group in each geographic area can be created. Dimensions are values added to an entry to act as markers for the program, which allows entries with similar dimension values to be grouped for analysis purposes. Many different types of entries in the program can have dimensions, including the following: Master records Transaction document headers and lines Journal lines Ledger entries Posted documents and their lines Each dimension can have an unlimited number of dimension values. For example, a dimension called Department can have dimension values of Sales, Administration, Purchasing, and so on. Users define and tailor these dimensions and values to their company's needs. Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
30

Na2009 enus devii_08

Nov 07, 2014

Download

Technology

Peter Muscat

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Na2009 enus devii_08

Chapter 8: Dimensions

8-1

CHAPTER 8: DIMENSIONS Objectives

The objectives are:

• Describe Global, Shortcut and Budget dimension types and their functions.

• List the basic rules of Dimension Setup. • List functions that help populate the dimension tables. • Implement dimensions on the master record level. • Describe the flow of dimension values for posted documents. • Describe how shortcut dimension fields are used.

Introduction Dimensions are used to control how analysis occurs. A two-dimensional analysis can be analysis of sales for a geographic area. However, by using more than two dimensions when creating an entry, a more complex analysis can be performed. For example an analysis of sales for each sales campaign for each customer group in each geographic area can be created.

Dimensions are values added to an entry to act as markers for the program, which allows entries with similar dimension values to be grouped for analysis purposes. Many different types of entries in the program can have dimensions, including the following:

• Master records • Transaction document headers and lines • Journal lines • Ledger entries • Posted documents and their lines

Each dimension can have an unlimited number of dimension values. For example, a dimension called Department can have dimension values of Sales, Administration, Purchasing, and so on. Users define and tailor these dimensions and values to their company's needs.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 2: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-2

Prerequisites Dimensions will play a key role in the development of the Seminar Management module.

Dimension Types

There are three types of dimensions:

• Global • Shortcut • Budget

Global: When setting up dimensions in the G/L Setup, two of them can be global dimensions. These dimension types can be used throughout the program as a filter for G/L entries and on reports, account schedules, and batch jobs. Global dimensions are the only dimensions that are stored as part of the tables they describe. For instance, the G/L Entry table has two fields for the global dimensions.

Shortcut: Enter shortcut dimensions on journal and document lines. These lines have eight fields that are designated for dimensions. The first two are always the global dimensions, but the remaining six can be selected from those set up as shortcut dimensions in the G/L Setup. Dimensions that are not set up as shortcut dimensions can also be specified, but these must be set up in a separate Dimensions window for the header or line. Shortcut dimensions that are not set up as global dimensions are not stored as actual fields of the tables they describe. Instead, they are stored in a separate table.

Budget: Four dimensions can be defined for each budget.

When a global, shortcut, or budget dimension is set up, the program automatically renames all fields that use the dimension type with the code caption specified when the dimension is setup.

Where dimensions are stored depends on the type of entry. The following table shows different tables that contain dimensions with the types of entries with which they are associated.

Dimension Table Type of Entry

352 Default Dimension Master records

355 Ledger Entry Dimension Ledger entries

356 Journal Line Dimension Journal lines

357 Document Dimension Document headers and lines

358 Production Document Dimension

Production orders, lines, and components

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 3: Na2009 enus devii_08

Chapter 8: Dimensions

8-3

Dimension Table Type of Entry

359 Posted Document Dimension Posted document headers and lines

361 G/L Budget Dimension Budget entries

Dimension Setup

Dimensions are set up under the Administration area in the Departments, under Administration\Application Setup\Financial Management\Dimensions. For each dimension, a code, a name, a code caption, and a filter caption are defined.

FIGURE 8.1 DIMENSIONS PAGE

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 4: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-4

Global dimensions and shortcut dimensions are set up under General Ledger Setup, under the Dimensions FastTab. For the standard CRONUS International Ltd. demonstration database, the global dimensions have been set to the "Department" and "Project" dimensions, as shown in the following illustration.

FIGURE 8.2 GENERAL LEDGER SETUP - DIMENSIONS FASTTAB

Global Dimensions 1 and 2, if set up in the system, will now link to these two dimensions. For example, the Global Dimension 1 Code field in the Customer table will now have a caption of Department Code, because this dimension is set up as the Global Dimension 1 Code in General Ledger Setup.

Code Walkthrough - Dimension Management Codeunit Codeunit DimensionManagement (408) contains functions that help populate the dimension tables.

Dimensions are stored in separate tables, and are identified by the table ID of the table that the dimension describes. The TypeToTableID functions in the DimensionsManagement codeunit are used to determine the correct table ID to store in the dimension value tables. They take one option parameter and then return the table ID of the table related to that parameter. For example, if "G/L Account" is passed in, the function returns table ID 15. These functions are used, through other functions, to populate the dimension tables where the table ID is needed. Without them, it is be necessary to write a similar case statement every time the table ID of an option field is needed.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 5: Na2009 enus devii_08

Chapter 8: Dimensions

8-5

Notice the SetupObjectNoList function. This function sets a temporary record object with a list of tables that use dimensions. This function is used in table 352, in the OnLookup trigger of the Table ID field. To include the master tables, the SetupObjectNoList function must be modified.

Other functions of note in this codeunit are ValidateDimValueCode and SaveDefaultDim. ValidateDimValueCode takes in two parameters, the field number and the dimension value. The function checks to see that the dimension is valid, and returns an error if it is not. SaveDefaultDim saves the dimension in the default dimension table.

In general, there are functions that correspond to each type of Dimension table for getting default dimensions, as well as updating, saving, deleting, inserting, and validating the consistency and combinations of dimensions.

Dimensions in Master Tables, Pages, and Codeunits The purpose of implementing dimensions on the master record level is to enable analysis of transactions that involve records from the master tables.

Solution Analysis

The dimension values flow from the master records into the transactions in which they are involved. For example, the ledger entries that are a result of posting a transaction for a customer will have the same value for Department Code as that customer.

In accordance with Microsoft Dynamics NAV standards, many master records are associated with default dimensions, including two Global Dimensions. The master record dimensions flow to the transactions in which the master data is used. These document dimensions eventually flow to the ledger entries and posted document dimensions.

Solution Design - DimensionManagement Codeunit

Many enhancements to a system include creating new master tables. Enabling dimensions for new master tables requires changes to the master tables and pages and codeunits that manage dimensions.

Entries for master records are included in the Default Dimension table (352). This table and the DimensionManagement codeunit must be modified so that they accept entries from the master tables.

When the user creates a new record in a master table, the program inserts or updates the default dimensions. Likewise, when the user deletes a record, the program automatically deletes the associated dimensions.

When the user enters a value in a dimension field, theValidateShortcutDimCode function is used to validate the entry. The DimensionManagement codeunit has a function called ValidateDimValueCode that helps with this.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 6: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-6

When an option field is part of a link to a master table, the DimensionManagement codeunit needs to know how to translate option values to table IDs. This is done through a number of functions, all starting with "TypeToTableID." For example, the function TypeToTableID1 function translates a specific set of option values into table IDs that are then entered into the TableID field of the appropriate dimension table. The option values of the Type parameter are the same as the option values of the field that is passed into the function.

The following will likely have to be modified to support the use of dimensions within a new enhancement:

• The SetupObjectNoList function includes the master tables. The SetupObjectNoList function must be expanded to include every master table.

• The TableIDArray variable dimension value must be expanded to include the new master table. The value for the expanded TableIDArray element variable must be set to the table ID of the new master table, much like the existing values are set for standard Microsoft Dynamics NAV master tables.

Solution Design - Global Dimension Fields

The master table has fields defined where Global Dimensions 1 and 2 are stored. A fast and proper way to create these fields is to copy them from a core Microsoft Dynamics NAV master table, such as the Customer table.

There are three setup steps in the master table:

1. Each field must be defined with the proper table relationship to the Dimension Value table, so that the Global Dimension No. field is a filter for the value 1 or 2. This is to correspond to Global Dimension 1 and Global Dimension 2, respectively.

2. The master table must be expanded to include a function that validates the dimension, named ValidateShortcutDimCode. Use the OnValidate trigger of the new Global Dimension fields to call the ValidateShortcutDimCode function.

3. The table triggers must have proper function calls to the DimensionManagement codeunit to update the dimension values when records are inserted into and deleted from the master table.

These function calls drive the dimension values related to master tables. The function calls manage the synchronization of the actual fields in the master table and their corresponding records in the Dimension Value table.

To examine these function calls in an existing master table, open the Customer table (18) in the Object Designer. Search the C/AL editor for all instances of the DimMgt variable.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 7: Na2009 enus devii_08

Chapter 8: Dimensions

8-7

Solution Design - User Interface

Access to Dimensions is added to the Card page under the Related Information menu. Use the shortcut key of Ctrl+Shift+D to open the Default Dimensions page that is related to the current master record.

FIGURE 8.3 THE DIMENSIONS SELECTION ON THE RELATED INFORMATION MENU ON THE CUSTOMER CARD PAGE

Dimensions in Documents Dimension values that are related to master records flow into each transaction in which they are involved. For example, when a customer is selected on a sales order, that customer's dimensions are copied from the master record into the document dimension. Similarly, when an Item, or a Resource, or a G/L Account (remember the TypeToTableID functions) is entered into an order detail, its dimension values will flow into the document dimension on the order's line records.

When these documents are posted, their dimension values flow into the journal tables, the ledger entry tables and the posted document tables.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 8: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-8

Solution Design - Shortcut Dimension Fields

Transaction documents and lines use shortcut dimension codes. Enabling dimensions in transaction documents means setting up the shortcut dimension codes for the header and lines, and writing code so that the dimensions from the seminar, seminar room, and instructor chosen for the seminar registration are also included. This also enables dimensions on the posted seminar registration tables and pages.

Just as is done with relating dimensions to master records, the document tables must be expanded with the correct dimension fields. Also, the code in the table needs to be expanded to include the logic used to manage dimension values.

To see how this works in the standard application, look at how dimensions are handled in the Sales Header table (36) and the Sales Line table (37). Both tables have a Shortcut Dimension 1 Code field and a Shortcut Dimension 2 Code field.

In addition to the fields, the document tables need to include calls to the appropriate functions in the DimensionMangement codeunit. Just as with the master table, document tables require the following added to the C/AL code behind the table:

• The table must be expanded to include a function that validates the dimension, called ValidateShortcutDimCode. Call this function from the OnValidate trigger of the Shortcut Dimension Fields.

• The table's OnInsert and OnDelete triggers must have calls to the DimensionManagement codeunit to update the dimension values when records are inserted into and deleted from the master table.

From the OnValidate trigger of the field that controls which dimensions are attached to the documents, there should be a call to the CreateDim function. This will attach the dimensions to the document from the associated master record. This is the same model as the logic which is executed in the Sales Header table when the Bill-to Customer is changed.

GUI Design

Standard Microsoft Dynamics® NAV allows for up to eight shortcut dimensions, two of which are reserved as Global Dimensions. The remaining six shortcut dimensions can be entered directly into the user interface in selected areas.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 9: Na2009 enus devii_08

Chapter 8: Dimensions

8-9

One example is the Sales Order, where values can be entered into the shortcut dimension fields directly. In addition to the two global shortcut dimension fields, there are controls to enter values directly into the remaining six shortcut dimension fields. These fields are not physically present as fields in the underlying table, but are displayed on the page from an associated table.

FIGURE 8.4 CUSTOMIZE LINES FOR THE LINE'S FASTTAB OF THE SALES ORDER PAGE

NOTE: There are a series of dimension fields available, ranging from the Department Code to Shortcut Dimension 8 Code. These dimension fields are the same as those set up as shortcut dimensions in General Ledger Setup.

To see how this works in standard Microsoft Dynamics NAV, inspect the object for the Sales Order Subform page (46). The shortcut dimension fields are located at the bottom of this page designer. The code in the page triggers function calls to the dimension functions in the table, which in turn calls functions in the Dimension Management codeunit. There is additional code to display the right caption, and code to validate the dimension when entered into the page.

NOTE: The SourceExpr properties of the shortcut dimension fields point to the two shortcut dimension fields in the underlying table and to the ShortcutDimCode variable, which is set by the function calls in the page and validation triggers.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 10: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-10

Dimensions in Posting To enable the transfer of dimensions in the posting process, shortcut dimension fields are added to the journal and ledger entry tables. Then code in the posting routines transfer the dimensions from document headers and lines to the posted document headers and lines in the appropriate journal and ledger entry tables.

For dimensions that are not set up as global dimensions, the system will create values in the dimension value tables related to the posted documents and the ledger entries.

Managing the flow of dimensions from unposted documents to journal lines, ledger entries and posted documents is done by a number of function calls in the posting routines. The best way to understand how this is done is to create a transaction and to debug the posting process, and focus on the dimension logic.

The DimensionManagement codeunit has a number of functions that transfer dimension values from one place to another, and each function has its own specific purpose. For example, there is a function called CopyDocDimToJnlLineDim that copies the dimensions that are entered for the unposted document into the journal line. Then during the posting routine for that journal line, there will be another function call to the DimensionManagement codeunit to transfer the dimension from the journal line into the ledger entry.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 11: Na2009 enus devii_08

Chapter 8: Dimensions

8-11

Lab 8.1- Using The Debugger Interface To View The Dimension Process

Dimensions have been created. Now use the debugger interface to view the internal processes of a specific instance in the dimension process.

Scenario

The debugger interface lab uses dimensions to illustrate a scenario in which the debugger is used to understand a process in Microsoft Dynamics NAV 2009. This lab is intended as an instructor-led, walk-through that students can follow along if they wish.

The C/SIDE debugger runs only from within the Classic client, the client from which all C/AL development is done.

This lab uses the standard Microsoft Dynamics NAV CRONUS International Ltd. company dimension setup. For more information about debugging in the RoleTailored client, see the the Microsoft Dynamics NAV 2009 Developer and IT Pro Help.

Challenge Yourself!

Use the debugger interface to view the dimension process.

Define Dimensions

1. To open the following Dimensions screen: o Open the Financial Management menu o Select the Setup option o Select the Dimensions option

FIGURE 8.5 FINANCIAL MANAGEMENT MENU TO SETUP OPTION TO DIMENSIONS

2. The following fields are used: o Code, to identify the dimension o Name, to describe the dimension

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 12: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-12

o Code Caption, the caption used for shortcut dimensions o Filter Caption, used when dimensions are part of a filter

General Ledger Setup

1. From the Financial Management menu, select the Setup option. 2. Select the General Ledger Setup. 3. Shortcut dimensions are defined on the Dimensions tab of this form,

as show in the next image.

FIGURE 8.6 GENERAL LEDGER SETUP / DIMENSIONS

NOTE: Department and Project are selected as the global dimensions (the same as the first two shortcut dimensions).

Dimensions In Master Records

To illustrate dimensions in master records, look at dimensions as they are used for the Customer table.

• The first task is to prepare the Customer Card form to display the global dimension fields, create a new customer, and assign dimensions to the customer.

• The debugger interface will be used to observe how the code is processed when a dimension is assigned to the customer.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 13: Na2009 enus devii_08

Chapter 8: Dimensions

8-13

Design Walkthrough

The Customer table, like any other master table in Microsoft Dynamics NAV, has two fields to store global dimensions, as shown in the following image.

FIGURE 8.7 TABLE 18 CUSTOMER - TABLE DESIGNER

• Both fields have a table relationship to the Code field of the Dimension Value table.

• Global Dimension No. equals 1 for the Global Dimension 1 Code field and it equals 2 for the Global Dimension 2 Code field.

• The CaptionClass property of the field (which is set to '1,1,1' for the Global Dimension 1 Code field, and to '1,1,2' for the Global Dimension 2 Code field) determines the caption of the field when it is displayed by another object. The code that translates these captions is in Codunit1.

The OnValidate trigger for both of the dimension fields has a call to the ValidateShortcutDimCode function of the Customer table. This function validates the dimension value, and saves the dimension value into the Default Dimension table. This function validates the dimension value, and saves the dimension value into the Default Dimension table.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 14: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-14

The Default Dimension table is where all dimension values for maser records are stored. Both the validation and save tasks are done in functions of the DimensionManagement codeunit (408), as shown in the following image.

FIGURE 8.8 VALIDATION AND SAVE DONE IN DIMENSION MANAGEMENT CODEUNIT 408

The ValidateDimValueCode function checks to see if the selected dimension is indeed the correct global dimension, that this dimension can indeed be selected for this table, and that the value itself is a permitted value for the dimension.

The SaveDefaultDim function saves the dimension into the Default Dimension table, including a link to the current master record, by way of table ID and key value.

The purpose of the Default Dimension table is that in every dimension it can be accessed from the same source. The purpose of having the dimension in its own field in the master tables (at least for up to two global dimensions) is to provide quicker access without retrieving the dimension value from another table.

Customer Card

Neither of the global dimension fields is displayed on the default Customer Card form. To be able to debug the process, the fields must be added to the form.

1. Open the Customer Card form in design mode. 2. Add the two global dimension fields to the Communication tab. The

only purpose of this change is to allow direct entry of a dimension value and in turn allow the tracing of the resulting processing using the debugger.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 15: Na2009 enus devii_08

Chapter 8: Dimensions

8-15

The next image shows the Customer Card in design, with the two added dimension fields on the Communication tab.

FIGURE 8.9 CUSTOMER CARD IN DESIGN WITH ADDED DIMENSION FIELDS ON THE COMMUNICATION TAB

NOTE: The field name and the caption are different from each other for both fields.

The field names are Global Dimension 1 Code and Global Dimension 2 Code. Their captions are Department Code and Project Code. If returning to the Dimensions form and changing the Code Caption value of one field to the Something Code, then this becomes the caption of the associated fields in the field menu.

Create New Customer

To illustrate, begin by creating a new customer.

1. Open the customer card from the Sales option in the Sales & Marketing menu.

2. Click F3 and enter a new customer. 3. Ensure that this new customer has valid posting groups so that it can

be used when a new order is created later in this chapter.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 16: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-16

The next few images show the General, Invoicing, and Communication tabs of the new customer:

FIGURE 8.10 GENERAL TAB OF CUSTOMER THE CARD

FIGURE 8.11 INVOICING TAB OF THE CUSTOMER CARD

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 17: Na2009 enus devii_08

Chapter 8: Dimensions

8-17

FIGURE 8.12 COMMUNICATION TAB OF THE CUSTOMER CARD

Debugging Process

The debugger is used to display C/AL code in parallel with the code's interpretation and execution by Microsoft Dynamics NAV. Debugger output is displayed when certain conditions are met. By default, the debugger runs in the background, and only displays with the code reaches a breakpoint. This happens when an error occurs, when a user defined breakpoint is reached, or when Breakpoint on Triggers is turned on when the code enters a new trigger.

1. The debugger is activated from the Debugger section on the Tools menu.

2. When the debugger section is displayed, the current values of the debugger are shown, as in the following image.

FIGURE 8.13 SETTING DEBUGGER TO ACTIVE

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 18: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-18

3. Notice that two debugger settings are available: o Active (Shift+Ctrl+F11) which sets the debugger to run in the

background o Breakpoint on Triggers (Shift+Ctrl+F12) which sets the

debugger to interpret each new trigger as a breakpoint. This option is used when the developer wants to debug the entire process from the start. By default, this option is turned off, and the debugger will break when an error is caused or when the code hits a user-defined breakpoint.

4. Turn on the Breakpoint on Triggers and set the debugger to Active. 5. Return to the Customer card and click in the Department Code

field. 6. Immediately, the debugger opens up in the CaptionClassTranslate

function of codeunit 1. The CaptionClassTranslate function builds the caption for the Global Dimension 1 Code field, based upon the CaptionClass. These values will be looked at closer later in this Lab exercise.

7. Look closely at the Debugger Tool. The following image shows the entire debugger screen, with its most important parts visible.

FIGURE 8.14 THE DEBUGGER SCREEN

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 19: Na2009 enus devii_08

Chapter 8: Dimensions

8-19

8. The Code section of the debugger screen (shown in the following image) is the most prominent area of the debugger screen.

FIGURE 8.15 CODE SECTION OF THE DEBUGGER SCREEN

This is where the C/AL code that is currently being executed is displayed. When viewing the active code window, the yellow arrow points at the line of code that is about to be executed. The code section is where a developer spends most of his or her time, stepping through the code one line at a time, while tracking values.

The purpose of the debugger is to walk through the code and determine if the code is doing what it is supposed to do. If the code is not performing as expected, the debugger helps the developer find exactly where it is failing.

9. The Variables section of the debugger screen (shown in the following image) displays all variables that are currently in scope, listing the name, value and type for each variable. Notice at the bottom of the variables section, there are tabs for Locals, Globals, Text Constants and a tab that displays all variables.

FIGURE 8.16 THE VARIABLES SECTION OF THE DEBUGGER SCREEN

The developer checks values of the variables that are used during code execution, making the variables section the second most frequently visited section of the debugger.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 20: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-20

When variable values change, the values are displayed in red immediately after the line of code is executed. Notice that in the previous image of the debugger's variable section, the Text021 text constant and the CommaPosition variable are displayed in red. This means the line of code just executed modified these values.

The Call Stack section of the debugger screen (shown in the following image) displays the trail of triggers that is being executed. As the code steps deeper into triggers, the system places these triggers on top of the stack.

FIGURE 8.17 THE CALL STACK SECTION OF THE DEBUGGER SCREEN

Notice in the above image that the yellow arrow points at the current trigger (the DimCaptionClassTranslate trigger), which is called from the CaptionClassTranslate trigger.

As the call stack shows the yellow arrow by the DimCaptionClassTranslate function, the code section displays the yellow arrow by the line of code that is about to be executed.

The developer can double-click the triggers in the call stack to display the last line of code that is executed in that trigger, to see how the code got to this point, and how the current trigger is called. The results of double-clicking on the second trigger in the call stack are shown in the following image:

FIGURE 8.18 RESULT OF DOUBLE-CLICKING THE SECOND TRIGGER IN CALL STACK

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 21: Na2009 enus devii_08

Chapter 8: Dimensions

8-21

Double-clicking the triggers in the call stack is a powerful way to investigate how the code is executed up to the current point in code. Notice in the previous image, there is a green arrow next to the second trigger in the call stack, and there is also a green arrow by the line of code in that trigger. This shows how the next trigger is called. As both triggers are in the same object, both are in the same window.

10. The Watch section of the debugger screen can be used to monitor the value of selected variables. To get a variable into the Watch section, it must be pulled in by right-clicking the variable, and then selecting Add Watch, as shown in the next image.

FIGURE 8.19 ADD WATCH SECTION TO THE DEBUGGER SCREEN

In the above image, the GLSetupRead variable is about to be added to the Watch section. Once the variable is in the Watch section, it will remain there until removed by the developer. Even when other objects are debugged, the Watch section will still display the variable along with a message that it is "uninitialized."

As in the Variables section, the Watch section is used to see the value of selected variables. The difference between the Variables section and the Watch section is that the number of variables in the Watch section is completely under the control of the developer during runtime.

The Watch section can be an efficient way to monitor variables because as long as the number of variables in the Watch section is limited, the developer does not have to browse the variable windows for the specific variable wanted. Also, the developer can add a Watch section entry for a local variable and a global variable at the same time, and then monitor his or her values in the same section.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 22: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-22

Following is an example of the Watch section, immediately after the GLSetupRead variable changes in code.

FIGURE 8.20 THE WATCH SECTION AFTER THE GLSETUPREAD VARIABLECHANGED

11. The Output window of the debugger screen reports errors when they happen. This is a redundant action, as the debugger also displays an actual error message. To minimize the Output window and maximize the remaining sections on the debugger screen, resize the screen as shown in the following image, or close the Output window by clicking the X in the corner.

FIGURE 8.21 RESIZE DEBUGGER SCREEN TO MINIMIZE THE OUTPUT SECTION

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 23: Na2009 enus devii_08

Chapter 8: Dimensions

8-23

The preceding image shows the debugger screen with the minimized Output window at the bottom of the screen. Notice that the Watch window still displays the GLSetupRead variable, even though it is now out of scope. Also, the call stack shows three triggers in two objects, and that window menu lists two windows, both of which show C/AL code that is executed in the Code section.

12. Stepping Through The Code. After viewing all the important debugger screen windows, it is now time to actually step through the process. There are three essential ways to execute code in the debugger: o Step Into (F8). The Step Into command enters into the current

line of code. It executes the current line of code and if this is a call to another trigger, it will jump right to that trigger's C/AL code.

o Step Over (Ctrl+F8). The Step Over command executes the current line of code, and then jumps right to the following line of code. If the current line of code is a call to another object that the developer does not need to step through one line at a time, it can "step over" the current line and continue debugging the following lines. This is very useful for avoiding tedious step-by-step processing of functions not of interest at the moment.

o Go (F5). Go pushes the debugger into the background until the next breakpoint, or until the start of a new trigger if the Breakpoint on Triggers is turned on.

13. Setting Breakpoints is a way to make debugging more efficient. Many processes run through large numbers of objects. It can be quite time consuming to step through the code one line at a time. When the area of code is known, and the developer does not want to step through all of the code, a breakpoint can be defined in the area of interest. The developer can then let the debugger run with Breakpoint on Triggers turned off. This action will allow the debugger to run in the background, displaying the code when it reaches the defined breakpoint.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 24: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-24

Breakpoints are set by putting the cursor on the line of code in question and pressing F9, which can be done in one of two ways:

• In the C/AL editor at design time. • In the debugger, when the code is in the object that is currently on

display in the code section.

FIGURE 8.22 SETTING BREAKPOINT WITH F5

The previous image shows a yellow arrow pointing to the current line of code. Note the maroon circle in the margin to the left of the last line of code in the current trigger. The developer is not interested in any of the code in this trigger, and wishes to quickly jump to the last line of code. By setting the breakpoint, and then pressing F5, the debugger is instructed to jump right to the next breakpoint.

A useful debugging strategy is to set a breakpoint immediately after a function call, especially if the developer is not certain what that function call is going to do. This allows the developer to step into the function, see what it is actually going to do, and still have a way to quickly jump back to the original object by pressing F5.

14. Aborting a process. Turning off the debugger and pressing F5 will cause the current debugging process to complete. However, it may be useful at times to abort the current transaction altogether to start a new debugging session with the same data.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 25: Na2009 enus devii_08

Chapter 8: Dimensions

8-25

To abort a debugging process select Stop Debugging (Shift+F5) from the drop-down Debug menu to stop the Debugger and roll back the current transaction.

FIGURE 8.23 ABORT WITH STOP DEBUGGING (SHIFT+F5)

15. Returning to Dimensions. At various sections of the debugger while processing dimensions-related code, it seems that the debugger is continuously going back into the same object. It seems as though some sort of interaction between the debugger and the Classic client is causing an endless loop. It appears that when the debugger gives control back to the Classic client for a split second, such as when starting to process the new dimension value, the debugger activates the Customer card, then jumps back into translating the caption class for the Global Dimension Code fields. The one way to step through the code in a controlled fashion is to set a manual breakpoint, then turn off the debugger, and press F5. This action will return the Customer card form in the Classic client.

16. Setting the Breakpoint. o Open the Customer table in the Object Designer. o Browse to the Global Dimension 1 Code field o Press F9

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 26: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-26

This will open the C/AL editor with the cursor on the OnValidate trigger of this field.

• Put breakpoints on C/AL code of the Global Dimension 1 Code and the Global Dimension 2 Code fields, as shown in the next image.

FIGURE 8.24 SETTING BREAKPOINTS IN THE C/AL CODE OF DIMENSION 1 CODE AND DIMENSION 2 CODE FIELDS

• Now turn the debugger back on, and ensure that Breakpoints on Triggers is turned off.

17. Debug Entering a Department Code. o Open the Customer card, go to the Communication tab. o Look up the dimension value table, and select one of the values. o When the value is selected into the field, press Enter to accept

the value into the field. This causes the OnValidate code of the Global Dimension 1 Code field to execute.

o Because the debugger is running, and because a manual breakpoint is set, the debugger breaks on this line of code, and then it displays the debugger window.

o Step through the code one step at a time, by pressing F8. Notice how it jumps from the OnValidate trigger into the ValidateShortcutDimCode function in the Customer table, and into the ValidateDimValueCode function in the Customer table, and then into the ValidateDimValueCode function in the Dimension Management codeunit.

o Try double-clicking either one of the triggers to see where the code is executed, which type of arrow is displayed, and what the meaning is of these arrows.

o Pick any variable, add it to the Watch window and observe how its value changes.

o Try to follow along and see when the Default Dimension record is created for the current customer. When does the system verify that the value that is being entered is a valid dimension value?

18. Debugging is a task that developers do on a daily basis, quite possibly more so than actually writing code. It is one task that every developer should master. It is important to build debugging skills, to become efficient with the various sections, and to learn when to step into a line of code.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 27: Na2009 enus devii_08

Chapter 8: Dimensions

8-27

Summary This chapter explored the role of dimensions in Microsoft Dynamics NAV and demonstrated how to implement dimensions in the existing features of the Seminar Management module. As a result, the student can now work with dimensions as a development tool in Microsoft Dynamics NAV.

This chapter also introduced the debugger interface which is applied to dimensions and is used as a tool to follow the flow of dimensions C/AL code.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 28: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-28

Test Your Knowledge

1. What is a dimension and what is its purpose in Microsoft Dynamics NAV?

2. In what tables are the dimensions for the following entry types stored?

Categories (Tables):

_____ Item 1: "Master" data entries (like Customer or Seminar)

_____ Item 2: Transaction document header and lines (like Sales Line or Seminar Registration Header)

_____ Item 3: Journal lines

_____ Item 4: Ledger entries

_____ Item 5: Posted documents

3. Describe the flow of information and how dimensions are transferred from the master data through transaction documents to ledger entries and posted documents.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 29: Na2009 enus devii_08

Chapter 8: Dimensions

8-29

Quick Interaction: Lessons Learned Take a moment and write down three key points you have learned from this chapter

1.

2.

3.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 30: Na2009 enus devii_08

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

8-30

Solutions Test Your Knowledge

1. What is a dimension and what is its purpose in Microsoft Dynamics NAV?

MODEL ANSWER:

A dimension is a value that is entered into a transaction to enable transactions with similar values to be grouped together for analysis.

2. In what tables are the dimensions for the following entry types stored?

Categories (Tables):

352 Item 1: "Master" data entries (like Customer or Seminar)

357 Item 2: Transaction document header and lines (like Sales Line or Seminar Registration Header)

356 Item 3: Journal lines

355 Item 4: Ledger entries

359 Item 5: Posted documents

3. Describe the flow of information and how dimensions are transferred from the master data through transaction documents to ledger entries and posted documents.

MODEL ANSWER:

Dimension values are transferred from the master record to the transaction when the master record is selected into the document. The dimension values are then transferred from the document to the Journal Lines, Ledger Entries and Posted Documents by logic in the posting routines.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement