| |||||||||||||||||||||||||||||||||||||||||
Reading and writing records and lists Description This set of examples shows how to work with advanced data structures when accessing data in spreadsheets and databases:
Further explanation of this example: Xpress Whitepaper 'Using ODBC and other database interfaces with Mosel', Section Examples - Working with lists - Working with records.
Source Files By clicking on a file name, a preview is opened at the bottom of this page. Data Files
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, rev. Feb. 2019 *******************************************************!) model "Record output (generic spreadsheet)" uses "mmsheet", "mmsystem" parameters CSTR= 'mmsheet.xls:recorddata.xls' ! CSTR= 'mmsheet.xlsx:recorddata.xlsx' FNAME2='recordout.xls' CSTR2= 'mmsheet.xls:skiph+;'+FNAME2 ! FNAME2='recordout.xlsx' ! CSTR2= 'mmsheet.xlsx:skiph+;'+FNAME2 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 ! **** Writing out into a spreadsheet with named ranges **** ! 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 selected record fields initializations to CSTR PDATA(Cost) as "CostOut" ALLDATA(Product,Mach,Duration) as "noindex;DurationOut" end-initializations ! **** Writing out into a new spreadsheet file (without named ranges) **** ! Remove any copy of the output file created by previous runs fdelete(FNAME2) ! Driver option skiph+ enables addition of specified column titles in output ! Column ranges can be specified in various ways; ! if no sheet name is given the first sheet is used initializations to CSTR2 ! Output complete records PDATA as "grow;[OutputData$A:D](Product,Mach,Cost,Duration)" ALLDATA as "noindex;grow;[F:I](Product,Mach,Cost,Duration)" ! Output selected record fields PDATA(Cost) as "grow;[R1C11:R1C13](Product,Mach,Cost)" ALLDATA(Product,Mach,Duration) as "noindex;grow;[R1C15:R1C17](Product,Mach,Duration)" end-initializations end-model | |||||||||||||||||||||||||||||||||||||||||
© Copyright 2024 Fair Isaac Corporation. |