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
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;
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.
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.
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;
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156