You are on page 1of 16

Coding Patterns Document

Table of Contents
INTRODUCTION .......................................................................................................................................... 2 CODING OF VARIABLES AND FUNCTIONS ......................................................................................... 3 MARKING OF OBJECTS AND CHANGES .............................................................................................. 8 VERSION LIST ............................................................................................................................................ 11 TERMINOLOGY ......................................................................................................................................... 12 GUI ................................................................................................................................................................. 13 C/SIDE STATEMENTS ............................................................................................................................... 14

Coding_Patterns_Doc

Introduction
Purpose Audience References
Reference Terminology Handbook Description The Terminology Handbook explains the concept of terminology and how we work with it. It also describes the underlying structure of Navision and outlines our naming conventions for objects. The C/Al Programming Guide describes the guidelines for writing C/AL code. Source

C/AL Programming Guide GUI Guide

The GUI Guide describes the graphical user interface components of Navision Attain and states how these components must be used to form the graphical user interface of the application. The main purpose of the GUI Guide is to enhance the usability of Navision Attain and add-on products to Navision Attain by ensuring visual and functional consistency across applications based on the Client/Server Integrated Development Environment (C/SIDE.)

Coding_Patterns_Doc

Coding of variables and functions


Fields
A meaningful name is used to define new fields to existing or new tables. The name is equal to the caption (US English) of the field.

Variables
New variables are declared according to the following syntax: <name>_<scope><type><application> Name Scope Type Application = Name of the variable = l(ocal) or g(lobal), i(nput), v(ar) = type of the variable (see table below) = Tmp for temporay tables, Arr for arrays.

Coding_Patterns_Doc

Nr. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23 24. 25. 26. 27. 28. 29. 30. 31. 32.

Control Action Automation BigInteger BigText Binary Boolean Char Code Codeunit Dataport DateFormula DateTime Decimal Dialog Duration FieldRef File Form GUID InStream Integer KeyRef OCX Option Outstream Record RecordID RecordRef Report System Text Time

Abbreviation

Act Aut Bgi Bgt Bin Bln Chr Cod Cdu Dpt Dtf Dat Dec Dlg Dur Frf Fil Frm Gui Ism Int Krf Ocx Opt Osm Rec Rid Rrf Rep Sys Txt Tim 4

Coding_Patterns_Doc

Nr. 33. 34. 35.

Control TransactionType Variant XMLport

Abbreviation

Trt Var Xml

Text Constants
New text constants are declared according to the following syntax: <name>_<scope>Ctx Scope = l(ocal) or g(lobal)

Functions
New functions are declared according to the following syntax: <name>_<scope>Fnc Scope = l(ocal) or g(lobal)

Coding_Patterns_Doc

Controls In some case it is required to add a name to controls on a form (e.g. for sub forms). The name that is assigned should follow the next rule: <Name>_ C<Type> Name c Type : Speaking Name. : C(ontrol). : Type, see table below.

Coding_Patterns_Doc

Nr. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.

Control Label Text Box Check Box Option Button Command Button Menu Button List Box Frame Image Picture Box Shape Indicator Tab Control Subform Table Box Matrix Box Report Frame

Abbreviation

Lbl Txb Cbx Obt Cbt Mbt Lbx Fme Img Pbx Shp Ind Tab Sfm Tbx Mbx Rfr

Coding_Patterns_Doc

Marking of objects and changes


Document trigger
------------------------------------------------------------------------------Columbus IT ------------------------------------------------------------------------------ID Date Author ------------------------------------------------------------------------------T-JJJ-xxx-vv, dd-mm-yyyy, <Name> <Description> -------------------------------------------------------------------------------

T JJJ XXX Vv

= Type (I = Initial, R=Revision, B=Bugfix). = Job No. Can be Alpha-Numeric = Job Task Number = Sequence Number

Changes
Syntax: <type>-<Job><Task>-<sequence>.<change> Type Job Sequence Change n o ns ne os oe New Old New start New end Old start Old end = I(nitial), R(evision), B(ugfix) = Job number (3 alpha numeric characters) = Sequence number (2 digits) = n, o, ns & ne, os & oe

Markings should be indented according to the indention of the source, except when only a single line is altered.

Coding_Patterns_Doc

Function description
You can add a short description at the beginning of a function if the function contains a complex routine. The description contains: The purpose of the function including the steps that are carried out. The pre-condition of the function. The post-condition of the function. For complex functions: //I-JEN-009-01.ns //Purpose : The function does something. //Pre : -//Post : -BEGIN <..> <..> END; //I-JEN-009-01.ne

Coding_Patterns_Doc

For simple functions: //I-JEN-009-01.ns BEGIN <..> <..> END; //I-JEN-009-01.ne

Coding_Patterns_Doc

10

Version List
The version list of an object should be filled with a code, according to the rules below. For existing objects: <Standard Navision Code>,[Name]<JJJ.MM.mm> For new objects: [Name]<JJJ.MM.mm> Name : In a multiple development scenario, where many developers are working on the same development server, the Developers Name is added so that other users are aware that the particular object is being worked upon. Once completed, the Name is removed. JJJ : Job Code. MM : Major Version. mm : Minor Version. Note that the date and time should be set to the current date, respectively 12.00 hrs. before the object is released.

Coding_Patterns_Doc

11

Terminology
See: Microsoft Business Terminology Handbook.

Coding_Patterns_Doc

12

GUI
See: Navision GUI Guide.

Coding_Patterns_Doc

13

C/SIDE Statements
Get records from database
Introduction
The new C/SIDE functions for reading records in a SQL Server environment are not backwards compatible with older Navision versions. This means a technical upgrade to NA401 is necessary. Paragraphs 0, 0, 0 are only applicable for Navision 4.00 SP1 and beyond.

FINDFIRST
This function should be used instead of FIND('-') when you only need the first record. For instance: IF Item_lRec.FINDFIRST THEN ItemMgt_lCdu.CopyItem(Item_lRec);

FINDLAST
This function should be used instead of FIND('+') when you only need the last record. For instance: IF ValueEntry_lRec.FINDLAST THEN LastEntryNo_lInt := ValueEntry_lRec.Entry No.;

FINDSET
Use this function to find a set of records in a table based on the current key and filter. The records can only be retrieved in ascending order. Syntax: Ok := Record.FINDSET([ForUpdate][, UpdateKey])

ForUpdate
Data type: boolean Set this to FALSE if you don't intend to modify any records in the set. Set this to TRUE if you want to modify some records in the set. If you set this parameter to TRUE, a LOCKTABLE is immediately performed on the table before the records are read.

UpdateKey
Data type: boolean This only applies if ForUpdate is set to TRUE. If you want to modify any field value within the current key, set this parameter to TRUE. Coding_Patterns_Doc 14

This function is designed to optimize finding and updating sets. If you set any or both of the parameters to FALSE, you can still modify the records in the set but these updates will not be performed optimally. This function actually replaces the FIND / REPEAT-UNTIL construction which we used until now. Example 1: Looping through a set without updating it.
SalesLine_lRec.SETFILTER("Purch. Order Line No.",'<>0'); IF SalesLine_lRec.FINDSET THEN BEGIN REPEAT CopyLine_lFnc(SalesLine_lRec); UNTIL SalesLine_lRec.NEXT = 0; END;

Example 2 Looping through a set and update a field that is not part of the current key
SalesLine_lRec.SETRANGE("Document Type",DocumentType); SalesLine_lRec.SETRANGE("Document No.",DocumentNo); IF SalesLine_lRec.FINDSET(TRUE, FALSE) THEN BEGIN REPEAT SalesLine_lRec."Location Code" := lFncGetNewLocation(SalesLine); SalesLine_lRec.MODIFY; UNTIL SalesLine_lRec.NEXT = 0; END;

Example 3: Loop through a set and update a field that is part of the current key
SalesShptLine_lRec.SETRANGE("Order No.", SalesLine_lRec."Document No."); SalesShptLine_lRec.SETRANGE("Order Line No.", SalesLine_lRec."Line No."); SalesShptLine_lRec.SETCURRENTKEY("Order No.","Order Line No."); IF SalesShptLine_lRec.FINDSET(TRUE, TRUE) THEN BEGIN REPEAT SalesShptLine2_lRec := SalesShptLine_lRec; SalesShptLine2_lRec."Order Line No." := SalesShptLine_lRec."Order Line No." + 10000; SalesShptLine2_lRec.MODIFY; UNTIL SalesShptLine_lRec.NEXT = 0; END;

Coding_Patterns_Doc

15

You might also like