Tuesday, 22 April 2025

Boost String Number Handling in AL with the New IncStr Parameter

You've probably used the IncStr method to increment numbers embedded in string variables, especially when dealing with number series. Traditionally, IncStr was limited to increasing or decreasing the number by 1. For anything beyond that, you'd have to roll up your sleeves and build some custom logic. Not anymore!

🆕 What’s New?

The IncStr method now supports an optional increments parameter, allowing you to change a number inside a string by any integer value, not just 1.

Whether you're jumping ahead in a number series or stepping back, this update simplifies your code and makes it easier to work with strings that contain numbers.


Feature Highlights

  • New overload: IncStr(Text, [Increment: Integer])
  • Flexible: Supports any positive or negative integer.

💡 Use Case Example

Let’s say you have a string:

'Account no. 99 does not balance.'

You want to change 99 to 109. Previously, you'd have to parse and replace the number manually.

Now, you can do it in one line:

ResultAccount := IncStr(Account, 10);

Here’s a full AL code example:

codeunit 50111 MyAccountCodeunit

{

    procedure MyIncStr()

    var

        Account: Text[60];

        ResultAccount: Text[60];

        AText: TextConst ENU = 'Account no. 99 does not balance.';

    begin

        Account := AText;

        ResultAccount := IncStr(Account, 10); // Increases 99 → 109

    end;

}

 


No comments:

Post a Comment