Re: Decoding PDF data from a web service

Daniel Gross <[email protected]> Fri, 13 Mar 2026 19:07:27 +0100
Newsgroups gmane.comp.lang.as400.rpg
Message-ID <[email protected]>
Greg,

seems like something simple - but I don't have access to a machine right now. 

I can try over the weekend, and send you a resolution.

Regards,
Daniel


> Am 13.03.2026 um 18:45 schrieb Greg Wilburn <[email protected]>:
> 
> Daniel,
> 
> Thanks... actually, I tried that first (using AI example) to decode and write to the IFS.  I got an SQLSTATE of 22501 and gave up.
> 
> I tried your code below... it gives a SQL precompile error:
> SQL0303: Position 32 Variable DECODED_CLOB not compatible or value too long.
> 
> I have it defined exactly as below (I'm on v7r5)
> 
> TIA,
> Greg
> 
> 
> 
> -----Original Message-----
> From: RPG400-L <[email protected]> On Behalf Of Daniel Gross
> Sent: Friday, March 13, 2026 12:39 PM
> To: [email protected]
> Cc: [email protected]
> Subject: Re: Decoding PDF data from a web service
> 
> 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 <[email protected]>:
>> 
>> 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://protect.checkpoint.com/v2/r01/___https://www.totalbizfulfillment.com/___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3OmUxNGQ6Yjg2YTA5NWMzZmRmNjE5NmY0MmEzMTFiNDgwMmQzYTA1NjA2OTQyZjAwODRlZjg5ZDFhMTQyZGJkMTgwMTJjMDpwOlQ6Rg>    Greg Wilburn
>> Director of IT
>> 301.895.3792 ext. 1231
>> 301.895.3895 direct
>> [email protected]<mailto:[email protected]>
>> 1 Corporate Dr
>> Grantsville, MD 21536
>> https://protect.checkpoint.com/v2/r01/___www.totalbizfulfillment.com___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3OjMzOTQ6YTY1MjdhMDY5ZDNkYzJlYmUyNjAyMThmYTAzMTY3N2FiMWIwM2EzMDY3NmQ3OTA1NDdmOWM0ODA1NTg4MDM3ZjpwOlQ6Rg<https://protect.checkpoint.com/v2/r01/___http://www.totalbizfulfillment.com___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3OjVkYWU6MWMwMDE5ZmNiZDY5MzhmMWMyYzgwNmQyZDZhMDFmZDRhNjQ2OWNmYjc0ZDE4NDc0MWVjZGRmZmQyYmM3OTBkNDpwOlQ6Rg>
>> --
>> This is the RPG programming on IBM i (RPG400-L) mailing list
>> To post a message email: [email protected]
>> To subscribe, unsubscribe, or change list options,
>> visit: https://protect.checkpoint.com/v2/r01/___https://lists.midrange.com/mailman/listinfo/rpg400-l___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3Ojc0OTk6ZDUxNWM2YTdkOWRlNjY1N2I4MWJiYzliZGQ3NDFiMmRhN2YwYjBlOThkYTUzMDI0N2E5NTI0NDAwM2Y3NTU3ODpwOlQ6Rg
>> or email: [email protected]
>> Before posting, please take a moment to review the archives
>> at https://protect.checkpoint.com/v2/r01/___https://archive.midrange.com/rpg400-l___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3OjFiNjY6MDZhYWFiZDYwNDM3YmQxMjY2ZmQ1NmVkZTZmYWM3ODg5NjY3YmE1ZjRiZTg5ZTE2MjM0Y2M0Y2E2MDE0ZTQ0MjpwOlQ6Rg.
>> 
>> Please contact [email protected] for any subscription related questions.
>> 
> --
> This is the RPG programming on IBM i (RPG400-L) mailing list
> To post a message email: [email protected]
> To subscribe, unsubscribe, or change list options,
> visit: https://protect.checkpoint.com/v2/r01/___https://lists.midrange.com/mailman/listinfo/rpg400-l___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3OjdiZWQ6NDZkNzI3OTQ2OWFhYjQ4MDBkMDg0OTE1MTMzNmZmYTc5YTJkZmJlNjU0MGUwOTY1ZjYyZGQ3YWFlOTFjNzBhODpwOlQ6Rg
> or email: [email protected]
> Before posting, please take a moment to review the archives
> at https://protect.checkpoint.com/v2/r01/___https://archive.midrange.com/rpg400-l___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzo1MWJhM2VhODNlZmFmNmFiNjIyOGYwMDI0MGQ2MDU1Yjo3OjNhZmY6OTU0OGZkNjQzMzg3M2U2MTljNTk3NTFlYzQ2NDIzZGU0MDlkMzJjNGI4NTVmMWQ5MDAzODc1MzU3NDA0ZWU0NjpwOlQ6Rg.
> 
> Please contact [email protected] for any subscription related questions.
> 
> Greg Wilburn
> Director of IT
> 301.895.3792 ext. 1231
> --
> This is the RPG programming on IBM i (RPG400-L) mailing list
> To post a message email: [email protected]
> To subscribe, unsubscribe, or change list options,
> visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
> or email: [email protected]
> Before posting, please take a moment to review the archives
> at https://archive.midrange.com/rpg400-l.
> 
> Please contact [email protected] for any subscription related questions.
> 
-- 
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact [email protected] for any subscription related questions.