Hi Greg,

I know I sound like a broken record here on the mailing list - but have you tried it with SQL? If the string gets decoded by the online decoder, it might be possible, that there is a problem with the decoding procedure.

As the strings are quite large, you will average to use CLOBs, as SQL only supports VARCHAR up to a length of 32739 bytes.

So it might be an an idea to try:

dcl-s encoded_clob sqltype(clob:1000000) ccsid(*utf8) inz;
dcl-s decoded_clob sqltype(clob:1000000) ccsid(*utf8) inz;

encoded_clob_data = json.data.node.packingSlipPdfData;
encoded_clob_len = %len(json.data.node.packingSlipPdfData);

exec sql set :decoded_clob = base64_decode(:encoded_clob);

base64decoded = %subst(decoded_clob_data:1:decoded_clob_len);

Or you can even use SQL to write the decoded data directly to your IFS file.

HTH
Daniel


Am 13.03.2026 um 17:19 schrieb Greg Wilburn <gwilburn@xxxxxxxxxxxxxxxxxxxxxxx>:

I have done this quite a few times before, so I'm not sure why I'm struggling so much with this...

I'm getting a json document from a server that contains a base64 encoded string representing a packing slip... I'm able to copy the data from the webservice response file (JSON) on the IFS, and paste that into an online decoder. That works.

But when I try to do he same in my program, I'm getting an error:
" Unable to decode character at position 1. (Char=x'4A') "

Using the online decoder, indicating UTF8, it will decode. Using the same decoder, selecting autodetect, it decodes differently indicating windows 1252?

Just wondering if anyone can spot any glaring errors in my code. I've been looking at it all morning. UGH.

// definitions

dcl-s base64encoded varchar(1000000) ccsid(*utf8) inz;
dcl-s base64decoded char(1000000) inz;
dcl-s fd int(10);

dcl-s pdfFile varchar(128) inz;
dcl-s pdfData varchar(1000000) ccsid(*utf8) inz;


// Decode Packslip Data
base64Encoded = json.data.node.packingSlipPdfData;
len = base64_decode( %addr(base64Encoded:*data)
: %len(%trim(base64Encoded))
: %addr(base64Decoded)
: %size(base64Decoded)
);
pdfData = %subst(base64decoded:1:len);
pdfFile = fldr + '/packslips/' + inCom + '_' + inOrd + '.pdf';

flag = o_wronly + o_creat + o_ccsid + o_excl;
mode = s_irusr + s_iwusr + s_iroth + s_iwoth;
fd = open(pdfFile:flag:mode:1208:0); // PDF is UTF8
rc = write( fd
: %addr(pdfData:*data)
: %len(pdfData));

[Logo]<https://www.totalbizfulfillment.com/> Greg Wilburn
Director of IT
301.895.3792 ext. 1231
301.895.3895 direct
gwilburn@xxxxxxxxxxxxxxxxxxxxxxx<mailto:gwilburn@xxxxxxxxxxxxxxxxxxxxxxx>
1 Corporate Dr
Grantsville, MD 21536
www.totalbizfulfillment.com<http://www.totalbizfulfillment.com>
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.