Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day...

65
Microsoft ® Business Solutions– Navision ® 4.0 Development II - C/SIDE Solution Development Day 2

Transcript of Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day...

Page 1: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Microsoft® Business Solutions–Navision®

4.0 Development II - C/SIDE Solution

Development

Microsoft® Business Solutions–Navision®

4.0 Development II - C/SIDE Solution

Development

Day 2

Page 2: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Managing Master FilesManaging Master Files

Review Questions

Page 3: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Multilanguage – Text ConstantsMultilanguage – Text Constants

Page 4: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

4 of 65

Text ConstantsText Constants

• Defined as C/AL Globals• Captions for different languages

(ConstValueML)• Used instead of text strings in C/AL code

– Definition : Text001:ENU=‘%1 must be positive.’

– Usage : ERROR(Text005,FIELDCAPTION(Amount));

• Use table and field captions to replace the placeholders in text constants

Page 5: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Matrix FormsMatrix Forms

Page 6: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

6 of 65

Matrix FormMatrix Form

Form SourceTable fields (SourceTable = Item)

Matrix Header TextBox

Matrix Box (MatrixSourceTable = Location)

Form SourceTable field (SourceTable = Item) Calculated per Item and Location

Filter and Options(SourceTable = Item)

Page 7: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

7 of 65

Matrix FormsMatrix Forms

OnAfterGetRecord (Form)OnAfterGetRecord (Form)

OnAfterGetRecord (Matrix)OnAfterGetRecord (Matrix)

Triggers

• Fires for each source table record (Item)

• Fires for each matrix source table record (Location)• Used to update calculated matrix fields (Inventory)• C/AL code example:

SETRANGE("Location Filter",CurrForm.ItemAvailMatrix.MatrixRec.Code);CALCFIELDS(Inventory);

Page 8: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Table TypesTable Types

Page 9: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

9 of 65

Table TypesTable Types

• Database Table– Regular table type to store data in the

database

• Virtual Table– Information provided by the system

• Temporary Table– Temporary variable to buffer table data on

client side

• System Table– Created automatically by the system

Page 10: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

10 of 65

Table TypesTable Types

• Table that contains information provided by the system

• Information is read-only• Data is not stored in the database• Table definition cannot be modified• Can be used, for example, to show dates

in different periods (Date table)

Virtual Table

Page 11: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

11 of 65

Table TypesTable Types

• Temporary variable based on a database table

• Data stored temporarily in workstation’s memory

• Write transactions principle does not apply• Reduces load on server and network• Can be used, for example, in posting

functions (table Invoice Post. Buffer)

Temporary Table

Page 12: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

12 of 65

Table TypesTable Types

• Tables created automatically by the system

• Data is stored in the database• Table definition can be modified• Can be used by the system, for example,

to manage security and permissions (User, Member Of and User Role tables)

System Table

Page 13: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

13 of 65

Additional FunctionsAdditional Functions

• CALCDATE• DATE2DMY• DATE2DWY• ROUND• RUNMODAL• CONFIRM• MESSAGE• ERROR• TESTFIELD• WORKDATE• VALIDATE• FORMAT• COUNT

Page 14: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Managing RegistrationsManaging Registrations

Lab

Page 15: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

15 of 65

ConclusionConclusion

• We have now created the tables and forms necessary to register participants in seminars

• Now that we can enter transaction information, we need to create a posting routine

Page 16: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Managing RegistrationsManaging Registrations

Review Questions

Page 17: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

17 of 65

ReviewReview

• Multilanguage – Using Text Constants• Matrix Forms• Table Types

Page 18: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Structure of Journal FormsStructure of Journal Forms

Page 19: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

19 of 65

Structure of Journal FormsStructure of Journal Forms

TemplateTemplate BatchBatchBatchBatch

BatchBatch LineLineLineLine

LineLineLineLine

Form Types

LineLine

Page 20: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

20 of 65

Structure of Journal FormsStructure of Journal Forms

• General Journal Templates– Set up different journal windows– Template for batches– No posting possible

• General Journal Batches– Different batches for each template– Set up for journals, like Bal. Account– Posting possible

• General Journal Line– Each line belongs to one template and batch– Transaction information for posting, such as Date,

Account and Amount– Posting possible

General Journal Forms

Page 21: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Journal Posting RoutinesJournal Posting Routines

Page 22: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

22 of 65

Journal Posting RoutinesJournal Posting Routines

• The Difference between a Journal and a Ledger

• Standard Journal to Ledger Posting Routines

• The Main Three Codeunits• The Theory behind Document Posting• The Codeunits used in Document Posting

Page 23: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

23 of 65

The Difference between a Journal and a Ledger

• Ledger• Protected Table• Primary Key - Entry No.

An Integer• Entry Numbers Start at 1• Many Secondary Keys• Holds the Majority of the Detail

Information for the Functional Area

• NEVER INSERT OR DELETE!

•Journal• Temporary Work Area• Main Table is Journal Line• Two Supplemental Tables

• Journal Template• Journal Batch

• Compound Primary Key• Line Number Incremented Automatically

Journal Posting RoutinesJournal Posting Routines

Page 24: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

24 of 65

Numbering of Journal Posting RoutinesNumbering of Journal Posting Routines

1 Journal Check Line2 Journal Post Line3 Journal Post Batch

1 Journal Check Line2 Journal Post Line3 Journal Post Batch

0 Journal Management1 Journal Post2 Journal Post+Print3 Journal Batch Post4 Journal Batch Post+Print5 Show Ledger

0 Journal Management1 Journal Post2 Journal Post+Print3 Journal Batch Post4 Journal Batch Post+Print5 Show Ledger

•Posting routines

•Management and “starter” routines

Journal Posting Routines

Page 25: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

25 of 65

Standard Journal to Ledger Posting RoutinesStandard Journal to Ledger Posting Routines

• “Starter” Routines - Just ask Question(s) and Go– 1. Post - Posts One Batch– 2. Post and Print - Posts One Batch and Prints

Register– 3. Batch Post - Posts Multiple Batches– 4. Batch Post and Print - Posts Multiple Batches

and Prints Each Register

Page 26: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

26 of 65

Standard Journal to Ledger Posting RoutinesStandard Journal to Ledger Posting Routines

• Posting Routines - Don’t Ask, Just Do the Work– 1. Check Line - Test the Journal Line without

Disturbing Server– 2. Post Line - Transfer Data from Journal Line to

Ledger Line(s)– 3. Post Batch - Process a User-Entered Journal

Page 27: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

27 of 65

The Main Three Posting Routine CodeunitsThe Main Three Posting Routine Codeunits

• Check Line• Post Line• Post Batch

Page 28: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

28 of 65

The Main Three Posting Routine CodeunitsThe Main Three Posting Routine Codeunits

• Check Line– Checks One Journal Record (Line)– No User Interface– Never Reads or Updates Journal Table– Does Data Entry Testing which does not Disturb

Server• Test to See if User Entered all Required Data• Tests that Certain Business Rules have been Followed• Tests for Valid Posting Dates• Tests may Read a Setup Record, but only if it can be

done Once per Posting Process

Page 29: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

29 of 65

The Main Three Posting Routine CodeunitsThe Main Three Posting Routine Codeunits

• Post Line– Posts One Journal Record (Line)– No User Interface– Never Reads or Updates Journal Table– Calls Check Line for its Journal Record– Does Validity Testing which can Read Records

from Other Tables– Creates Ledger Entry or Entries (needs

Permissions to do so)– Applies (links) Ledger Records as Necessary– Can be called from Other Posting Routines

Page 30: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

30 of 65

The Main Three Posting Routine CodeunitsThe Main Three Posting Routine Codeunits

• Post Batch– Posts Records from One Batch of Journal Table– Displays Progress to User, but no User Input

Allowed– Calls Check Line for Each Record in Journal– Does Total / Balance / Recurring Testing– Calls Post Line for Each Record in Journal– Deletes or Updates Journal Records

Page 31: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

31 of 65

Architecture of Journal Posting RoutinesArchitecture of Journal Posting Routines

Post BatchCodeunit X3Post Batch

Codeunit X3

Post LineCodeunit X2

Post LineCodeunit X2

Check LineCodeunit X1Check Line

Codeunit X1

Check LineCodeunit X1Check Line

Codeunit X1

Starter RoutineStarter Routine

Journal Posting Routines

Page 32: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Document Posting RoutinesDocument Posting Routines

Page 33: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

33 of 65

The Theory Behind Document PostingThe Theory Behind Document Posting

• What is a Document?• Breaking it Down

Page 34: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

34 of 65

Header

Line 2(selling an

Item)

Line 3(selling a

Resource)

Line 1(selling an Account)

GeneralJournal

Document Tables Journal Tables Ledger Tables

ResourceJournal

ItemJournal

ResourceLedger

ItemLedger

CustomerLedger

General LedgerAccounts Rec. AcctSales Account 1Sales Account 2Sales Account 3

CreditsDebitsBalance Detail Entry

The Theory Behind Document Posting

Document Posting RoutinesDocument Posting Routines

Page 35: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

35 of 65

Document Posting RoutinesDocument Posting Routines

Post documentCodeunit X0

Post documentCodeunit X0

Post document preparationCodeunit X1 / X2

Post document preparationCodeunit X1 / X2

Architecture of Document Posting

Type

Gen. Journal-Post Line (CU12)Gen. Journal-Post Line (CU12)

Gen. Journal Line TableGen. Journal Line Table

Item Journal-Post Line (CU22)Item Journal-Post Line (CU22)

Item Journal Line TableItem Journal Line Table

Page 36: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

36 of 65

Document Posting RoutinesDocument Posting Routines

0 Document - Post0 Document - Post

1 Document - Post (Yes/No)2 Document - Post +Print1 Document - Post (Yes/No)2 Document - Post +Print

•Posting function

•Start functions

Numbering of Document Posting Routines

Page 37: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

37 of 65

Document Posting RoutinesDocument Posting Routines

• A sales document is posted primarily by codeunit 80 – Sales-Post

• You can however post an entire batch of sales invoice documents by calling report 297

Page 38: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

38 of 65

Document Posting RoutinesDocument Posting Routines

• Focusing in on Codeunit 80 (Sales-Post)– First, it creates a Journal Line using a record

variable (usually called GenJnlLine, ResJnlLine, ItemJnlLine, etc...) for the appropriate journal

– All of the necessary fields are assigned values from the Header or the Line (mostly the Line)

– Other values are calculated or retrieved from the posting group tables

– Finally, the record variable (never inserted into the table) is passed to the PostLine Codeunit for the appropriate journal

– All postings to the G/L go through the Gen. Jnl.-Post Line Codeunit

Page 39: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Table LockingTable Locking

Page 40: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

40 of 65

Table LockingTable Locking

• Different locking in Microsoft Navision and Microsoft® SQL Server®

• All write operations automatically lock the table or the record (SQL Server only) in use

• Use LOCKTABLE to explicitly lock a table in C/AL

• Use RECORDLEVELLOCKING to test for SQL Server

• Use COMMIT to end a write transaction manually only where needed

Page 41: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

41 of 65

Table LockingTable Locking

Microsoft Navision Database Server• Whole table is locked when issuing LOCKTABLE• Consistent versions for read tasks• Optimistic concurrency for multiple records by

means of LOCKTABLE(TRUE,TRUE)

SQL Server Option• Records are locked when accessed after LOCKTABLE• When no LOCKTABLE: Dirty reads (”Read

Uncommitted”)• Optimistic concurrency supported for single records

by means of Timestamp field added to all tables

Major Differences between Microsoft Navision and SQL Server

Page 42: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Performance IssuesPerformance Issues

Page 43: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

43 of 65

Low Impact ProgrammingLow Impact Programming

• Low Impact on the Application• Low Impact on the Server• Low Impact on the Network• Low Impact on the Database

Page 44: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

44 of 65

Low Impact on the ApplicationLow Impact on the Application

• Modifying Existing Objects– Tables– Reports– Codeunits– Forms

Page 45: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

45 of 65

Low Impact on the ApplicationLow Impact on the Application

• Tables– In some cases, it is better to add a new table

than to modify an existing table– It is better to add a new field to an existing

table than to modify the meaning of an existing field

– It is better to change the Caption property than the Name property

– It is better to change the caption of an existing field than to add a new field, if the only purpose is to change the name

– Try to write new functionality into separate functions

Page 46: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

46 of 65

Low Impact on the ApplicationLow Impact on the Application

• Reports– Always create a copy of an existing report and

modify the copy– Document changes well– Try to write new functionality into separate

functions

Page 47: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

47 of 65

Low Impact on the ApplicationLow Impact on the Application

• Codeunits– Try to write new functionality into separate

functions

Page 48: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

48 of 65

Low Impact on the ApplicationLow Impact on the Application

• Forms– Most changes– Hard to document– Try to write new functionality into separate

functions using local variables

Page 49: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

49 of 65

Low Impact on the ServerLow Impact on the Server

• COMMIT• LOCKTABLE• INSERT, MODIFY, DELETE• CALCSUMS, CALCFIELDS• Keys• Validity Testing

Page 50: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

50 of 65

Low Impact on the ServerLow Impact on the Server

• COMMIT– Handled automatically for almost all

applications– Should almost never be used manually

Page 51: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

51 of 65

Low Impact on the ServerLow Impact on the Server

• LOCKTABLE– Limit to only where necessary.– Insert, modify, rename, and delete will lock

automatically.

Page 52: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

52 of 65

Low Impact on the ServerLow Impact on the Server

• INSERT, MODIFY, DELETE– Try to structure to not use the return value.

Page 53: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

53 of 65

Low Impact on the ServerLow Impact on the Server

• CALCSUMS, CALCFIELDS– Use when possible rather than looping through

records.– Takes about the same amount of time as one Get

command.

Page 54: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

54 of 65

Low Impact on the ServerLow Impact on the Server

• Keys– Define new keys when appropriate– Select keys carefully, based on filters– Attach SumIndexFields to the most efficient key

Page 55: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

55 of 65

Low Impact on the ServerLow Impact on the Server

• Validity Testing– When possible, perform tests that do not

involve the server first– Use temporary tables

Page 56: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

56 of 65

Low Impact on the NetworkLow Impact on the Network

• MODIFYALL, DELETEALL• CALCSUMS, CALCFIELDS• Filters

Page 57: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

57 of 65

Low Impact on the NetworkLow Impact on the Network

• MODIFYALL, DELETEALL– Use these commands when possible, vs.

MODIFY and DELETE– Use appropriate keys and filters

Page 58: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

58 of 65

Low Impact on the NetworkLow Impact on the Network

• CALCSUMS, CALCFIELDS– Multiple parameters can sum many fields with

one function call (and one network packet)

Page 59: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

59 of 65

Low Impact on the NetworkLow Impact on the Network

• Filters– Use when possible, even if not part of a key

Page 60: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

60 of 65

Low Impact on the DatabaseLow Impact on the Database

• SumIndexFields• Keys• Duplication of Data

Page 61: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

61 of 65

Low Impact on the DatabaseLow Impact on the Database

• SumIndexFields– Take up a significant amount of space, only use

where beneficial

Page 62: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

62 of 65

Low Impact on the DatabaseLow Impact on the Database

• Keys– Take up a significant amount of space, only use

where beneficial– Assign infrequently used keys to Key Groups

and deactivate when not needed

Page 63: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

63 of 65

Low Impact on the DatabaseLow Impact on the Database

• Duplication of Data– Avoid where possible

Page 64: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

Debugging ToolsDebugging Tools

Page 65: Microsoft ® Business Solutions–Navision ® 4.0 Development II - C/SIDE Solution Development Day 2.

65 of 65

Debugging ToolsDebugging Tools

• Navision Debugger– Checks C/AL code lines– Uses breakpoints– Contains several windows to watch fields,

variables, and stack

• Code Coverage– Logs objects and code– Shows not-executed lines in different color

(red)