Guru: Decoding Base64 ASCII
August 18, 2025 Chris Ringer
A co-worker of mine recently asked me how to decode a base64 ASCII string in RPG, received from an HTTP response. My response was “that’s easy”, simply use the relevant SQL function BASE64_DECODE. I promptly wrote some sample code and after some debugging I realized this function threw me a curveball.
Let me demonstrate the issue and offer a simple solution.
01 **Free
02 ctl-opt DftActGrp(*No) Copyright('(C) Chris Ringer');
03 dcl-s string_UTF8 varchar(1000) ccsid(*UTF8);
04 dcl-s base64_UTF8 varchar(1350) ccsid(*UTF8);
05 dcl-s decoded_UTF8 varchar(1000) ccsid(*UTF8);
06 dcl-s decoded_Hex varchar(1000) ccsid(*HEX);
07 Exec SQL Set Option Commit=*NONE, Naming=*SYS;
08 string_UTF8 = …
Read more
