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

  • Ryden Profile Picture
    10 on at
    RE: CASE Statement

    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;

  • ManishS Profile Picture
    80 on at
    RE: CASE Statement

    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.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: CASE Statement

    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.

  • mmv Profile Picture
    11,467 on at
    RE: CASE Statement

    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;

  • Verified answer
    Suresh Kulla Profile Picture
    47,688 on at
    RE: CASE Statement

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans