Daniel, there is this simple rule. You create an IFS file with CCSID 1208
and you HAVE TO WRITE data also with CCSID 1208. If you write data with a
variable populated with CCSID 037, you will see garbage, because the file
should show UTF-8 encoding but you are writing EBCDIC buffers that are of
course not the same. THe opposite applies: if you create the file with
CCSID 037 and you write a UTF-8 buffer, you will see garbage.

If you want to see CCSID 037 data, you MUST CREATE the file with the same
CCSID too. This is apples with apples, and oranges with oranges.

As simple as that.

HTH
Javier.

El sáb, 8 feb 2025 a las 11:44, Daniel Gross (<daniel@xxxxxxxx>) escribió:

Maybe you can post some more code?

Where does the string come from? A procedure parameter?

An idea would be, to try:

exec sql set :out = cast(:input as varchar(32000) ccsid :ccsid);

Of course this would also work with CLOB and BLOB data - I think you might
have to make some experiments, because no one of use can test this, as no
one runs jobs with CCSID 65535 (aka *HEX).

The only other dynamic solution that comes to mind is "iconv" - the C-API
that makes such conversions - but that might not be a "walk in the park",
as it uses pointer arrays (char **).

Regards,
Daniel


Am 08.02.2025 um 17:27 schrieb smith5646midrange@xxxxxxxxx:

I used the C function open() and created the file with 1208. I then
wrote to it normally via the C write() function.

When I connected to it via the Access IFS tools, the contents were
garbage. When I changed the variable in the program to also be CCSID 1208
as shown below, the contents were readable.

Am I overlooking something?

-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Jon
Paris
Sent: Friday, February 7, 2025 5:40 PM
To: RPG programming on the IBM i (AS/400 and iSeries) <
rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: variable CCSID for a variable

Maybe I'm missing something, but there are two ways of writing to the
IFS that I am aware of. One uses the C functions and the other uses SQL. In
both cases the code page can be specified - on the open() for the C
functions and the Write for SQL. Both values can be passed as variables or
hard-coded as literals.

So .... ???


Jon Paris
Jon.Paris@xxxxxxxxxxxxxx



On Feb 7, 2025, at 3:12 PM, smith5646midrange@xxxxxxxxx wrote:
I have a program that writes data to the IFS.
Strings are concatenated into dataString. Eventually dataString is
written to the IFS. It used to only write UTF-8 so it utilized the
CCSID on the variable as follows.
dcl-s dataString varchar(1048576) ccsid(1208);
Now my client has times they want to write ebcdic instead of utf8. Is
there a way to make the ccsid on the above variable a variable that I
can pass into my program? I would rather not write code like this.
First because it is ugly to have these if statements throughout the
code (I know, I can create a function and it won't be as bad) but
second we are now locked into using only two CCSIDs and I would have
to change the program if they decided that they want a third or fourth
CCSID. With a parm, I can just say give it a try.
dcl-s dataString1208 varchar(1048576) ccsid(1208);
dcl-s dataString37 varchar(1048576) ccsid(37);
if parmCCSID = UTF8
append to dataString1208
else
append to dataString37
endif
--
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.

--
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.


--
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.
--
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-2025 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.