<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: lucas leonel</title>
    <description>The latest articles on DEV Community by lucas leonel (@shuras27).</description>
    <link>https://dev.to/shuras27</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4087055%2Ffce2cbd0-6283-49a1-be1a-317879e3d8cc.png</url>
      <title>DEV Community: lucas leonel</title>
      <link>https://dev.to/shuras27</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shuras27"/>
    <language>en</language>
    <item>
      <title>Escaping the mainframe: converting legacy ERP flat files (SAP, JD Edwards, COBOL/EBCDIC)</title>
      <dc:creator>lucas leonel</dc:creator>
      <pubDate>Thu, 20 Aug 2026 17:54:52 +0000</pubDate>
      <link>https://dev.to/shuras27/escaping-the-mainframe-converting-legacy-erp-flat-files-sap-jd-edwards-cobolebcdic-559p</link>
      <guid>https://dev.to/shuras27/escaping-the-mainframe-converting-legacy-erp-flat-files-sap-jd-edwards-cobolebcdic-559p</guid>
      <description>&lt;p&gt;Every company over ~25 years old has the same skeleton in the closet: data&lt;br&gt;
still living in fixed-width flat files exported from SAP, JD Edwards, or a&lt;br&gt;
mainframe. These files are multi-GB, sometimes EBCDIC-encoded, and their&lt;br&gt;
schema lives in a comment that nobody has looked at since 1994.&lt;/p&gt;

&lt;p&gt;Modernizing means getting that data out — but the ecosystem around flat-file&lt;br&gt;
conversion is stuck in the same era as the files themselves. GUI tools with&lt;br&gt;
license fees. Proprietary formats. Scripts that die on the first malformed&lt;br&gt;
line.&lt;/p&gt;

&lt;p&gt;I hit this repeatedly in consulting work. And I kept rewriting the same&lt;br&gt;
converter. So I open-sourced it.&lt;/p&gt;
&lt;h2&gt;
  
  
  The shape of the problem
&lt;/h2&gt;

&lt;p&gt;A "flat file" is the oldest structured format in computing: records of a&lt;br&gt;
fixed byte length, fields sliced by offset. No headers. No types. No&lt;br&gt;
metadata. The layout lives in the COBOL FD or the SAP program that wrote it.&lt;/p&gt;

&lt;p&gt;Three things make them painful:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Byte offsets, not columns.&lt;/strong&gt; &lt;code&gt;amount&lt;/code&gt; lives at bytes 36–48. Get the
offset wrong and you get the customer name and the balance concatenated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Codepages.&lt;/strong&gt; Mainframes are often EBCDIC, not ASCII. The subtle trap:
Python's codec is &lt;code&gt;cp037&lt;/code&gt;, not &lt;code&gt;ebcdic-cp037&lt;/code&gt;. Naive converters either
crash or silently produce mojibake.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Size.&lt;/strong&gt; Multi-GB files don't fit in the "read it all into memory"
approach that most one-off scripts use.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  The approach: schemas, not code
&lt;/h2&gt;

&lt;p&gt;Instead of writing a parser per format, describe the layout in YAML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cobol_fixed&lt;/span&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1.0.0&lt;/span&gt;
&lt;span class="na"&gt;record_length&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;57&lt;/span&gt;
&lt;span class="na"&gt;codepage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ebcdic-cp037&lt;/span&gt;
&lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;customer_name&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;start&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;6&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;  &lt;span class="nv"&gt;length&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;30&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;balance&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;       &lt;span class="nv"&gt;start&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;36&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;length&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;12&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;decimal&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;scale&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;2&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;align&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;right&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One generic parser handles every format. The knowledge is portable: one&lt;br&gt;
shared schema means identical parsing at any company that receives the same&lt;br&gt;
export.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why determinism matters
&lt;/h2&gt;

&lt;p&gt;For migration projects — moving ledgers, AR/AP, customer balances — the&lt;br&gt;
output is an audit artifact. Same input + same schema must produce the same&lt;br&gt;
output, every run, on any machine. That's not a nice-to-have; it's the&lt;br&gt;
difference between "we converted the data" and "we can prove we converted the&lt;br&gt;
data."&lt;/p&gt;

&lt;p&gt;The tool treats this as a guarantee, and adds SHA-256 sidecars hashing the&lt;br&gt;
input, output, and schema version.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tools, in brief
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Streaming&lt;/strong&gt;: line-by-line, constant memory on multi-GB files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cumulative validation&lt;/strong&gt;: collects every error with its record number
instead of stopping at the first bad line.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Codepage-aware&lt;/strong&gt;: CP850, CP1252, Latin-1, EBCDIC-CP037.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto-detection&lt;/strong&gt;: point it at a file and it scores the built-in schema
library to find the best match.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plugins&lt;/strong&gt;: drop a Python &lt;code&gt;Reader&lt;/code&gt; for binary formats — framed records,
packed decimals — with the same validation and determinism.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Outputs&lt;/strong&gt;: JSON, CSV, NDJSON, SQL inserts, Parquet (exact &lt;code&gt;decimal128&lt;/code&gt;),
Excel, and Singer for tap pipelines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Air-gapped by design: no network, no database, stdlib + PyYAML. That last&lt;br&gt;
part matters for exactly the environments these files live in.&lt;/p&gt;

&lt;h2&gt;
  
  
  One command
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;erp-export-normalizer
git clone https://github.com/lucasgiurastante/erp-export-normalizer
&lt;span class="nb"&gt;cd &lt;/span&gt;erp-export-normalizer/examples

&lt;span class="c"&gt;# COBOL mainframe dump (EBCDIC) → NDJSON, no config needed&lt;/span&gt;
erp-normalize &lt;span class="nt"&gt;--input&lt;/span&gt; data/cobol.txt &lt;span class="nt"&gt;--output&lt;/span&gt; - &lt;span class="nt"&gt;--format&lt;/span&gt; ndjson
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The real goal
&lt;/h2&gt;

&lt;p&gt;I'm not trying to build a company here. I want the worst flat-file formats&lt;br&gt;
documented in one public library so the next person doing a migration&lt;br&gt;
doesn't have to re-derive the offsets, the codepage, and the scale from&lt;br&gt;
scratch. If you've got a horrible fixed-width layout sitting in your repo,&lt;br&gt;
open an issue with a sample — I'll turn it into a schema.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/lucasgiurastante/erp-export-normalizer" rel="noopener noreferrer"&gt;https://github.com/lucasgiurastante/erp-export-normalizer&lt;/a&gt;&lt;br&gt;
PyPI: &lt;a href="https://pypi.org/project/erp-export-normalizer/" rel="noopener noreferrer"&gt;https://pypi.org/project/erp-export-normalizer/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sap</category>
      <category>etl</category>
      <category>python</category>
    </item>
  </channel>
</rss>
