This tutorial shows you how to produce a report on IC Product quantities by location. You can use MaxBasic to create a Pivot Table with this information, then format the table.
ICPROD.ProductCode
ICPROD.Description
ICQTY.LocationCode
ICQTY.QuantityAvailable
The fields selected will be displayed in the grid at the bottom of the SQL Query Builder form.
WHERE ICProd.NonDiminishing = False AND ICProd.ProductCode BETWEEN :FromCode AND :ToCode Order By ICProd.ProductCode , ICQty.LocationCode
This will only select products that are diminishing (kitsets will not be included), and will allow you to input a range of Product Codes to select from. It will also order the results by the Product Code, then Location Code.
SQL =
Then Paste the SQL Query into the window, on the same line as SQL = . You now have the SQL query so it can be used by the MaxBasic code. The script will look like this:
SQL = "SELECT ICPROD.ProductCode " & _
" ,ICPROD.Description " & _
" ,ICQTY.LocationCode " & _
" ,ICQTY.QuantityAvailable " & _
"FROM ICPROD " & _
" INNER JOIN ICQTY ON ICPROD.ProductCode=ICQTY.ProductCode " & _
" WHERE ICProd.NonDiminishing = False " & _
"AND ICProd.ProductCode BETWEEN :FromCode AND :ToCode " & _
"Order By ICProd.ProductCode , ICQty.LocationCode "
'Report Selections
Dim scForm as Object
scForm = CreateObject("Accredo.ScriptedForm")
scForm.Caption = "Locations Cross Tab Selections"
Dim FromCodeControl as Object
Dim ToCodeSibling as Object
FromCodeControl = scForm.InputCode("FromCode","ICPROD", "Product - From", "", False, False, True)
scForm.SetValue("FromCode", "")
ToCodeSibling = scForm.InputCode("ToCode","ICPROD", "Product - To", "", False, False, True)
ToCodeSibling.DittoSibling = FromCodeControl
scForm.SetValue("ToCode", "")
Do
If Not scForm.Execute Then
Abort("Report cancelled by user.")
Else
FromCode = scForm.GetValue("FromCode")
ToCode = scForm.GetValue("ToCode")
Exit Do
End If
Loop
If FromCode = "" And ToCode = "" then
FromCodeSelect = False
Else
FromCodeSelect = True
End If
'Default empty selection to start/end
If FromCode = "" Or ToCode = "" then
ICPROD = OpenTable("ICPROD")
ICPROD.IndexName = "Product"
If FromCode = "" Then
ICPROD.First
FromCode = ICPROD.ProductCode
End If
If ToCode = "" Then
ICPROD.Last
ToCode = ICPROD.ProductCode
End If
End If
Dim tblQty as Object
tblQty = ExecuteSQL(SQL,FromCode,ToCode)
Dim tblPivot as Object
tblPivot = PivotTable(tblQty, "ProductCode;Description", "LocationCode", "Sum(QuantityAvailable)", True)
TotalFields = tblPivot.Fields.Count
tblPivot.Fields.Item("ProductCode").DisplayWidth = 20
tblPivot.Fields.Item("Description").DisplayWidth = 40
tblPivot.Fields.Item(TotalFields - 1).DisplayLabel = "Total|Available"
For x = 2 to TotalFields - 2
CurrentLabel = tblPivot.Fields.Item(x).DisplayLabel
tblPivot.Fields.Item(x).DisplayLabel = Replace(CurrentLabel, "QuantityAvailable", "|Quantity|Available")
tblPivot.Fields.Item(x).DisplayWidth = 10
Next x
For x = 2 to TotalFields - 1
tblPivot.Fields.Item(x).total = True
Next x
Dim Report as Object
Report = CreateREport(tblPivot, "IC Quantity by Location")
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 Product Quantities by Location Pivot Table. You can cut and paste this script into the script editor to create this report.