Method overloading in AL

Yet another cool feature in AL is method overloading. Imagine having a method being able to accept different paramters. What’s very common in most other modern languages just arrived in BC right now. In good old C/AL times you would have created several different methods… probably with some kind of a proxy method to prevent code duplication.

Today, luckily, we have the possibility to use method overloading. So, we’re able to define one an the same method, but with different parameters and implementations.

Probably the most important advantage of method overloading in AL is extensibility. We can extend already existing methods e.g. in the BaseApp or other extensions!

Example

local procedure MyProcedure(TextVar: Text)
begin
    //Implementation A
end;

//Same method name, but different paramters
local procedure MyProcedure(TextVar: Text; DecimalVar: Decimal)
begin
    //Implementation B
end;

And now the cool thing… VS Code shows the overloads:

MethodOverload1
MethodOverload2

... is a technical consultant and developer at Comsol Unternehmenslösungen AG in Kronberg/Taunus. Major tasks are the architecture and implementation of complex, usually cross-system applications in and around Microsoft Dynamics 365 Business Central.

Leave a Reply

Your email address will not be published.