RE: CCSID - RPG issues

"Birgitta Hauser" <Hauser-bRAHsVz2yv4TVIZRl6KS/[email protected]> Wed, 25 Feb 2026 12:10:34 +0100
Newsgroups gmane.comp.lang.as400.rpg
Message-ID <[email protected]>
%SUBST can handle varying length fields correctly.
Your problem might be, that the string functions (%SUBSTR, %SCAN) etc, deal
per Default with the number of byte and NOT with the number of characters).
In UTF-8 a single character can be 1, 2, 3 or 4 Byte.

If you add *NATURAL the number of Characters will be used:
%SUBST(YourText: StrPos: *Natural)

Mit freundlichen Grüßen / Best regards

Birgitta Hauser
Modernization – Education – Consulting on IBM i
Database and Software Architect  
IBM Champion since 2020

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
"Train people well enough so they can leave, treat them well enough so they
don't want to. " (Richard Branson)
"Learning is experience … everything else is only information!" (Albert
Einstein)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org> On Behalf Of Gad Miron
Sent: Wednesday, 25 February 2026 11:41
To: [email protected]
Subject: Re: CCSID - RPG issues

Hello Barbara

The (source) ds_NMMLIMP2.ITEMNAME looks OK - I'll check again though

Does %sbst function "knows" how to deal with a VARLEN data?

I'll check the CHARCOUNT thing.

THANKS
Gad








>


> date: Tue, 24 Feb 2026 09:29:25 -0500
> from: Barbara Morris <[email protected]>
> subject: Re: CCSID - RPG issues
>
> On 2026-02-24 8:56 a.m., Gad Miron wrote:
> > ...
> >     // take first 128 chars of Item Description
> >          ds_NMWRKR.ITEMNAME8 = %subst(ds_NMMLIMP2.ITEMNAME :1 : 128) 
> > ;
> >
> >      // Update map file - target
> >           update NMWRKR ds_NMWRKR  ;
> >
> > C                   eval      *INLR = *ON
> >
> > The update works but the value placed in ITEMNAME8 is erroneous ...
> In debug, does ds_NMMLIMP2.ITEMNAME look correct before the %subst? 
> Does it have UTF8 data? (look at the hex value of the field in the 
> debugger)
>
> Does ds_NMWRKR.ITEMNAME8 look correct after the %subst?
>
> Is it always incorrect? Or does the problem only happen with some values?
>
> Using %subst with UTF8 data has the potential to only pick up the 
> first byte of a 2-byte character unless you are using the new 
> CHARCOUNT NATURAL support.
>
> https://www.ibm.com/docs/en/i/7.5.0?topic=functions-subst-get-substrin
> g
>
>
> https://www.ibm.com/docs/en/i/7.5.0?topic=cdt-processing-string-data-b
> y-natural-size-each-character
>
> (I should update that pdf document to talk about the CHARCOUNT support 
> that was added in 7.4 and 7.5 with PTFs.)
>
> --
> Barbara
>
>
>
>
>
--
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: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.

Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org 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: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions.