| recordin.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin.mos
   `````````````````
   Reading records from
   spreadsheets or databases via ODBC.
   - Using 'initializations from' with odbc IO driver -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jan. 2014
*******************************************************!)
model "Record input (ODBC)"
 uses "mmodbc"
 parameters
                              ! Use Excel spreadsheet `recorddata.xls'
!  CNCTIO = "recorddata.xls"
                              ! Use Access database `recorddata.mdb'
  CNCTIO = "debug;recorddata.mdb"
                              ! Use mysql database `recorddata' (not provided)
!  CNCTIO = "debug;DSN=mysql;DB=recorddata"
                              ! Use SQLite database `recorddata' via ODBC
!  CNCTIO = 'DSN=sqlite;DATABASE=recorddata.sqlite'
                              ! Use SQLite database `recorddata' directly
!  CNCTIO = 'recorddata.sqlite'
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA,PDATA2: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA,ALLDATA2: array(R) of AllDataRec
 end-declarations
! **** Reading complete records
 initializations from "mmodbc.odbc:"+CNCTIO
  PDATA as "ProdData"
  ALLDATA as "noindex;ProdData"
 end-initializations
! **** Reading record fields
 initializations from "mmodbc.odbc:"+CNCTIO
  PDATA2(Cost) as "ProdData(IndexP,IndexM,Cost)"
  ALLDATA2(Product,Mach,Duration) as "noindex;ProdData(IndexP,IndexM,Duration)"
 end-initializations
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
 writeln('PDATA2 is: ', PDATA2)
 writeln('ALLDATA2 is: ', ALLDATA2)
end-model
 | 
| 
 | 
| recordin1.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin1.mos
   ``````````````````
   Reading records from a text file.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jul. 2010
*******************************************************!)
model "Record input (text files)"
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading complete records
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
end-model
 | 
| 
 | 
| recordin2.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin2.mos
   ``````````````````
   Reading records from
   spreadsheets or databases via ODBC.
   - Using SQL commands -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jul. 2013
*******************************************************!)
model "Record input (SQL)"
 uses "mmodbc"
 parameters
                              ! Use Excel spreadsheet `recorddata.xls'
!  CNCT = 'DSN=Excel Files;DBQ=C:/xpress/examples/mosel/WhitePapers/MoselODBC/recorddata.xls'
!  CNCT = 'recorddata.xls'
                              ! Use Access database `recorddata.mdb'
!  CNCT = 'DSN=MS Access Database;DBQ=C:/xpress/examples/mosel/WhitePapers/MoselODBC/recorddata.mdb'
  CNCT = 'recorddata.mdb'
                              ! Use mysql database `recorddata' (not provided)
!  CNCT = 'DSN=mysql;DB=recorddata'
                              ! Use SQLite database `recorddata' via ODBC
!  CNCT = 'DSN=sqlite;DATABASE=recorddata.sqlite'
                              ! Use SQLite database `recorddata' directly
!  CNCT = 'recorddata.sqlite'
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading complete records
 setparam("SQLverbose",true)
 SQLconnect(CNCT)
 SQLexecute("select * from ProdData", PDATA)
 setparam("SQLndxcol", false)           ! Dense data
 SQLexecute("select * from ProdData", ALLDATA)
 SQLdisconnect
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
end-model
 | 
| 
 | 
| recordin3.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin3.mos
   ``````````````````
   Reading records from
   spreadsheets or databases via ODBC.
   - Using 'initializations from' with the excel driver -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Dec. 2012
*******************************************************!)
model "Record input (Excel)"
 uses "mmsheet"
 parameters
  CSTR = 'mmsheet.excel:skiph;recorddata.xls'
 end-parameters
 
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA,PDATA2: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA,ALLDATA2: array(R) of AllDataRec
 end-declarations
! **** Reading complete records
 initializations from CSTR
  PDATA as "ProdData"
  ALLDATA as "noindex;ProdData"
 end-initializations
! **** Reading record fields
 initializations from CSTR
  PDATA2(Cost) as "CostData"
  ALLDATA2(Product,Mach,Duration) as "noindex;DurationData"
 end-initializations
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
 writeln('PDATA2 is: ', PDATA2)
 writeln('ALLDATA2 is: ', ALLDATA2)
end-model
 | 
| 
 | 
| recordin4.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin4.mos
   ``````````````````
   Reading records from an Oracle database.
   - Using 'initializations' and OCI statements -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "Record input (OCI)"
 uses "mmoci"
 parameters
  DB="myname/mypassword@dbname"     ! Login to Oracle database (not provided)
  CNCT="mmoci.oci:debug;"+DB
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA,PDATA1,PDATA2: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA,ALLDATA1,ALLDATA2: array(R) of AllDataRec
 end-declarations
 
! **** Using SQL statements ****
! Reading complete records
 setparam("OCIdebug",true)
 OCIlogon(DB)
 
 OCIexecute("select * from ProdData", PDATA)
 setparam("ocindxcol",false)      ! Dense data format (no indices)
 OCIexecute("select * from ProdData", ALLDATA)
 OCIlogoff
! **** Using 'initializations from' ****
! Reading complete records
 initializations from CNCT
  PDATA1 as "ProdData"
  ALLDATA1 as "noindex;ProdData"
 end-initializations
! Reading record fields
 initializations from CNCT
  PDATA2(Cost) as "ProdData(IndexP,IndexM,Cost)"
  ALLDATA2(Product,Mach,Duration) as "noindex;ProdData(IndexP,IndexM,Duration)"
 end-initializations
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
 writeln('PDATA1 is: ', PDATA1)
 writeln('ALLDATA1 is: ', ALLDATA1)
 writeln('PDATA2 is: ', PDATA2)
 writeln('ALLDATA2 is: ', ALLDATA2)
end-model
**************************************************
! Creation of data tables in an Oracle database:
 declarations
  tsucc: array ({false,true}) of string
  PDATA3: dynamic array(PRODUCTS,MACH) of ProdRec
 end-declarations
 tsucc(false):="failed"; tsucc(true):="succeeded"
 initializations from "recorddata.dat"
  PDATA3 as "ProdData"
 end-initializations
 setparam("OCIdebug",true)
 OCIlogon(DB)
 writeln("Connection number: ",getparam("OCIconnection"))
 OCIexecute("drop table ProdData")
 OCIexecute("create table ProdData (IndexP varchar(10), IndexM integer, Cost float, Duration integer)")
 writeln(" - Create ProdData (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("insert into ProdData (IndexP,IndexM,Cost,Duration) values (:1, :2, :3, :4)", PDATA3)
 writeln(" - Insert values into ProdData (",tsucc(getparam("OCIsuccess")),",",
        getparam("OCIrowcnt"),'/',getparam("OCIrowxfr")," rows)")
 OCIlogoff
 | 
| 
 | 
| recordin5.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin5.mos
   ``````````````````
   Reading records from spreadsheets.
   - Using 'initializations from' with the xls driver -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "Record input (generic spreadsheet)"
 uses "mmsheet"
 parameters
!  CSTR= 'mmsheet.xls:skiph;recorddata.xls'
  CSTR= 'mmsheet.xlsx:skiph;recorddata.xlsx'
 end-parameters
 
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA,PDATA2: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA,ALLDATA2: array(R) of AllDataRec
 end-declarations
! **** Reading complete records
 initializations from CSTR
  PDATA as "ProdData"
  ALLDATA as "noindex;ProdData"
 end-initializations
! **** Reading record fields
 initializations from CSTR
  PDATA2(Cost) as "CostData"
  ALLDATA2(Product,Mach,Duration) as "noindex;DurationData"
 end-initializations
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
 writeln('PDATA2 is: ', PDATA2)
 writeln('ALLDATA2 is: ', ALLDATA2)
end-model
 | 
| 
 | 
| recordin6.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordin6.mos
   ``````````````````
   Reading records from spreadsheets.
   - Using 'initializations from' with the csv driver -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "Record input (CSV)"
 uses "mmsheet"
 parameters
  CSTR= 'mmsheet.csv:recorddata.csv'
 end-parameters
 
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA,PDATA2: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA,ALLDATA2: array(R) of AllDataRec
 end-declarations
! **** Reading complete records
 initializations from CSTR
  PDATA as "[B4:E12]"
  ALLDATA as "noindex;[B4:E12]"
 end-initializations
! **** Reading record fields
 initializations from CSTR
  PDATA2(Cost) as "[B4:D12]"
  ALLDATA2(Product,Mach,Duration) as "noindex;[B17:D25]"
 end-initializations
! Now let us see what we have
 writeln('PDATA is: ', PDATA)
 writeln('ALLDATA is: ', ALLDATA)
 writeln('PDATA2 is: ', PDATA2)
 writeln('ALLDATA2 is: ', ALLDATA2)
end-model
 | 
| 
 | 
| recordout.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout.mos
   ``````````````````
   Writing out records to
   spreadsheets or databases via ODBC.
   - Using 'initializations from' with odbc IO driver -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jan. 2014
*******************************************************!)
model "Record output (ODBC)"
 uses "mmodbc"
 parameters
                              ! Use Excel spreadsheet `recorddata.xls'
!  CNCTIO = "recorddata.xls"
                              ! Use Access database `recorddata.mdb'
  CNCTIO = "debug;recorddata.mdb"
                              ! Use mysql database `recorddata' (not provided)
!  CNCTIO = "debug;DSN=mysql;DB=recorddata"
                              ! Use SQLite database `recorddata' via ODBC
!  CNCTIO = 'DSN=sqlite;DATABASE=recorddata.sqlite'
                              ! Use SQLite database `recorddata' directly
!  CNCTIO = 'recorddata.sqlite'
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Write out complete records
! (This assumes that the output tables have been created previously.)
! ATTENTION: results from previous runs must be removed previously.
 initializations to "mmodbc.odbc:"+CNCTIO
  PDATA as "ProdDataOutH"
  ALLDATA as "noindex;AllDataOutH"
 end-initializations
! **** Write out record fields
 initializations to "mmodbc.odbc:"+CNCTIO
  PDATA(Cost) as "CostOutH"
  ALLDATA(Product,Mach,Duration) as "noindex;DurationOutH"
 end-initializations
end-model
 | 
| 
 | 
| recordout1.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout1.mos
   ```````````````````
   Writing out records to a text file.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jul. 2010
*******************************************************!)
model "Record output (Text file)"
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Write out complete records
 initializations to "recordout.dat"
  PDATA as "ProdDataOutH"
  ALLDATA as "AllDataOutH"
 end-initializations
! **** Write out record fields
 initializations to "recordout.dat"
  PDATA(Cost) as "CostOutH"
  ALLDATA(Product,Mach,Duration) as "DurationOutH"
 end-initializations
end-model
 | 
| 
 | 
| recordout2.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout2.mos
   ```````````````````
   Writing out records to
   spreadsheets or databases via ODBC.
   - Using SQL commands -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jan. 2014
*******************************************************!)
model "Record output (SQL)"
 uses "mmodbc"
 parameters
                              ! Use Excel spreadsheet `recorddata.xls'
!  CNCT = 'DSN=Excel Files;DBQ=C:/xpress/examples/mosel/WhitePapers/MoselODBC/recorddata.xls'
!  CNCT = 'recorddata.xls'
                              ! Use Access database `recorddata.mdb'
!  CNCT = 'DSN=MS Access Database;DBQ=C:/xpress/examples/mosel/WhitePapers/MoselODBC/recorddata.mdb'
  CNCT = 'recorddata.mdb'
                              ! Use mysql database `recorddata' (not provided)
!  CNCT = 'DSN=mysql;DB=recorddata'
                              ! Use SQLite database `recorddata' via ODBC
!  CNCT = 'DSN=sqlite;DATABASE=recorddata.sqlite'
                              ! Use SQLite database `recorddata' directly
!  CNCT = 'recorddata.sqlite'
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Write out complete records
 setparam("SQLverbose",true)
 setparam("SQLdebug",true)
 SQLconnect(CNCT)
 SQLexecute("delete from ProdDataOutH") ! Cleaning up previous results: works
                                        ! only for databases, cannot be used
                                        ! with spreadsheets (instead, delete
                                        ! previous solutions directly in the
                                        ! spreadsheet file)
 SQLexecute("insert into ProdDataOutH(IndexP,IndexM,Cost,Duration) values (?,?,?,?)",
  PDATA)
 SQLexecute("delete from AllDataOutH")  ! Cleaning up previous results
 setparam("SQLndxcol", false)           ! Dense data
 SQLexecute("insert into AllDataOutH(IndexP,IndexM,Cost,Duration) values (?,?,?,?)",
  ALLDATA)
 SQLdisconnect
end-model
 | 
| 
 | 
| recordout3.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout3.mos
   ```````````````````
   Writing out records to
   spreadsheets or databases via ODBC.
   - Using 'initializations to' with the excel driver -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Dec. 2012
*******************************************************!)
model "Record output (Excel)"
 uses "mmsheet"
 parameters
  CSTR = 'mmsheet.excel:recorddata.xls'
 end-parameters
 
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Write out complete records
! (This assumes that the output tables have been created previously.)
! ATTENTION: results from previous runs must be removed previously.
! Driver options: noindex - dense data
 initializations to CSTR
  PDATA as "ProdDataOut"
  ALLDATA as "noindex;AllDataOut"
 end-initializations
! **** Write out record fields
 initializations to CSTR
  PDATA(Cost) as "CostOut"
  ALLDATA(Product,Mach,Duration) as "noindex;DurationOut"
 end-initializations
end-model
 | 
| 
 | 
| recordout4.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout4.mos
   ```````````````````
   Writing out records to an Oracle database.
   - Using 'initializations to' and OCI statements -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "Record output (OCI)"
 uses "mmoci"
 parameters
  DB="myname/mypassword@dbname"     ! Login to Oracle database (not provided)
  CNCT="mmoci.oci:debug;"+DB
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Using SQL statements ****
 setparam("OCIdebug",true)
 OCIlogon(DB)
 OCIexecute("delete from ProdDataOutH") ! Cleaning up previous results 
 OCIexecute("insert into ProdDataOutH(IndexP,IndexM,Cost,Duration) values (:1, :2, :3, :4)",
  PDATA)
 OCIexecute("delete from AllDataOutH")  ! Cleaning up previous results
 setparam("ocindxcol",false)            ! Dense data format (no indices)
 OCIexecute("insert into AllDataOutH(IndexP,IndexM,Cost,Duration) values (:1, :2, :3, :4)",
  ALLDATA)
 OCIlogoff
! **** Using 'initializations to' ****
! Write out complete records
 initializations to CNCT
  PDATA as "ProdDataOutH"
  ALLDATA as "noindex;AllDataOutH"
 end-initializations
! Write out record fields
 initializations to CNCT
  PDATA(Cost) as "CostOutH"
  ALLDATA(Product,Mach,Duration) as "noindex;DurationOutH"
 end-initializations
end-model
**************************************************
! Creation of data tables in an Oracle database:
 declarations
  tsucc: array ({false,true}) of string
 end-declarations
 tsucc(false):="failed"; tsucc(true):="succeeded"
 setparam("OCIdebug",true)
 OCIlogon(DB)
 writeln("Connection number: ",getparam("OCIconnection"))
 OCIexecute("drop table ProdDataOutH")
 OCIexecute("create table ProdDataOutH (IndexP varchar(10), IndexM integer, Cost float, Duration integer)")
 writeln(" - Create ProdDataOutH (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("drop table AllDataOutH")
 OCIexecute("create table AllDataOutH (IndexP varchar(10), IndexM integer, Cost float, Duration integer)")
 writeln(" - Create AllDataOutH (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("drop table CostOutH")
 OCIexecute("create table CostOutH (IndexP varchar(10), IndexM integer, Cost float)")
 writeln(" - Create CostOutH (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("drop table DurationOutH")
 OCIexecute("create table DurationOutH (IndexP varchar(10), IndexM integer, Duration integer)")
 writeln(" - Create DurationOutH (",tsucc(getparam("OCIsuccess")),")")
 OCIlogoff
 | 
| 
 | 
| recordout5.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout5.mos
   ```````````````````
   Writing out records to spreadsheets.
   - Using 'initializations to' with the xls driver -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "Record output (generic spreadsheet)"
 uses "mmsheet"
 parameters
  CSTR= 'mmsheet.xls:recorddata.xls'
!  CSTR= 'mmsheet.xlsx:recorddata.xlsx'
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Write out complete records
! (This assumes that the output tables have been created previously.)
! Driver options: noindex - dense data
 initializations to CSTR
  PDATA as "ProdDataOut"
  ALLDATA as "noindex;AllDataOut"
 end-initializations
! **** Write out record fields
 initializations to CSTR
  PDATA(Cost) as "CostOut"
  ALLDATA(Product,Mach,Duration) as "noindex;DurationOut"
 end-initializations
end-model
 | 
| 
 | 
| recordout6.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file recordout6.mos
   ```````````````````
   Writing out records to spreadsheets.
   - Using 'initializations to' with the csv driver -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "Record output (CSV)"
 uses "mmsheet"
 parameters
  CSTR= 'mmsheet.csv:recorddataout.csv'
 end-parameters
 declarations
  PRODUCTS: set of string
  MACH: range
  ProdRec = record
   Cost: real
   Duration: integer
  end-record 
  PDATA: dynamic array(PRODUCTS,MACH) of ProdRec
  R = 1..9
  AllDataRec = record
   Product: string
   Mach: integer
   Cost: real
   Duration: integer
  end-record 
  ALLDATA: array(R) of AllDataRec
 end-declarations
! **** Reading data from a text file
 initializations from "recorddata.dat"
  PDATA as "ProdData"
  ALLDATA as "AllData"
 end-initializations
! **** Write out complete records
! (This assumes that the output tables have been created previously.)
! Driver options: noindex - dense data
 initializations to CSTR
  PDATA as "[B4:E12]"
  ALLDATA as "noindex;[G4:J12]"
 end-initializations
! **** Write out record fields
 initializations to CSTR
  PDATA(Cost) as "[B17:D25]"
  ALLDATA(Product,Mach,Duration) as "noindex;[G17:I25]"
 end-initializations
end-model
 | 
| 
 | 
| listinout.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout.mos
   ``````````````````
   Reading/writing lists from/to
   spreadsheets or databases via ODBC.
   - Using 'initializations from' with odbc IO driver -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jan. 2014
*******************************************************!)
model "List handling (ODBC)"
 uses "mmodbc"
 parameters
                              ! Use Excel spreadsheet `listdata.xls'
!  CNCTIO = "listdata.xls"
                              ! Use Access database `listdata.mdb'
  CNCTIO = "debug;listdata.mdb"
                              ! Use mysql database `listdata' (not provided)
!  CNCTIO = "debug;DSN=mysql;DB=listdata"
                              ! Use SQLite database 'listdata.sqlite' directly 
!  CNCTIO = "debug;listdata.sqlite"
                              ! Use SQLite database 'listdata.sqlite' via ODBC
!  CNCTIO = "debug;DSN=sqlite;DATABASE=listdata.sqlite"
 end-parameters
 declarations
  R: range
  LI: list of integer
  A: integer
  LS,LS2: list of string
 end-declarations
 initializations from "mmodbc.odbc:"+CNCTIO
  LI as "List1"
  A
  LS as "List2"
 end-initializations 
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS 
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 initializations to "mmodbc.odbc:"+CNCTIO
  LI as "List1Out"
  LS2 as "List2Out"
 end-initializations 
end-model
 | 
| 
 | 
| listinout1.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout1.mos
   ```````````````````
   Reading/writing lists from/to text files.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007
*******************************************************!)
model "List handling (Text file)"
 declarations
  R: range
  LI: list of integer
  LS,LS2: array(R) of list of string   ! With text data files we can use
                                       ! compositions of structured types
 end-declarations
 initializations from "listdata.dat"
  LI as "List1"
  LS as "List2"
 end-initializations 
! Display the lists
 writeln("LI: ", LI)
 writeln("LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS 
 forall(i in R) LS2(i):= sum(l in LS(i)) [l+" year"+i]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 initializations to "listout.dat"
  LI as "List1Out"
  LS2 as "List2Out"
 end-initializations 
end-model
 | 
| 
 | 
| listinout2.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout2.mos
   ```````````````````
   Reading/writing lists from/to
   spreadsheets or databases via ODBC.
   - Using SQL commands -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Jan. 2014
*******************************************************!)
model "List handling (SQL)"
 uses "mmodbc"
 parameters
                              ! Use Excel spreadsheet `listdata.xls'
!  CNCT = 'DSN=Excel Files;DBQ=' + getparam("workdir") + '/listdata.xls'
!  CNCT = 'listdata.xls'
                              ! Use Access database `listdata.mdb'
!  CNCT = 'DSN=MS Access Database;DBQ=C:/xpress/examples/mosel/WhitePapers/MoselODBC/listdata.mdb'
  CNCT = 'listdata.mdb'
                              ! Use mysql database `listdata' (not provided)
!  CNCT = 'DSN=mysql;DB=listdata'
                              ! Use SQLite database 'listdata.sqlite' via ODBC
!  CNCT = 'DSN=sqlite;DATABASE=listdata.sqlite'
                              ! Use SQLite database 'listdata.sqlite' directly 
!  CNCT = "listdata.sqlite"
 end-parameters
 declarations
  R: range
  LI: list of integer
  A: integer
  LS,LS2: list of string
 end-declarations
 setparam("SQLverbose",true)
 SQLconnect(CNCT)
 SQLexecute("select * from List1", LI)
 A:= SQLreadinteger("select * from A")
 SQLexecute("select * from List2", LS)
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS 
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 SQLexecute("delete from List1Out")     ! Cleaning up previous results: works
 SQLexecute("delete from List2Out")     ! only for databases, cannot be used
                                        ! with spreadsheets (instead, delete
                                        ! previous solutions directly in the
                                        ! spreadsheet file)
 SQLexecute("insert into List1Out values (?)", LI)
 SQLexecute("insert into List2Out values (?)", LS2)
 SQLdisconnect
end-model
 | 
| 
 | 
| listinout3.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout3.mos
   ```````````````````
   Reading/writing lists from/to
   spreadsheets or databases via ODBC.
   - Using 'initializations from' with the excel driver -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007, rev. Dec. 2012
*******************************************************!)
model "List handling (Excel)"
 uses "mmsheet"
 parameters
  CSTR = 'mmsheet.excel:listdata.xls'
 end-parameters
 
 declarations
  R: range
  LI: list of integer
  A: integer
  LS,LS2: list of string
 end-declarations
 initializations from CSTR
  LI as "List1E"
  A as "AE"
  LS as "List2E"
 end-initializations 
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 initializations to CSTR
  LI as "List1EOut"
  LS2 as "List2EOut"             ! Output into a row
  LS2 as "grow;List2EGOut"       ! Output into a column
 end-initializations
end-model
 | 
| 
 | 
| listinout4.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout4.mos
   ```````````````````
   Reading/writing lists from/to
   an Oracle database.
   - Using 'initializations' and OCI statements -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "List handling (OCI)"
 uses "mmoci"
 parameters
  DB="myname/mypassword@dbname"     ! Login to Oracle database (not provided)
 end-parameters
 declarations
  R: range
  LI: list of integer
  A: integer
  LS,LS2: list of string
 end-declarations
 
! **** Using SQL statements ****
 setparam("OCIdebug",true)
 OCIlogon(DB)
 writeln("Connection number: ",getparam("OCIconnection"))
 OCIexecute("select * from List1 ", LI)
 A:=OCIreadinteger("select * from A")
 OCIexecute("select * from List2 ", LS)
 
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
 
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS 
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 OCIexecute("delete from List1Out")     ! Cleaning up previous output   
 OCIexecute("delete from List2Out")
 OCIexecute("insert into List1Out values (:1)", LI)
 OCIexecute("insert into List2Out values (:1)", LS2)
 
 OCIlogoff
! **** Using 'initializations from' ****
 initializations from "mmoci.oci:debug;"+DB
  LI as "List1"
  A
  LS as "List2"
 end-initializations 
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS 
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 initializations to "mmoci.oci:"+DB
  LI as "List1Out"
  LS2 as "List2Out"
 end-initializations 
end-model
**************************************************
! Creation of data tables in an Oracle database:
 declarations
  tsucc: array ({false,true}) of string
 end-declarations
 tsucc(false):="failed"; tsucc(true):="succeeded"
 setparam("OCIdebug",true)
 OCIlogon(DB)
 writeln("Connection number: ",getparam("OCIconnection"))
 OCIexecute("create table List1 (ListValues integer)")
 writeln(" - Create List1 (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("insert into List1 (ListValues) values (:1)", [ 1,2,3,4,5,6,7,8 ])
 writeln(" - Insert values into List1 (",tsucc(getparam("OCIsuccess")),",",
        getparam("OCIrowcnt"),'/',getparam("OCIrowxfr")," rows)")
 
 OCIexecute("create table A (AValue integer)")
 writeln(" - Create A (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("insert into A (AValue) values (:1)", [ 2002 ])
 writeln(" - Insert values into A (",tsucc(getparam("OCIsuccess")),",",
        getparam("OCIrowcnt"),'/',getparam("OCIrowxfr")," rows)")
 
 OCIexecute("create table List2 (ListValues char(3))")
 writeln(" - Create List2 (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("insert into List2 (ListValues) values (:1)", [ Jan,May,Jul,Nov,Dec ])
 writeln(" - Insert values into List2 (",tsucc(getparam("OCIsuccess")),",",
        getparam("OCIrowcnt"),'/',getparam("OCIrowxfr")," rows)")
 
 OCIexecute("create table List1Out (ListValues integer)")
 writeln(" - Create List1Out (",tsucc(getparam("OCIsuccess")),")")
 OCIexecute("create table List2Out (ListValues char(10))")
 writeln(" - Create List2Out (",tsucc(getparam("OCIsuccess")),")")
 
 OCIlogoff
 | 
| 
 | 
| listinout5.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout5.mos
   ```````````````````
   Reading/writing lists from/to spreadsheets.
   - Using 'initializations from' with the xls driver -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "List handling (generic spreadsheet)"
 uses "mmsheet"
 parameters
!  CSTR= 'mmsheet.xls:listdata.xls'
  CSTR= 'mmsheet.xlsx:listdata.xlsx'
 end-parameters
 
 declarations
  R: range
  LI: list of integer
  A: integer
  LS,LS2: list of string
 end-declarations
 initializations from CSTR
  LI as "List1E"
  A as "AE"
  LS as "List2E"
 end-initializations 
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 initializations to CSTR
  LI as "List1EOut"
  LS2 as "List2EOut"             ! Output into a row
  LS2 as "grow;List2EGOut"       ! Output into a column
 end-initializations
end-model
 | 
| 
 | 
| listinout6.mos | 
| (!******************************************************
   Mosel Example Problems
   ====================== 
   file listinout6.mos
   ```````````````````
   Reading/writing lists from/to spreadsheets.
   - Using 'initializations from' with the csv driver -
   
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012
*******************************************************!)
model "List handling (CSV)"
 uses "mmsheet"
 parameters
  CSTR_IN= 'mmsheet.csv:listdata.csv'
  CSTR_OUT= 'mmsheet.csv:listdataout.csv'
 end-parameters
 
 declarations
  R: range
  LI: list of integer
  A: integer
  LS,LS2: list of string
 end-declarations
 initializations from CSTR_IN
  LI as "[B4:I4]"
  A as "[K4]"
  LS as "[L4:P4]"
 end-initializations 
! Display the lists
 writeln("LI: ", LI)
 writeln("A: ", A, ", LS: ", LS)
! Reverse the list LI
 reverse(LI)
! Append some text to every entry of LS
 LS2:= sum(l in LS) [l+" "+A]
! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)
 initializations to CSTR_OUT
  LI as "[B3:I3]"
  LS2 as "[K3:O3]"                 ! Output into a row
  LS2 as "grow;[K6]"               ! Output into a column
 end-initializations
end-model
 | 
| 
 |