﻿// remove info area if already displayed
if V[mcta_customer_info=A]
  Clear  V[mcta_customer_info]
  return
endif

// create table variable with country name and customer count
CreateTable V[ctab]  country count

// rsest display status  
Clear V[ctab.stat.*]

// Set SQL parameters
Set V[table] "KNA1"
Set V[fields] "LAND1,COUNT(*) AS I1"
Set V[groupby] "LAND1"
Set V[orderby] "I1 descending,LAND1"

//  determine customer count per country 
Call "/guixt/dbselect" _
  export.table="table" _
  export.fields="fields" _
  export.groupby="groupby" _ 
  export.orderby="orderby" _ 
  import.values="ctab"



// temporary image file
Set V[imagefilename] "&%[TEMP]\mvta_chart.&V[today_y-m-d hms].png"


// statusmessage 
StatusMessage title="Please wait a little bit..." addString="Preparing chart for &V[ctab.rowcount] countries"

// start Excel and copy data
CallJS XL_chart "ctab" "E:\MyCharts\charts.xlsm" "chartmap" "&V[imagefilename]"

// remove status message
StatusMessage -remove

//display info
Set V[mcta_customer_info] "A"

// done
Return
