This tutorial shows you how to produce a report on IC Product prices. You can use MaxBasic to create a Pivot Table with this information, then format the table.
Dim tblCOPRICE as Object
tblCOPRICE = OpenTable("COPRICE")
tblCOPRICE.IndexName = "Line"
'Report Selections
Dim scForm as Object
scForm = CreateObject("Accredo.ScriptedForm")
scForm.Caption = "Report Selections"
Dim ProductFromControl as Object
Dim ProductToSibling as Object
ProductFromControl = scForm.InputCode("ProductFrom","ICPROD", "Product - From", "", False, False, True)
scForm.SetValue("ProductFrom", "")
ProductToSibling = scForm.InputCode("ProductTo","ICPROD", "Product - To", "", False, False, True)
ProductToSibling.DittoSibling = ProductFromControl
scForm.SetValue("ProductTo", "")
Do
If Not scForm.Execute Then
scForm.ShowStatusHint("Cancelled")
Abort("", True)
Else
ProductFrom = scForm.GetValue("ProductFrom")
ProductTo = scForm.GetValue("ProductTo")
Exit Do
End If
Loop
'Default empty selection to start/end
If ProductFrom = "" Or ProductTo = "" then
ICPROD = OpenTable("ICPROD")
ICPROD.IndexName = "Product"
If ProductFrom = "" Then
ICPROD.First
ProductFrom = ICPROD.ProductCode
End If
If ProductTo = "" Then
ICPROD.Last
ProductTo = ICPROD.ProductCode
End If
End If
Where ICProd.ProductCode Between :ProductFrom and :ProductToORDER BY ICPROD.ProductCode ,COPRICE.LineNo
This will allow you to input a range of Product Codes to select from. It will also order the results by the Product Code, then Line No.
SQL =
Then Paste the SQL Query into the window. You now have the SQL query so it can be used by the MaxBasic code.
Dim tblPrices as Object
tblPrices = ExecuteSQL(SQL,ProductFrom,ProductTo)
Dim tblPivot as Object
tblPivot = PivotTable(tblPrices, "ProductCode;Description;SalesGroupCode;StockGroupCode", "LineNo", "Sum(Price)",False)
TotalFields = tblPivot.Fields.Count
tblPivot.Fields.Item("ProductCode").DisplayWidth = 20
tblPivot.Fields.Item("Description").DisplayWidth = 40
For x = 4 to TotalFields - 1
CurrentLabel = tblPivot.Fields.Item(x).DisplayLabel
If tblCOPRICE.FindExact(val(CurrentLabel)) then
tblPivot.Fields.Item(x).DisplayLabel = tblCOPRICE.PriceCode
End If
tblPivot.Fields.Item(x).format = "0.00"
Next x
Dim Report as Object
Report = CreateREport(tblPivot, "IC Products and Prices")
Report.Destination = "Screen"
Report.Run
(Ctrl+S) to save the script.(Alt+R) to test the script. The pivot table containing IC Product Quantities by Location is shown as a report.The entire script for this tutorial is at MB Script: IC Products and Prices Pivot Table. You can cut and paste this script into the script editor to create this report.