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



Hi Tommy,

> I have a program that creates a file on the IFS. The file looks fine > on the AS/400 using WRKLNK & displaying the file. The file is an XML > document (very simple).

First of all, don't use codepage 37. That's EBCDIC, and the PC won't understand it. The XML standard does allow for different encodings, but to following the standards (which allow for programs to detect the encoding) you need to use either ASCII or Unicode. Never EBCDIC.

>
> XML on iSeries IFS:
> <XML>
>  <AUTHOR>Tommy Holden </AUTHOR>
> </XML>

The encodings that are guaranteed to be supported on all XML parsers are ISO-8859-1, UTF-8, US-ASCII and UTF-16. US-ASCII is a poor choice if you ever need to use your document with other countries. I strongly recommend that you use one of the other three encodings unless you have a very good reason not to.

Unless you need to support V4R5 and older releases, I strongly recommend that you use CCSIDs rather than code pages.

CCSID 819 (which is also code page 819) is ISO-8859-1.
CCSID 1208 is UTF-8.
CCSID 1200 is UTF-16.

If you use CCSID 819, it should look nice in both Notepad and on the iSeries. Assuming that your code is correct, and I suspect that it isn't!

> I'm using codepage 37 to create the file.
>           fd = Open( %TrimR(FileName)
>                    : O_CREAT+O_TRUNC+O_RDWR+O_CODEPAGE+O_TEXTDATA
>                    : S_IRUSR+S_IWUSR+S_IXUSR+
>                      S_IRGRP+S_IWGRP+S_IXGRP+
>                      S_IROTH+S_IXGRP:37);

Enabling translation from EBCDIC to CCSID 819 involves two steps:

a) Create a file, and tag that file with CCSID 819. This way, the system knows that the file is 819.

b) Open the file, an enable translation from the job's CCSID to the file's CCSID.

Unfortunately, it looks as though you've mixed the two steps together. You're trying to both create it and enable translation at the same time. O_TEXTDATA (which means "translate") tells the system to translate from the job's CCSID to the file's CCSID -- but the file doesn't exist! So no translation takes place!

O_CODEPAGE tells the system to tag the file with the code page. But if you set the codepage to 819, the system will tag the file as ASCII, but since O_TEXTDATA isn't doing any trnaslation, the data will be written in EBCDIC (therefore, it'll look like garbage from both i5/OS and Windows!)

Another potential problem is that the O_CODEPAGE only tags the file with a codepage *IF* the file doesn't yet exist. The tagging is only done when the file is created, you see. That's easy to work around... just delete the file beforehand.

Here's what I recommend:

   // delete the file

      unlink(%trimr(filename));

   // create the file, tag it with CCSID 819:
   // close it immediately, because we only want
   // to create it, not read/write.

      fd = open( %trimr(filename)
               : O_CREAT+O_EXCL+O_WRONLY+O_CCSID
               : S_IRUSR+S_IWUSR+S_IXUSR+
                 S_IRGRP+S_IWGRP+S_IXGRP+
                 S_IROTH+S_IXGRP
               : 819 );
      callp close(fd);

   // Open the file again.  Since the file already exists,
   // and has a CCSID, we can enable translation:

      fd = open( %trimr(filename) : O_RDWR+O_TEXTDATA );

Now any reads from the file will automatically translate from 819 to 37 (since 37 is the EBCDIC we usually use in the USA). Writes will automatically translate from 37 to 819.

Since the file will be in 819 (which is ASCII), Notepad will have no trouble.

Since the file is tagged with 819, properly written iSeries programs will understand that it needs to be translated when it's read. So iSeries tools like DSPF and EDTF will also read the file correctly. Tools like CPYFRMSTMF, QShell, etc, will all work correctly.

The only cumbersome bit is that you have to open it twice! Once to creata the file, and a second time to enable translation. In V5R2, IBM added another feature that lets you do both in one fell swoop. This feature is the O_TEXT_CREAT flag. So if you're on V5R2, you can use only one open statement, as follows:

      unlink(%trimr(filename));

      fd = open( %trimr(filename)
               : O_CREAT+O_EXCL+O_RDWR+O_CCSID
                    +O_TEXTDATA+O_TEXT_CREAT
               : S_IRUSR+S_IWUSR+S_IXUSR+
                 S_IRGRP+S_IWGRP+S_IXGRP+
                 S_IROTH+S_IXGRP
               : 819
               : 0 );

Personally, I thought this was a great feature when V5R2 first included it, but as time has passed, I've found that I like the "two opens" technique better because I find it simpler to read two shorter open() calls than one big one. :)

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