Reports Formulas

Good Afternoon everyone, I have just started using the c/al report writer with Navision Attain version 3.01.B. I created a simple report and now I need to do a formula. The report uses Item, Sales Invoice Line and Sales Invoice Header tables. The Sales Invoice Line is linked to the Item table and Sales Invoice Header is linked to the Sales invoice Line table. I have in the sections description, item number, Unit Cost ($), Unit Price from the Sales Invoice Line table and Customer name, sales invoice number from the Sales header table. I use the Item table to display the report by item number. Now the problem, all I want to do is show the price paid per item. We use discounts line and order. In the Sales Invoice Line table I figured out that “Amount” equals the total price paid per item. Which means the discount has already been taken off. But it is the total amount not the per item amount. How do you code a formula to divide amount by quantity and dump the answer into a c/al global called NetPrice? THere it is in a nut shell hope someone can help out there. Thanks sbanatt

Unit prices are also stored in the lines. If the value that you want is not there you can do something line : v_UnitPrice := “Line Amount”/Quantity; in the onaftergetrecord trigger of the lines data item. You can put v_unitprice on the body section of the lines data item.

Thank you It worked. I knew it was easy just could not figure out how easy. Thanks again sbanatt

quote:


Originally posted by Sbanatt
Thank you It worked. I knew it was easy just could not figure out how easy. Thanks again sbanatt


No worries. You’ll soon find out that the Report Designer is not always so easy… you’ll be back, … just like all of us.[:)]

I’m Back! I was previewing the report to see if it would break. Well it did. When I filter it a certain way it comes back with an error message of Navision Attain Error of Division by Zero o/o click ok. I can only think that it hits one of the invoices that has a o (zero) total amount or a 0 (zero) quantity. Is there a way to have the program skip this type of an invoice and go on to the next one? Thanks

The only way to prevent these “divide by zero” errors is to check the value (is this the dividend, divisor, divider, dividee or else [8D]) before the operation and perform a CurrReport.SKIP if a division by zero would occur. Or is advanced error handling a la VB/C++/Java finally available in Attain [?]

Thank you. I did find out that there are invoices that have an amount as 0 so it would be 0/1. I would have to go back to 3rd grade math to let you know this in words. Better yet I’ll ask my granddaughter. What if we need the 0 amounts to show up on the report is there away to print even if the invoice has a 0 amount? Thanks again I will try the CurrReport.Skip.

quote:


Originally posted by Sbanatt
What if we need the 0 amounts to show up on the report is there away to print even if the invoice has a 0 amount?


There are some reports in our system that have an option for showing would-be divide by zero entries. Don’t know if they are part of the standard. It’s quite simple to do this, though. Instead of the SKIP, you simply set the value to zero or print out a warning message etc., depending on your needs. In any case, you should avoid executing the offending division [;)]

I’m not sure how to get the information for the report to print even if it is a 0(zero) amount. What I am trying to do is get the per item amount so the division is needed to arrive at this net amount. I am printing the item number, description, quantity bought, the unit price, unit cost, customer name, invoice number, sales person, and of course the per unit amount. Which uses the division to arrive at the per amount. Can you give me more of a hint on how to capture the information even if it is 0.00. I only need to print the sales line with the 0.00 not do math on it. THanks for any help.

quote:


Originally posted by Sbanatt
Thank you. I did find out that there are invoices that have an amount as 0 so it would be 0/1.


Actually 0/1 should not do any harm. 1/0 does. Instead of skipping the record you might try something like this: IF Quantity <> 0 THEN v_UnitPrice := “Line Aumount”/Quantity ELSE v_UnitPrice := 0; Anna

Well, let’s say you coded the calculation as suggested, i.e. v_UnitPrice := “Line Amount”/Quantity; Then you would wrap this into an IF to prevent the error message: IF Quantity <> 0 THEN v_UnitPrice := “Line Amount”/Quantity ELSE v_UnitPrice := 0.0; This will simply print out the offending lines with a value of 0. If you want an error message, you could place a text box into the report section, with a source expression of e.g. ErrorText, which would be a global variable of type text with some appropriate length, and then code: IF Quantity <> 0 THEN BEGIN v_UnitPrice := “Line Amount”/Quantity; ErrorText := ‘’; END ELSE BEGIN v_UnitPrice := 0.0; ErrorText := ‘Warning: Quantity = 0’; END; You could also create alternate sections, one with the numeric value, the other with the message. In the OnPreSection trigger, you could decide which section should be printed, based on the value of ErrorText. For the section with the value: CurrReport.SHOWOUTPUT(ErrorText = ‘’); For the other section: CurrReport.SHOWOUTPUT(ErrorText <> ‘’);

Thank you everyone for all the help with problem.