I have many files in the IFS with a wide variety of CCSIDs (0, 37, 819, 1200, 1252, etc.) and I've been tasked with writing a simple RPGLE [1] program that will allow a user to view the contents of any of these files.

Our system (V6R1) CCSID (DSPSYSVAL QCCSID) is 65535 [2] and our jobs have a default CCSID of 37 which means when I try to display CCSID 819 (ASCII) for example, I see garbage – symbols, random colors, etc.

I am familiar with converting data from one CCSID to another via the [QtqIconvOpen](http://pic.dhe.ibm.com/infocenter/iseries/v6r1m0/index.jsp?topic=/apis/QTQICONV.htm) API so if I know a file has a CCSID that differs from our default CCSID, I can convert it. I wrote code years ago to do that and it works fine.

My problem is finding out the CCSID of the IFS file programmatically. After Googling the only relevant information I found was here on Stackoverflow from JamesA ([How to determine the CCSID used in CPYFRMIMPF command?](https://stackoverflow.com/questions/10982810/how-to-determine-the-ccsid-used-in-cpyfrmimpf-command)) who points out that you can execute “ls -S” in a QSHELL to get a listing of files showing their CCSID and filename.

So theoretically I could execute `ls -S filename`, parse the output to get the CCSID and then use that CCSID to perform a conversion of the data if necessary. That's an ugly hack though and I'd much prefer to use an IBM API if possible.

Does anyone know of such an API or a more elegant hack than parsing a listing from `ls -S filename`?

[1] I use the C API's `open()`, `read()` and `close()` to do the actual reading of data.

[2] I know 65535 is a poor choice but there's nothing I can do about it.