Back to trackLesson 4 of 6

Showcases 4: A Complete NACHA ACH File

Requires Pro (FlatFile behind RoutingNumber’s samples, and the render/assembler filters below)

Problem statement

You’re testing a payments pipeline that consumes NACHA ACH files. It needs files that are structurally valid, not just plausible-looking: every record padded to exactly 94 characters, an entry count that matches what’s actually in the file, an entry hash computed by summing routing numbers, debit and credit totals that reconcile, and the whole file padded with 9-filled records until its length is a multiple of ten. A hand-rolled fixture generator gets most of that right and one of those wrong, and the wrong one is invisible until a real ACH validator rejects the file.

Real ACH files are also full of live account numbers, which is its own reason not to use them for testing.

The model

Three layers, kept deliberately separate. The bottom layer produces values — a routing number with a real ABA check digit, an account number, a payment amount. The middle layer renders one payment into one 94-character Entry Detail record; it knows the NACHA field layout and nothing about where the values came from. The top layer pulls as many entries as you ask for, accumulates the running totals a real ACH file’s trailer records need, and emits the complete file as one string.

<?xml version="1.0" encoding="UTF-8"?>
<dataset columns="achFile" seed="42">
	<root node="AchFile"/>
	<nodes>
		<NachaFileAssembler name="AchFile" count="8"
			companyName="ACME PAYROLL" companyId="1234567890"
			companyEntryDescription="PAYROLL"
			originatingDfi="12102537" destinationRouting="021000021"
			destinationName="FEDERAL RESERVE" originName="ACME PAYROLL INC"
			serviceClassCode="220" standardEntryClass="PPD">
			<input name="Entry"/>
		</NachaFileAssembler>

		<NachaEntryRender name="Entry" transactionCode="22">
			<input name="ReceivingBank" role="routing"/>
			<input name="AccountNumber" role="account"/>
			<input name="NetPay" role="amount"/>
			<input name="Employee" role="name"/>
		</NachaEntryRender>

		<RoutingNumber name="ReceivingBank"/>
		<Constant name="AccountNumber" value="000123456789" type="string"/>
		<Lognormal name="NetPay" mu="7.6" sigma="0.5"/>
		<Constant name="Employee" value="EMPLOYEE NAME" type="string"/>
	</nodes>
</dataset>

Run it (samples/pro/financial/ach-file.xml) with --format raw, which writes the file verbatim — no CSV quoting, no delimiter inserted between fields:

101 021000021 1234567892601010000A094101FEDERAL RESERVE        ACME PAYROLL INC               
5220ACME PAYROLL                        1234567890PPDPAYROLL         260102   1121025370000001
622030594816000123456789     0000257053               EMPLOYEE NAME           0121025370000001
622094768565000123456789     0000194676               EMPLOYEE NAME           0121025370000002
...
822000000802476308080000000000000000015993521234567890                         121025370000001
9000001000002000000080247630808000000000000000001599352                                       

Why this shape works

A filter can pull its own input more than once. NachaFileAssembler isn’t limited to seeing one payment at a time — it drives <input> itself, calling getNextObservation() count times in a row, exactly the way the core Redimension filter already does to reshape a stream. That’s what lets it see every entry before it has to write the trailer records, which is the part a single render filter genuinely can’t do alone.

The values in the trailer are recomputed, not copied. The batch control record’s entry count, entry hash, and debit/credit totals are accumulated while the assembler pulls entries, then written once at the end. We checked this independently rather than trusting the code that wrote it: recomputing the entry hash and both totals from the eight entries in the committed sample matches the batch control record exactly — entry count 8, hash 247630808, credit total $15,993.52.

Dates are parameters, never the system clock. A file header carries a creation date and time (fileCreationDate, fileCreationTime, effectiveEntryDate), and all three default to fixed values rather than now() — set them explicitly if a particular date matters to your test. Reading them from the system clock instead would make the same model produce different bytes on different days, which defeats the entire point of a seeded model. Regenerating the sample twice from the same seed produces byte-identical output; we checked.

--format raw exists for exactly this. --format tsv happens to produce identical output for a single unquoted string column, but it’s still applying TSV’s own escaping rules underneath, and it would misbehave the moment a rendered line contained a literal tab. raw writes what the filter produced, with nothing inserted or escaped.