Data Access Worldwide Knowledge Base
Article ID 2034 Article Title HOWTO: Populate a dblist using a calculation function Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2034 KBase Category VDF (GENERAL) Date Created 09/01/2004 Last Edit Date 09/08/2004
Article Text
QUESTION:
I have a selection list (lookup) panel in my program and for one of the columns I have created a calculation function which I assigned to the column. The program compiles fine, but when I open the selection list, all rows show zeroes but the first one. When I click on a row or move my cursor down the rows, the value is calculated and shown.
In the function I use FIELD_CURRENT_VALUE to retrieve the value from the DataDictionary.
My function is like:
Function CalculatedPrice Returns Number
Number nQtyOrdered nPrice nExtendedPrice
Get Field_Current_Value Of oOrderdtl_DD Field Orderdtl.Qty_ordered To nQtyOrdered
Get Field_Current_Value Of oOrderdtl_DD Field Orderdtl.Price To nPrice
Move (nQtyOrdered * nPrice) To nExtendedPrice
Function_Return nExtendedPrice
End_Function // CalculatedPrice
I would like to see the rows populated with the calculated values as soon as I open the selection list. What do I need to do to make that happen?
ANSWER:
The reason why the values in that column are zero is because while the dblist object initially reads the data, the local record buffer of the data dictionary is not refreshed. This is done for speed reasons. If the dblist read 15 records from the database and stored the values in the local record buffer on each read record, the initial display would be too slow. Since the local record buffer is empty, the calculation results in 0.
The solution is, therefore, to change the code to:
Function CalculatedPrice Returns Number
Number nExtendedPrice
Move (Orderdtl.Qty_ordered * Orderdtl.Price) To nExtendedPrice
Function_Return nExtendedPrice
End_Function // CalculatedPrice
Note:
The above function can be omitted and the expression in the object can be changed from:
Begin_Row
Entry_Item Orderhea.Order_number
Entry_Item Orderdtl.Detail_number
Entry_Item (CalculatedPrice (Self))
End_Row
To:
Begin_Row
Entry_Item Orderhea.Order_number
Entry_Item Orderdtl.Detail_number
Entry_Item (Orderdtl.Qty_ordered * Orderdtl.Price)
End_Row
This should be applied only when the function was very simple like the one in this Knowledge Base article.
Enclosed to this KBase article are two sample screenshots. One is showing the wrong / bad display and the other the correct desired display.
Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu
Web Links Related to this Article
File to illustrate correct / desired display
URL=http://www.dataaccess.com/KBasePublic/Files/2034.orderdtl lookup good.JPG
File to illustrate wrong / undesired display
URL=http://www.dataaccess.com/KBasePublic/Files/2034.orderdtl lookup wrong.JPG
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.