How to read a comma-delimited file using Mentor and produce a fixed format file

The spec file CSVINPUT.SPX can be used to read in a delimited file and create a fixed format file and a listing of where data variables are now located.CSVINPUT.DAT is the comma-delimited file to use with this spec.

Make appropriate changes and then run Mentor.

Modify the out options define to change the format of the output file to any type of file desired.

Make sure that the Length is >= the needed output length, which will probably be larger than the input length.

Also make sure Maxfields is set to >= the number of different data fields in the input record.

>PURGESAME >DEFINE @DBNAME CSVINPUT''Dbfile name to store variables in.>DEFINE @INNAME CSVINPUT.DAT''Input file name (the comma-delimted file)>DEFINE @OUTNAME CSVINPUT.ASC''Output file name>DEFINE @OUTOPTIONS ASCII''Output filetype and/or other options>DEFINE @MAPNAME CSVINPUT.MAP''Map file name (Layout of new file)>DEFINE @LENGTH  78''Length of output records>DEFINE @MAXFIELDS 1000''Maximum number of fields in input>DEFINE @DELIM  CSVINPUT''COMMA or TAB depending upon type of delimiter>DEFINE @USEFIRST''UnComment this if first record has names and you want to use them''>DEFINE @IGNOREFIRST''UnComment this if first record has names and you DONT want to use them.''>DEFINE @SAVELAYOUT LAYOUT''Use this option if you want to save the current layout in the db file for later use''>DEFINE @USELAYOUT LAYOUT''Use an existing layout.  You'll need the dbfile open 'with it in it.  You may need to increase >quit errors=''>QUIT ERRORS=500''if you end up with > 200 truncated fields>IFDEFINE @USELAYOUT>USEDB @DBNAME>ELSE>CREATEDB @DBNAME>ENDIF>PRINTFILE $@MAPNAME>LOCFORMAT 1~INPUT @INNAMEASCII=@LENGTHMAX_DELIMIT_FIELDS=@MAXFIELDS>IFDEFINE @USEFIRSTDELIMIT_NAME_FIRST>ELSE>IFDEFINE @IGNOREFIRSTDELIMIT_DROP_FIRST>ENDIFDELIMIT_VARIABLE_NAME_PREFIX=CFMC>ENDIFDELIMITER=@DELIM>IFDEFINE @SAVELAYOUTSAVEDELIMITMAP=@SAVELAYOUT>ENDIF>IFDEFINE @USELAYOUTUSEDELIMITMAP=@USELAYOUT>ENDIFDELIMIT_MAPSHAREDOT=100WORK_LENGTH=@LENGTH~OUTPUT @OUTNAMELENGTH=@LENGTH@OUTOPTIONSWRITE_NOW~END

Another example that can be used is the file. This is a simple example thatreads in delimited files, creates fixed files,creates and modifiesa map, and forces consistent layouts with different delimited files.

  • csvinput.spx
  • csvinput.dat