You use Object Designer to create a new codeunit and you use the C/AL Editor to modify an existing codeunit.

For more information about how to create a codeunit, see How to: Create a Codeunit. For more information about how to modify a codeunit, see How to: Modify an Existing Codeunit.

Using the C/AL Editor

The C/AL Editor makes it easy to create and modify C/AL code. When you are working in the C/AL Editor, you have access to the C/AL Symbol Menu that helps you define C/AL functions. From the C/AL Symbol Menu, you can get help about all the C/AL commands. To view help for a function, select the C/AL function name in the right column and press F1.

You can open as many codeunits as you like. Each time you create a new codeunit or open an existing one, it is displayed in a separate window. This makes it easy to cut and paste lines of code between the codeunits. You can access the editing functions (Cut, Copy, and Paste) either from the Edit menu or by using the buttons on the toolbar. You can also use the standard shortcut keys that are described in the following table.

Shortcut key Description

CTRL+X

Cuts the selected text to the clipboard.

CTRL+C

Copies the selected text to the clipboard.

CTRL+V

Pastes the text on the clipboard into the codeunit at the cursor position.

CTRL+F

Opens the Find window to search for text.

Defining Variables, Text Constants, and Functions

After you create a new codeunit, the next step is to define the global variables, text constants, and functions that you need in the codeunit. You use the C/AL Globals tool for this. To access the C/AL Globals tool, select the C/AL Editor, click View, and then click C/AL Globals. In the C/AL Globals window, you must decide whether you want to add a global variable, a text constant, or a function. For more information, see the following topics:

Using the C/AL Symbol Menu

When you write C/AL code in the C/AL Editor, you can use the C/AL Symbol Menu window to get an overview of the following:

  • All the variables defined in the codeunit

  • All the C/AL functions

The C/AL Symbol Menu is divided into the following columns:

  • The first column lists the names of the variables (if you have defined any) and the function categories.

  • The second column lists the subcategories.

  • The third column lists the functions in the category that you selected.

You can see the syntax and other information, such as the Caption property corresponding to the field name that you have selected, in the lower left corner of the window.

In some cases, for example when a control on a form is a subform or when a field is a BLOB field, there are more than three columns in the C/AL Symbol Menu.

In the C/AL Symbol Menu, click OK or Apply to paste the syntax description into the C/AL Editor. When you click OK, the C/AL Symbol Menu window is closed automatically. When you click Apply, the window stays open.

For more information, see C/AL Functions.

Compiling and Saving Codeunits

Before you can run the functions in a codeunit, you must save and compile the code. When you compile the code, the syntax of the statements are checked. If the compiler finds any errors in the code it displays an error message. For more information about how to compile the code in a codeunit, see How to: Compile the Code in a Codeunit. For more information about how to save a codeunit, see How to: Save a Codeunit.