The following routine is used to read the data in a generated text file into the corresponding fields of a table. Character fields in the text file are the same length as in the table. Dates are formatted in six characters as MMDDYY (which matches the current SET DATE format). Numbers are always twelve characters and represent currency stored in cents, so it needs to be divided by 100.

function decodeLine( cLine, aDest )

#define YEAR_LEN 2 

#define NUM_LEN 12 

local nPtr, nFld, cFld, nLen 

nPtr = 1 && Pointer into string 

for nFld = 1 to fldcount( ) 

cFld = field( nFld ) && Store name of field in string variable for reuse 

do case 

case type( cFld ) == "C" 

aDest[ nFld ] = substr( cLine, nPtr, flength( nFld )) 

nPtr += flength( nFld ) 

case type( cFld ) == "D" 

aDest[ nFld ] = ctod( substr( cLine, nPtr, 2 ) + "/" + ; 

substr( cLine, nPtr + 2, 2 ) + "/" + ; 

substr( cLine, nPtr + 4, YEAR_LEN ) ) 

nPtr += 2 + 2 + YEAR_LEN 

case type( cFld ) == "N" 

aDest[ nFld ] = val( substr( cLine, nPtr, NUM_LEN )) / 100 

nPtr += NUM_LEN 

endcase 

endfor 

An array is passed to the routine along with the line to read. The field values are stored in the array, which is appended to the table with APPEND FROM ARRAY in the calling routine (not shown here). The function defines some manifest constants for the size of a numeric field and whether the year is two or four digits in case this changes in the future. A FOR loop goes through each field in the table. The name of each field is stored in a variable for convenience; it’s used repeatedly in the DO CASE structure.