× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Here is some sample code I think will meet your needs, let me know if it does.

Chris..

#include <stdio.h> // standard I/O
#include <stdlib.h> // standard Lib
#include <string.h> // memory and string
#include <errno.h> // error number
#include <iconv.h> // conversion header

iconv_t pjTable; // conversion table
iconv_t jpTable; // conversion table

int pToj_CCSID(char *instr,
char *outstr,
int num ) {
size_t ret_iconv; // ret val
size_t insz; // in size
size_t outsz; // out size

insz = num;
outsz = 8096;
ret_iconv = iconv(pjTable,&instr,&insz,&outstr,&outsz);
if(ret_iconv != 0) {
printf("%s\n",strerror(errno));
return -1;
}
return 1;
}

int jTop_CCSID(char *instr,
char *outstr,
int num ) {
size_t ret_iconv; // ret val
size_t insz; // in size
size_t outsz; // out size

insz = num;
outsz = 8096;
ret_iconv = iconv(jpTable,&instr,&insz,&outstr,&outsz);
if(ret_iconv != 0) {
printf("%s\n",strerror(errno));
return -1;
}
return 1;
}

int main(int argc, char **argv) {
int len = 0; // counter
char tstBuf[255]; // test buffer
char outBuf[255]; // test buffer output
char str[5] = "Node"; // test string
QtqCode_T jCode = {0,0,0,0,0,0}; // Job CCSID
QtqCode_T pCode = {37,0,0,0,0,0}; // Program CCSID

// create the conversion tables
jpTable = QtqIconvOpen(&jCode,&pCode);
if(jpTable.return_value == -1) {
printf("QtqIconvOpen Failed %s\n",strerror(errno));
exit(-1);
}
pjTable = QtqIconvOpen(&pCode,&jCode);
if(eaTable.return_value == -1) {
iconv_close(aeTable);
printf("QtqIconvOpen Failed %s\n",strerror(errno));
exit(-1);
}
len = sprintf(tstBuf,"[%s]",str);
// convert from the pgm to the user ccsid
pToj_CCISD(tstBuf,outBuf,len);
// the outBuf should not have the square brackets in the correct CCSId to display to the user.
printf("%s : %s\n",tstBuf,outBuf);
// important to close the tables when finished with
iconv_close(pjTable);
iconv_close(jpTable);
exit(0);
}

-----Original Message-----
From: C400-L <c400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Niels Liisberg
Sent: December 8, 2022 1:04 PM
To: Bare Metal Programming IBM i (AS/400 and iSeries) <c400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: [C400-L] IBM i code page / CCSID

also set your job to that ccsid

CHGJOB CCSID(37)

And if you are using a 5250 - the remember to set that to to 37

Also the source file - it using so , has to be set to that ccsid ...



On Thu, Dec 8, 2022 at 12:19 AM Roger Lacroix <roger.lacroix@xxxxxxxxxx>
wrote:

All,

I'm a newbie programmer on IBM i (OS/400) and I need a little bit of help.

I'm having a weird problem with EBCDIC and square brackets, pretty
much as described here:

https://www.ibm.com/support/pages/what-impact-changing-qccsid-shipped-
65535-another-ccsid

Recently, a customer was trying out a program but it was not working.
It took a couple of days to realize that they were running their
system on a different code page. At first, I thought I would add their
code page to the hard-coded list but then I thought that solution was
stupid and started hunting for a proper solution.

I decided that what I needed was a lookup table based on the code page
(CCSID) and the HEX values for the square brackets. The trick was
figuring out how to get the code page from the OS (operating system).
After what felt like a millions searches, I can across the nl_langinfo
subroutine. It is available on AIX, Linux, IBM i and z/OS. If you call
nl_langinfo subroutine with the parameter of CODESET then it will
return the code page (aka code set, CCSID) as a string.

Next, I found 101 EBCDIC code pages and created a lookup table of the
square brackets in sorted order by code page. Finally, I created a
routine to issue the nl_langinfo subroutine and then perform a binary
search of the lookup table and set the correct square brackets for the
program to use.

I found what I thought was a solution by using the
nl_langinfo(CODESET) call as detailed here:

https://www.ibm.com/docs/en/i/7.5?topic=functions-nl-langinfo-retrieve
-locale-information

I wrote about the lookup table and routine here:
https://www.capitalware.com/rl_blog/?p=7060

When I run a test program with the nl_langinfo(CODESET) call on my
system, it returns 37 for the code page/CCSID. When I run the
following commands on my system:

DSPSYSVAL SYSVAL(QCCSID)
DSPSYSVAL SYSVAL(QCHRID)

They both return code page/CCSID of 37.

So I gave the test program to the customer. When they run the program
it returns 37 for the code page/CCSID. But when the customer run
those
2 "DSPSYSVAL SYSVAL" commands, they return 273 for code page/CCSID.
And yes they are in Europe.

So, my question is to those IBM i experts, what am I doing wrong. Note:
The code that I am using was posted in my blog posting. I don't
understand why it didn't return 273 for code page/CCSID.

Is there a better way from a C program to retrieve the correct code
page/CCSID from the IBM i system?

Help please.

Regards,
Roger Lacroix
Capitalware Inc.


--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L)
mailing list To post a message email: C400-L@xxxxxxxxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxxxxxxxx Before posting, please
take a moment to review the archives at
https://archive.midrange.com/c400-l.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxxxxxxxx Before posting, please take a moment to review the archives at https://archive.midrange.com/c400-l.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2024 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.