Re: Decode base64 to job CCSID?

Javier Sanchez <[email protected]> Wed, 1 Apr 2026 13:22:31 -0600
Newsgroups gmane.comp.lang.as400.rpg
Message-ID <CAAvhgxKwrqKMRX+4F+fRh2xFL9=L2X_73YTsDFEq+3PDCdKtAA@mail.gmail.com>
English is aligned with UTF-8 up to the legible characters that do not have
accented, or tilde, characters.
Take into account this.  When you need to accept Latin, accented or
tilded characters not part of the English language, UTF-8 will render two
or more bytes, depending on the language.
So, do not take for granted the size of the utf-8 variable just like the
*job ccsid variable.
If it is ALL ENGLISH, not a problem.  When UNICODE was invented, ASCII
became a subset of UTF-8 and not the contrary.
For example, CODE PAGE 1252 (Windows Western something.....), it includes
some accented characters that are Latin, and their codepoints were changed
from the original ASCII set.

Give it a thought.  I'd try what I suggested, or else, go more complicated
and use the iconv() API with which you can rest.

HTH

JS

El mié, 1 abr 2026 a las 12:15, Daniel Gross (<[email protected]>) escribió:

> Ah - yes - BASE64_DECODE returns a blob without CCSID (or better with
> *HEX).
>
> I solved this lately with a DS:
>
>    dcl-ds decoded qualified;
>      blob varchar(1000);
>      utf8 varchar(1000) ccsid(*utf8) samepos(blob);
>    end-ds;
>
>    exec sql set :decoded.blob = QSYS2.BASE64_DECODE(:encoded);
>    return decoded.utf8;
>
> I think this works quite OK - you could of course do this also with some
> pointer-arithmetic.
>
> HTH
> Daniel
>
>
> > Am 01.04.2026 um 19:53 schrieb Justin Taylor <[email protected]>:
> >
> > If I specify the CCSID on retDecoded, I get SQLSTATE 42806 "Variable
> > RETDECODED not compatible or value too long.".
> >
> >
> > Example:
> >       Dcl-s retDecoded varChar(1000) ccsid(*UTF8) ;
> >
> >
> >
> >> On Wed, Apr 1, 2026 at 12:32 PM cesco via RPG400-L <
> >> [email protected]> wrote:
> >>
> >> You need to know what encoding the encoded in base64 was originally in.
> >> then try to declare retDecoded with that CCSID
> >>
> >>
> >>
> >>
> >>
> > --
> > 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.
>
>
-- 
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.