{"id":1710,"date":"2026-01-20T03:49:43","date_gmt":"2026-01-20T03:49:43","guid":{"rendered":"https:\/\/craftcookcode.com\/?p=1710"},"modified":"2026-02-04T19:48:04","modified_gmt":"2026-02-04T19:48:04","slug":"qlik-replicate-and-were-back-to-ebcdic-problems-again","status":"publish","type":"post","link":"https:\/\/craftcookcode.com\/?p=1710","title":{"rendered":"Qlik Replicate: And we&#8217;re back to EBCDIC problems again"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">EBCDIC &#8211; my perpetual nightmare<\/h2>\n\n\n\n<p>Before I have <a href=\"https:\/\/craftcookcode.com\/?p=1585\" target=\"_blank\" rel=\"noopener\" title=\"\">written about EBCDIC<\/a>; and the tribulations I have come across <\/p>\n\n\n\n<p>With the post festive system haze still on \u2013 I spent a full day trying to work out another encoding problem that came up in our exception table.<\/p>\n\n\n\n<p>Let me take you on a journey.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">It starts with MS-SQL.<\/h2>\n\n\n\n<p>We have Qlik Replicate replicating data from a DB2\/zOS system into a MS-SQL system.&nbsp; I was investigating why there were inserts missing from the target table and exploring the dbo.attrep_apply_exceptions table I notice a bunch of INSERTS from another table in the exception table:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n\/*\nCREATE TABLE dbo.destination\n(\n\tadd_dte numeric(5, 0) NOT NULL,\n\tchg_dte numeric(5, 0) NOT NULL,\n\tchg_tme varchar(6) NOT NULL,\n\targmt varbinary(10) NOT NULL,\n\tCONSTRAINT pk_destination PRIMARY KEY CLUSTERED\n\t(\n\t\targmt\n\t) WITH (DATA_COMPRESSION = ROW) ON &#x5B;PRIMARY]\n) ON &#x5B;PRIMARY]\n*\/\n\nINSERT INTO &#x5B;dbo].&#x5B;destination] ( &#x5B;add_dte],&#x5B;chg_dte],&#x5B;chg_tme],&#x5B;argmt])  VALUES (46021,46021,&#039;151721&#039;, 0x35333538C3A302070000);\n<\/pre><\/div>\n\n\n<p>I thought it would be a good place to start by substituting the failed insert into a temp table and using the temp table to investigate downstream data flows.<\/p>\n\n\n\n<p>So:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nDROP TABLE IF EXISTS ##temp_destination;\n\nSELECT *\nINTO ##temp_destination\nFROM &#x5B;dbo].&#x5B;destination]\nWHERE 1 = 0;\n\nINSERT INTO ##temp_destination ( &#x5B;add_dte],&#x5B;chg_dte],&#x5B;chg_tme],&#x5B;argmt]) VALUES (46021,46021,&#039;151721&#039;, 0x35333538C3A302070000);\n<\/pre><\/div>\n\n\n<p>But as I was substituting the temp table into objects downstream &#8211; I was just getting logical errors.  Comparing the temp table against other data that already existed dbo.destination; it looked <em>not right<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Working Upstream<\/h2>\n\n\n\n<p>I thought it would be a good place to start by substituting the failed insert into a temp table and using the temp table to investigate downstream data flows.<\/p>\n\n\n\n<p>Since we just merged a system into our DB2\/zOS system; my initial thought it was a corrupted record coming from a merge process. I contacted the upstream system owners and asked for help.<\/p>\n\n\n\n<p>They came back and said the record was fine and the issue must be in the QR system converting the data wrong. This did not make sense &#8211; if there was a issue in the QR system; it would have been picked up in testing. Also, there would be lots of exceptions in dbo.attrep_apply_exceptions. I had confidence that QR was handling it right.<\/p>\n\n\n\n<p>Not trusting what the DB2\/zOS team had told me; I created a temp Qlik task to dump out that table into a test database.<\/p>\n\n\n\n<p>Using the other values in the record; I could look the record up in the table and compare the two.<\/p>\n\n\n\n<p>For the field argmt it came back as:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0xF5F3F5F846022F00000F<\/pre>\n\n\n\n<p>This looked nothing like what was in the exception table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">EBCDICy epiphany <\/h2>\n\n\n\n<p>Of course &#8211; it took a while; but it finally struck what was going on.<\/p>\n\n\n\n<p>The field argmt had sections encoded in EBCDIC.  This was getting brought across as bytes to MS-SQL.  There was a downstream trigger that was failing in the MS-SQL database.  But when it was getting written out into the exception table; it was getting written as ASCII (or possibly Windows-Latin) encoding.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"882\" height=\"730\" src=\"https:\/\/craftcookcode.com\/wp-content\/uploads\/2026\/01\/code_ebcdic_conv.png\" alt=\"\" class=\"wp-image-1714\" srcset=\"https:\/\/craftcookcode.com\/wp-content\/uploads\/2026\/01\/code_ebcdic_conv.png 882w, https:\/\/craftcookcode.com\/wp-content\/uploads\/2026\/01\/code_ebcdic_conv-300x248.png 300w, https:\/\/craftcookcode.com\/wp-content\/uploads\/2026\/01\/code_ebcdic_conv-768x636.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/figure>\n\n\n\n<p>(Only showing start of bytes as this is what we use downstream)<\/p>\n\n\n\n<p>With me just copying the insert statement and using it as is; I was treating ASCII bytes as EBCDIC; causing all sorts of logical errors downstream.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where to from here?<\/h2>\n\n\n\n<p>I&#8217;m going to raise this abnormality with Qlik.  I am not sure if it is a &#8220;bug&#8221; or a &#8220;feature&#8221;; but good to get clarification on that point.<\/p>\n\n\n\n<p>I also will need to educate our users on how to interpret the values in  dbo.attrep_apply_exceptions so not to stumble into mistakes that I did.<\/p>\n\n\n\n<p>As for fixing the data itself &#8211; since we have the full dump of data from the table and the data is slow moving; I can substitute the values from the data dump into the problem INSERT statement.<\/p>\n\n\n\n<p>This should allow it to run just fine.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>EBCDIC &#8211; my perpetual nightmare Before I have written about EBCDIC; and the tribulations I have come across With the post festive system haze still on&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1715,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,17],"tags":[102,36],"class_list":["post-1710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-qlik-replicate","category-sql","tag-ebcidic","tag-qlikreplicate"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/posts\/1710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1710"}],"version-history":[{"count":4,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/posts\/1710\/revisions"}],"predecessor-version":[{"id":1716,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/posts\/1710\/revisions\/1716"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=\/wp\/v2\/media\/1715"}],"wp:attachment":[{"href":"https:\/\/craftcookcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftcookcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}