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



> I've looked through the archives, but can't seem to find a definitive
> answer.  Some posts say creating the IFS with 'codepage=1252' is enough
> (It's not), others say that a call to open(), then closing, then
> reopening will work, others say to use iconv() (But no one seems to
> agree on the prototypes) and others say this is all fixed at V5R1.

You're getting a bunch of different things confused.  The following
statements are all true:

  a) Creating the file with codepage 1252, and making sure that the data
      is also 1252 will allow subsquent opens by your program or other
      programs to automatically translate from & to that codepage. This is
      true, but it's leaving something out: Just assigning the codepage
      doesn't automatically translate teh data, you must also open the
      file in text mode -- and you can't do that unless the file already
      exists when you open it.

  b) That brings us to the point about doing two opens. Yes, to enable
      auto-translation, you should open it once to CREATE the file and
      assign it a codepage or CCSID.  Then close it again and re-open it
      in text mode to start translating the data. In V5R2 there's a way
      to do it in one open, but it involves passing an additional flag
      to the open() API.  If this flag is not passed, it will continue to
      work the same as it did on V5R1 and earlier releases.

  c) In V4R5 and earlier, stream files could store any type of data
      you could put in them, but they could not be tagged in the
      filesystem with a CCSID. You could tag them with a codepage,
      but not a CCSID. So, if you wanted to write data that required
      CCSID support, you'd have to manually do the translations with
      the iconv() API.  However, this is not necessary with CCSID 1252!
      Codepage 1252 and CCSID 1252 will give you the same results --
      so you don't need to use iconv() in that case.  (You might, however,
      if you used an asian language the requires multiple codepages or
      if you needed unicode)

I'm unclear on what you mean by "nobody seems to agree on the prototype."
There are many ways to prototype the same function -- just make sure you
pick a sample program that actually WORKS instead of one where the author
posted his code to get help because he was stuck.


> I have an app that needs to run on all releases from V4R5 and up.  What
> is the best way to create and write to an IFS file?  If I specify the
> codepage on the open, should I still need to use iconv()?  If I use
> iconv() then run this on V5Rx, will I then get trash again because of a
> double conversion?

No, code written for V3R2 still works properly on V5R3. There's no issue
with double-conversion.

V5R2 added a flag called O_TEXT_CREAT which, if passed, allows you to get
by with a single open() call instead of having to call it twice.  If you
don't pass this flag, and open it twice like you did in V5R1 and earlier,
then it'll work just like it did in V5R1 and earlier.

Try the following code.  It should work on any V4 ot V5 system, AFIAK.  It
should automatically tag the file with 1252, and automatically translate
the data to ASCII as it's written.  If you read it with a utility that's
designed for text (such as most QShell functions, the EDTF command, or a
program that supplies O_TEXTDATA to the open API) then it should
automatically convert to EBCDIC as needed.

     H DFTACTGRP(*NO)

      /copy qrpglesrc,ifsio_h

     D ALLOW_RDWR      c                   438
     D f               s             10I 0
     D filename        s           1000A   varying
     D                                     inz('/tmp/test.txt')
     D data            s            100A

      **
      ** If file already exists, delete it.  That way you can be
      ** sure that the file will be created from scratch in the
      ** next step.
      **
     c                   callp     unlink(filename)

      **
      ** Create a new file with codepage 1252:
      **
     c                   eval      f = open( filename
     c                                     : O_CREAT+O_CODEPAGE+O_WRONLY
     c                                     : ALLOW_RDWR
     c                                     : 1252 )
     c                   if        f  = -1
     c** handle error
     c                   endif
     c                   callp     close(f)

      **
      ** Re-open the file in text mode so that translation is done:
      **
     c                   eval      f = open( filename
     c                                     : O_WRONLY + O_TEXTDATA )

      **
      ** Write something to it & close it.
      **
     c                   eval      data = 'Hello World' + x'0d25'
     c                   callp     write(f: %addr(data): %len(%trimr(data)))

     c                   callp     close(f)

     c                   eval      *inlr = *on

Hope that helps


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.