web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

CASE Statement

(0) ShareShare
ReportReport
Posted on by

When writing a case statement what should the "CASE ....... OF" Include. 


IF recProdOrderRtngLine.FINDSET THEN REPEAT
CASE (What should come here) OF
recInventorySetup."SMT Default Routing Link"
MESSAGE('SMT');
recInventorySetup."TH Default Routing Link";
MESSAGE('TH');
recInventorySetup."N Default Routing Link";
MESSAGE('SYS');
ELSE
MESSAGE('TEST');

I've never used CASE statements before 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Check the below link for the CASE statement explanation

    msdn.microsoft.com/.../dd339070.aspx

    Basically in your example an expression

    CASE recInventorySetup."Field" which you are comparing the values of SMT, TH or N

    For example check this

    CASE SalesSetup."Logo Position on Documents" OF

                        SalesSetup."Logo Position on Documents"::"No Logo":

                          ;

                        SalesSetup."Logo Position on Documents"::Left:

                          BEGIN

                            CompanyInfo1.GET;

                            CompanyInfo1.CALCFIELDS(Picture);

                          END;

                        SalesSetup."Logo Position on Documents"::Center:

                          BEGIN

                            CompanyInfo2.GET;

                            CompanyInfo2.CALCFIELDS(Picture);

                          END;

                        SalesSetup."Logo Position on Documents"::Right:

                          BEGIN

                            CompanyInfo3.GET;

                            CompanyInfo3.CALCFIELDS(Picture);

                          END;

                      END;

    In the above example it is comparing Logo Position on Documents field

  • mmv Profile Picture
    11,471 on at

    Hi,

    A typical case statement looks as below:-

     i := 2;
    CASE i OF
      1:
        MESSAGE('Your number is %1.', i);
      2:
        MESSAGE('Your number is %1.', i);
      ELSE
        MESSAGE('Your number is not 1 or 2.');
    END;

  • Suggested answer
    Community Member Profile Picture
    on at

    You can not use three different fields while using case statement.  You need to use single field and related field values while using Case Statement.

  • ManishS Profile Picture
    86 on at

    CASE recInventorySetup OF

     "SMT Default Routing Link" :

       MESSAGE('SMT');

     "TH Default Routing Link" :

       MESSAGE('TH');

     "N Default Routing Link":

       MESSAGE('SYS');

    END;

    Assuming the above setup is a option field.

  • Ryden Profile Picture
    10 on at

    Yes, you can use different fields and even different tables!

    Assuming the fields are Booleans we can use TRUE as switching variable

    IF recProdOrderRtngLine.FINDSET THEN REPEAT

       CASE TRUE OF

           recInventorySetup."SMT Default Routing Link" :

               MESSAGE('SMT');

           recInventorySetup."TH Default Routing Link" :

               MESSAGE('TH');

           recInventorySetup."N Default Routing Link" :

               MESSAGE('SYS');

           ELSE

               MESSAGE('TEST');

     END;

    Until recProdOrderRtngLine.NEXT = 0;

    If the fields aren't Booleans then do something like this, of course you can build very complicated logical expression

    CASE TRUE OF

       Table.TextField1 = 'Some text' :

           MyFunction(Rec);

       Table.IntegerField IN (1,10,100..199,999999..);

           Table.MODIFY;

       AnotherTable.AnotherIntegerField <> 0 :  // Note that you can use different tables as well! First found Case is executed

           ERROR('This must be zero!');

       ELSE

           MyCodeunit.SomeFunction(AnotherTable);

    END;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans